Matomo Cross-Domain Tracking | OpsBlu Docs

Matomo Cross-Domain Tracking

How to track users across multiple domains and subdomains with Matomo. Covers cross-domain configuration, cookie handling, session stitching, and.

Overview

Cross-domain tracking in Matomo ensures visitor sessions persist when users navigate between different domains you own. Without proper configuration, each domain transition creates a new visitor session, fragmenting your analytics data and making conversion attribution impossible.

When Cross-Domain Tracking Is Required

  • Multi-domain journeys: Main site to checkout subdomain (e.g., www.example.com to checkout.example.com)
  • Third-party payment providers: Redirects to payment gateways that return users to your confirmation page
  • Microsites and campaign landing pages: Promotional sites that funnel users to the main conversion domain
  • International domains: Country-specific TLDs that share a common user journey (e.g., .com, .co.uk, .de)
  • App-to-web transitions: Mobile app deep links that open web content in a browser

Configuration Steps

Using setDomains

Add all domains that should share visitor sessions to the setDomains configuration:

_paq.push(['setDomains', [
  '*.example.com',
  '*.checkout.example.com',
  'payments.thirdparty.com'
]]);

The asterisk wildcard includes all subdomains. List the primary domain first as it becomes the cookie domain.

Enabling the Cross-Domain Linker

For Matomo Tag Manager deployments:

  1. Navigate to Variables and create a constant variable containing your domain list
  2. In your Matomo Configuration tag, enable Enable cross domain linking
  3. Add all domains to the Domains field, comma-separated
  4. The linker automatically appends pk_vid parameters to cross-domain links

For direct JavaScript implementation:

_paq.push(['enableCrossDomainLinking']);
_paq.push(['setDomains', ['*.example.com', '*.partner-site.com']]);

Referral Exclusions

Prevent sibling domains from appearing as traffic sources:

  1. In Matomo, go to Administration > Websites > Manage
  2. Select your site and navigate to Excluded Parameters
  3. Add all domains participating in cross-domain tracking to Excluded Referrers

This ensures users returning from checkout or payment domains retain their original attribution.

Third-Party Checkout Handling

When users redirect to external payment providers (Stripe, PayPal, Adyen):

  1. Pre-redirect capture: Store the Matomo visitorId in a server-side session or pass it as a URL parameter to the payment provider
  2. Return URL configuration: Include the pk_vid parameter in the return/callback URL from the payment provider
  3. Post-redirect restoration: Matomo automatically reads the pk_vid parameter and restores the visitor session

Example return URL structure:

https://example.com/order-confirmation?pk_vid=abc123xyz789&order_id=12345

Edge Cases and Considerations

Cross-domain linking requires cookies to be accepted. For cookieless tracking:

  • The linker still works but relies entirely on URL parameters
  • Session continuity may be less reliable without persistent cookies
  • Consider first-party data strategies for high-value conversions

Some browsers and privacy extensions strip URL parameters:

  • Implement server-side session stitching as a fallback
  • Use first-party subdomains where possible to reduce parameter reliance
  • Monitor cross-domain conversion rates for anomalies indicating blocking

iFrame Embeds

When embedding content via iframes across domains:

  • Parent and child frames must both have Matomo tracking
  • Use postMessage to pass visitor identifiers between frames
  • Consider whether the embedded content genuinely needs tracking

Validation Steps

Pre-Launch Testing

  1. Tag Manager Preview: Enable Matomo Tag Manager preview mode and navigate through cross-domain flows
  2. Network inspection: Verify pk_vid parameters appear on cross-domain links in browser DevTools
  3. Real-Time dashboard: Confirm a single visitor session spans multiple domains
  4. Cookie inspection: Check that the _pk_id cookie domain matches your configuration

Post-Launch Monitoring

  • Compare pre- and post-implementation session counts per domain
  • Review conversion attribution reports for accuracy
  • Check that referral traffic from internal domains has dropped to near zero
  • Validate ecommerce funnel completion rates across domain transitions

Troubleshooting Common Issues

Symptom Likely Cause Solution
Sessions split at domain boundary setDomains missing target domain Add all domains to configuration
Internal domains appear as referrals Referral exclusions not configured Add domains to exclusion list
pk_vid not appearing on links Cross-domain linking not enabled Enable linker in Tag Manager or JS
Session lost after payment redirect Return URL missing pk_vid Configure payment provider callbacks