Skip to content

Conversation

@jethron
Copy link
Contributor

@jethron jethron commented May 23, 2025

If you create a tracker in anonymousTracking mode with session tracking enabled, and then change the storage strategy when disabling anonymousTracking mode, the tracker looks for the ses cookie using the new strategy rather than the old one, which fails. This makes it think a new session has begun. In order to tie the anonymous behaviour to the non-anonymous behaviour, you have to stitch via pageview ID or network user ID rather than the expected session ID.

If this is the initial pageview, this can cause interesting cases like events from a single pageview with two different domain_sessionid values, both with domain_sessionidx = 1.

With this change, we detect when a storage strategy is being changed, and if we are already in a session with the old strategy, update the ses cookie with the new strategy before loading the ID. This allows the tracker to notice a session is already in progress with the new strategy, and resume it with the existing session ID/index.

If there is no change to the storage strategy, or there is currently no session in progress, the behavior remains unchanged.

E.g.

snowplow('newTracker', 'sp', 'http://localhost:9090', {
    anonymousTracking: {
      withSessionTracking: true,
      withServerAnonymisation: true
    },
    stateStorageStrategy: 'localStorage',
});

snowplow('trackPageView'); // session ID 1

snowplow('disableAnonymousTracking', {stateStorageStrategy: 'cookieAndLocalStorage'}); // got consent, switch to cookies

snowplow('trackStructEvent', { // session ID 2 - oops!
  category: 'Mixes',
  action: 'Play',
  label: 'MrC/fabric-0503-mix',
  property: '',
  value: 0.0
});

@jethron jethron requested a review from matus-tomlein May 23, 2025 08:04
@jethron jethron force-pushed the issue/bcpf-1813-stratchange-resume branch from 6987961 to b495fa1 Compare May 23, 2025 08:06
Copy link
Contributor

@matus-tomlein matus-tomlein left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@jethron jethron merged commit 0e162b1 into snowplow:release/4.6.3 May 27, 2025
1 check failed
@jethron jethron deleted the issue/bcpf-1813-stratchange-resume branch May 27, 2025 01:31
@matus-tomlein matus-tomlein mentioned this pull request May 27, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants