Skip to content

Fix session resumption when changing storage strategy with disableAnonymousTracking#1433

Merged
Jethro Nederhof (jethron) merged 1 commit intosnowplow:release/4.6.3from
jethron:issue/bcpf-1813-stratchange-resume
May 27, 2025
Merged

Fix session resumption when changing storage strategy with disableAnonymousTracking#1433
Jethro Nederhof (jethron) merged 1 commit intosnowplow:release/4.6.3from
jethron:issue/bcpf-1813-stratchange-resume

Conversation

@jethron
Copy link
Copy Markdown
Contributor

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 Jethro Nederhof (jethron) force-pushed the issue/bcpf-1813-stratchange-resume branch from 6987961 to b495fa1 Compare May 23, 2025 08:06
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM!

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

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants