Skip to content
Snippets Groups Projects
Unverified Commit 16d81f6e authored by Dillon Dumesnil's avatar Dillon Dumesnil
Browse files

AA-513: Reset segment state if anon user and there is a segment user id

If we are seeing an anonymous user, but the segment user id is still
set, we believe the segment user id is coming from a different user on
the same machine. This will make sure we clear out that storage and
then the indentify call will make a new anonymous id
parent 9aefd6f9
No related branches found
No related tags found
No related merge requests found
......@@ -30,6 +30,22 @@
else {
onLoadCallback();
}
% else:
// If we do not have an authenticated user, but Segment has a user id,
// reset the Segment user state so we start tracking fresh.
// This has to be wrapped in the document.readyState logic because the analytics.user()
// function isn't available until the analytics.js package has finished initializing.
if (document.readyState === 'complete') {
if (analytics.user().id()) {
analytics.reset();
}
} else {
document.addEventListener('readystatechange', event => {
if (event.target.readyState === 'complete' && analytics.user().id()) {
analytics.reset();
}
});
}
% endif
</script>
<!-- end segment footer -->
......
......@@ -22,6 +22,22 @@
}
);
});
% else:
// If we do not have an authenticated user, but Segment has a user id,
// reset the Segment user state so we start tracking fresh.
// This has to be wrapped in the document.readyState logic because the analytics.user()
// function isn't available until the analytics.js package has finished initializing.
if (document.readyState === 'complete') {
if (analytics.user().id()) {
analytics.reset();
}
} else {
document.addEventListener('readystatechange', event => {
if (event.target.readyState === 'complete' && analytics.user().id()) {
analytics.reset();
}
});
}
% endif
</script>
<!-- end segment footer -->
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment