Webclat / Martech Practice
Webclat / Martech Practice  /  qa  /  matomo

How do I get Matomo to recognize the same visitor by User ID across two different domains?

Answer in brief

Matomo's default visitor ID is a cookie scoped to a single domain, so it cannot follow a visitor across domains on its own. Use Matomo's User ID feature instead: call setUserId(knownId) on both domains once you know who the visitor is, which stitches every session on either domain to the same visitor profile by ID rather than by cookie.

Why this happens

Browser cookies, and by extension Matomo's first-party visitor ID cookie, are scoped per-domain by design - a cookie set on domain-a.com is invisible to domain-b.com even if both belong to the same company. Matomo's cross-domain link tracking carries an anonymous visitor ID across a single click from one domain to another, but it only survives that one hop and breaks on a second visit.

The User ID feature solves the underlying problem directly: instead of relying on cookie continuity, it ties activity to an identifier you already know, which is domain-independent because your own code supplies it rather than a cookie.

Fix it

  1. Enable cross-domain link tracking in Matomo's site settings if you also need pre-login anonymous continuity (Websites > Manage > the domains field with all relevant domains listed).
  2. On login, or wherever the visitor's identity becomes known, call _paq.push(["setUserId", "your-internal-user-id"]) on every domain the same session touches.
  3. Keep the User ID stable and non-PII - an internal database ID, not an email address, per Matomo's own recommendation.
  4. On logout, call _paq.push(["resetUserId"]) before the next anonymous session begins, so a later visitor on a shared device is not attributed to the previous user.
  5. In reporting, use the Visitor Profile or a User ID-based segment to confirm sessions across both domains merge into one profile - not the standard cross-domain linker report, which only covers anonymous same-visit hops.

How to verify it worked

Log in as a test user, visit domain A, then navigate to domain B in the same or a later session, and check that user's Visitor Profile in Matomo shows activity from both domains under one merged profile keyed to the User ID - not two separate anonymous visitors.

Still Seeing This After Trying the Fix?

Send us what you are seeing - the console error, the Network tab, the Live View output. We trace tracking implementations for a living and can usually tell you what is actually happening in one look.

Ask An Engineer