Need to generate new session_id if user_id changes

Hi there. We are having the issue of more than 1 users under 1 session_id. Is there a way to generate new session_id if the user_id changes?


Welcome to Snowplow @feihusong

You can call the following:


snowplow('clearUserData', { preserveSession: false, preserveUser: true });


snowplow('clearUserData', false, true);

This is only available in the latest releases of v3 and v2 of the tracker. You’ll also want to send an event straight after this as it resets the cookies and will only recreate the user_id cookie when the next event is sent.

1 Like

Hello @PaulBoocock

Thanks for the solution! We have deployed the changes and now everytime users log out and log in again a new session_id is created, which is great. However, we now see domain_sessionidx being missing for a lot of session_ids after the deployment. Could the be caused by this change?


Hi @feihusong

preserveSession: false will also reset the visit count (i.e. the domain_sessionidx) back to 0.

I may have misunderstood your original question. If you simply wanted to start a new session when the user changes, you can call:


This will reset the domain_sessionid but increment the domain_sessionidx.

1 Like