Page hits are not connected to correct leads

Your software
My Mautic version is: 5.1.0
My PHP version is: 8.1.29
My Database type and version is: MySQL 5.7.44

Your problem

I need the ability to track users from our main website into Mautic. The main website is running NextJs so we use this piece of code added to every page for tracking via mautic script:

window.mt("send", "pageview", {
        path: pathname,
        email,
      })

The mt object is then appended to the page via GTM. I can see all the events from website inside mautic (in the page_hits table) but they are not connected to the correct contact even though the email in query is in Mautic as a contact. It seems Mautic creates a new lead, assigns the device ID and tracks it that way. How can I identify the contact in the tracking event so the page hits are correctly linked?

Any javascript errors? Are you running Mautic and your page on the same domain (I didn’t mean same subdomain)

There are no javascript errors on the mautic tracking script side (I assume you meant there). And I see the request to /mtc/event endpoint going correctly with 200 response. The email is correctly set in the Request’s formdata object. Moreover I see the events in the Mautic page_hits DB table (along with the emails in query column) as mentioned previously.

Mautic instance is running on mautic.company.com and the site we want to track is running on product.company.com so yes it’s the same domain.