analytics.js icon indicating copy to clipboard operation
analytics.js copied to clipboard

how to clear segment data when window closes

Open acollazomayer opened this issue 5 years ago • 2 comments

Is there a way to do a reset when the tab closes, Right now I store my user in sessionStorage, when I close the tab the user logs out. However the segment user id is still there.

Thanks

acollazomayer avatar Oct 05 '20 13:10 acollazomayer

@acollazomayer have you tried hooking into the page unload event and reseting analytics? Something like this:

window.addEventListener('unload', function() {
        window.analytics.reset();
      });

pooyaj avatar Oct 05 '20 23:10 pooyaj

@pooyaj Tried it, but session storage does not get clear on refresh. On beforeUnload or unload are triggered on refresh

acollazomayer avatar Oct 06 '20 09:10 acollazomayer