Quantcast
Channel: Support & Bugs - Matomo forums
Viewing all articles
Browse latest Browse all 5981

Session Fragmentation on Cross-Subdomain (Angular SPA + Redirects) despite correct Config

$
0
0

Hi everyone,

I am facing a persistent issue with session fragmentation between my main domain and a subdomain. Despite having standard cross-domain configurations in place, sessions are splitting intermittently.

Here is my environment and the problem in detail. I would appreciate any insights.

1. The Environment

  • Matomo Version: On-Premise (latest stable)

  • Tracking Method: Matomo Tag Manager (MTM)

  • Main Domain: tapin.ir (Wordpress/Standard)

  • Subdomain (User Panel): my.tapin.ir (Angular SPA)

  • Backend: Django (Shared backend for multiple white-label panels)

2. Current Configuration

I have configured the MTM container on both domains with the following settings to ensure continuity:

  • Cookie Domain: Set to *.tapin.ir

  • Cross-Domain Linking: Enabled (setDomains = *.tapin.ir, and enableCrossDomainLinking is active).

  • Cookie Attributes: Secure = True, SameSite = None.

  • User ID: Capturing Phone Number via Data Layer upon login.

3. The Scenario & The Issue

  1. A user visits tapin.ir.

  2. User clicks a Short Link (internal shortener) that redirects to my.tapin.ir/authentication/login?r=referrer_url.

  3. Matomo appends the pk_vid parameter to the URL during the cross-domain link click.

  4. The Result:

    • Success: For some users, the Visitor ID persists, and the session continues correctly.

    • Failure: For others, a NEW Visitor ID is generated upon landing on the subdomain.

    • Even after the user logs in and the User ID is pushed to Matomo, the sessions do not merge.

4. Diagnosis (The Evidence)

I confirmed this behavior using Segments:

  • Total Conversions (Goal: Phone Number Entry): 60 conversions.

  • Segment Entry Page URL contains tapin.ir: Shows only 40 conversions.

  • The Discrepancy: The missing 20 conversions show my.tapin.ir as the Entry Page. However, I know for a fact they came from the main domain because their landing URL contains our custom parameter ?r=... which carries the referrer from the main site.

This proves that Matomo failed to link the session during the redirect/loading phase for these specific users.

5. My Questions

Since pk_vid is present and cookies are set to wildcard (*), I suspect the issue lies in the SPA nature (Angular) or the Redirect chain.

  1. Angular SPA Timing: Is it possible that Angular clears the URL parameters (routing) before Matomo Tag Manager has a chance to read the pk_vid? How can I ensure MTM initializes first?

  2. Short Link Redirects: Does an intermediate 301/302 redirect (via a shortener) strip headers or cookies that Matomo relies on, even if pk_vid is seemingly passed?

  3. Backend Solution: Should I move the session handling to the Backend (Django)? i.e., grabbing the visitor ID server-side and passing it explicitly? If so, what is the best practice for this?

Thanks in advance for your help!

1 post - 1 participant

Read full topic


Viewing all articles
Browse latest Browse all 5981

Trending Articles