How to identify anonymous contact via API

Your software
My Mautic version is: 2.16.2
My PHP version is: 7.1.33

Your problem
My problem is:

Hello, I am trying to integrate my website with Mautic via API and I have the following problem. When some user views my website for the first time new anonymous contact is created in Mautic with his own ID which can be seen via in cookies. Now when someone converts into a lead for example by filling some contact form I want to save his email and other data to Mautic, but instead of identifying anonymous contact and merge data into it, Mautic creates a new contact with new ID so I lost information about what pages were seen by him before filling the contact form.

I cannot access ID from cookie because Mautic is installed on a different domain.
Together with email I tried to send ‘ipAddress’ => $_SERVER[‘REMOTE_ADDR’] but it does not work.

How could get the ID of anonymous contact? Or maybe there is another way to merge data from contact form into anonymous contact?