Skip to content

Commit 8fed565

Browse files
author
Paul Boocock
committed
Clear in memory identifiers in clearUserData() (close #968)
1 parent bbdba01 commit 8fed565

File tree

1 file changed

+12
-11
lines changed

1 file changed

+12
-11
lines changed

src/js/tracker.js

+12-11
Original file line numberDiff line numberDiff line change
@@ -673,23 +673,24 @@ export function Tracker(functionName, namespace, version, mutSnowplowState, argm
673673
}
674674
}
675675

676-
/**
677-
* Generate a pseudo-unique ID to identify this user
678-
*/
679-
function createNewDomainUserId() {
680-
return uuid();
681-
}
682-
683676
/**
684677
* Clears all cookie and local storage for id and ses values
685678
*/
686-
function deleteCookies() {
679+
function clearUserDataAndCookies(preserveSession, preserveUser) {
687680
const idname = getSnowplowCookieName('id');
688681
const sesname = getSnowplowCookieName('ses');
689682
attemptDeleteLocalStorage(idname);
690683
attemptDeleteLocalStorage(sesname);
691684
deleteCookie(idname, configCookieDomain, configCookieSameSite, configCookieSecure);
692685
deleteCookie(sesname, configCookieDomain, configCookieSameSite, configCookieSecure);
686+
if (!preserveSession) {
687+
memorizedSessionId = uuid();
688+
memorizedVisitCount = 0;
689+
}
690+
if (!preserveUser) {
691+
domainUserId = uuid();
692+
businessUserId = null;
693+
}
693694
}
694695

695696
/*
@@ -707,7 +708,7 @@ export function Tracker(functionName, namespace, version, mutSnowplowState, argm
707708
if (idCookieComponents[1]) {
708709
domainUserId = idCookieComponents[1];
709710
} else if (!configAnonymousTracking) {
710-
domainUserId = createNewDomainUserId();
711+
domainUserId = uuid();
711712
idCookieComponents[1] = domainUserId;
712713
} else {
713714
domainUserId = '';
@@ -804,7 +805,7 @@ export function Tracker(functionName, namespace, version, mutSnowplowState, argm
804805
}
805806

806807
if (configDoNotTrack || toOptoutByCookie) {
807-
deleteCookies();
808+
clearUserDataAndCookies();
808809
return;
809810
}
810811

@@ -3120,7 +3121,7 @@ export function Tracker(functionName, namespace, version, mutSnowplowState, argm
31203121
/**
31213122
* Clears all cookies and local storage containing user and session identifiers
31223123
*/
3123-
apiMethods.clearUserData = deleteCookies;
3124+
apiMethods.clearUserData = clearUserDataAndCookies;
31243125

31253126
apiMethods.setDebug = function (isDebug) {
31263127
debug = Boolean(isDebug).valueOf();

0 commit comments

Comments
 (0)