@@ -673,23 +673,24 @@ export function Tracker(functionName, namespace, version, mutSnowplowState, argm
673
673
}
674
674
}
675
675
676
- /**
677
- * Generate a pseudo-unique ID to identify this user
678
- */
679
- function createNewDomainUserId ( ) {
680
- return uuid ( ) ;
681
- }
682
-
683
676
/**
684
677
* Clears all cookie and local storage for id and ses values
685
678
*/
686
- function deleteCookies ( ) {
679
+ function clearUserDataAndCookies ( preserveSession , preserveUser ) {
687
680
const idname = getSnowplowCookieName ( 'id' ) ;
688
681
const sesname = getSnowplowCookieName ( 'ses' ) ;
689
682
attemptDeleteLocalStorage ( idname ) ;
690
683
attemptDeleteLocalStorage ( sesname ) ;
691
684
deleteCookie ( idname , configCookieDomain , configCookieSameSite , configCookieSecure ) ;
692
685
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
+ }
693
694
}
694
695
695
696
/*
@@ -707,7 +708,7 @@ export function Tracker(functionName, namespace, version, mutSnowplowState, argm
707
708
if ( idCookieComponents [ 1 ] ) {
708
709
domainUserId = idCookieComponents [ 1 ] ;
709
710
} else if ( ! configAnonymousTracking ) {
710
- domainUserId = createNewDomainUserId ( ) ;
711
+ domainUserId = uuid ( ) ;
711
712
idCookieComponents [ 1 ] = domainUserId ;
712
713
} else {
713
714
domainUserId = '' ;
@@ -804,7 +805,7 @@ export function Tracker(functionName, namespace, version, mutSnowplowState, argm
804
805
}
805
806
806
807
if ( configDoNotTrack || toOptoutByCookie ) {
807
- deleteCookies ( ) ;
808
+ clearUserDataAndCookies ( ) ;
808
809
return ;
809
810
}
810
811
@@ -3120,7 +3121,7 @@ export function Tracker(functionName, namespace, version, mutSnowplowState, argm
3120
3121
/**
3121
3122
* Clears all cookies and local storage containing user and session identifiers
3122
3123
*/
3123
- apiMethods . clearUserData = deleteCookies ;
3124
+ apiMethods . clearUserData = clearUserDataAndCookies ;
3124
3125
3125
3126
apiMethods . setDebug = function ( isDebug ) {
3126
3127
debug = Boolean ( isDebug ) . valueOf ( ) ;
0 commit comments