Skip to content

Commit 94dffe2

Browse files
author
Paul Boocock
committed
Allow stateStorageStrategy to be changed on enableAnonymousTracking (close #969)
1 parent 8fed565 commit 94dffe2

File tree

1 file changed

+18
-19
lines changed

1 file changed

+18
-19
lines changed

src/js/tracker.js

+18-19
Original file line numberDiff line numberDiff line change
@@ -673,6 +673,20 @@ export function Tracker(functionName, namespace, version, mutSnowplowState, argm
673673
}
674674
}
675675

676+
function toggleAnonymousTracking(stateStorageStrategy) {
677+
if (stateStorageStrategy) {
678+
argmap.stateStorageStrategy = stateStorageStrategy;
679+
configStateStorageStrategy = getStateStorageStrategy(argmap);
680+
}
681+
682+
configAnonymousTracking = getAnonymousTracking(argmap);
683+
configAnonymousSessionTracking = getAnonymousSessionTracking(argmap);
684+
configAnonymousServerTracking = getAnonymousServerTracking(argmap);
685+
686+
outQueue.setUseLocalStorage(configStateStorageStrategy == 'localStorage' || configStateStorageStrategy == 'cookieAndLocalStorage');
687+
outQueue.setAnonymousTracking(configAnonymousServerTracking);
688+
}
689+
676690
/**
677691
* Clears all cookie and local storage for id and ses values
678692
*/
@@ -3080,20 +3094,9 @@ export function Tracker(functionName, namespace, version, mutSnowplowState, argm
30803094
* @param {string} stateStorageStrategy - Override for state storage
30813095
*/
30823096
apiMethods.disableAnonymousTracking = function (stateStorageStrategy) {
3083-
if (stateStorageStrategy) {
3084-
argmap.stateStorageStrategy = stateStorageStrategy;
3085-
argmap.anonymousTracking = false;
3086-
configStateStorageStrategy = getStateStorageStrategy(argmap);
3087-
} else {
3088-
argmap.anonymousTracking = false;
3089-
}
3097+
argmap.anonymousTracking = false;
30903098

3091-
configAnonymousTracking = getAnonymousTracking(argmap);
3092-
configAnonymousSessionTracking = getAnonymousSessionTracking(argmap);
3093-
configAnonymousServerTracking = getAnonymousServerTracking(argmap);
3094-
3095-
outQueue.setUseLocalStorage(configStateStorageStrategy == 'localStorage' || configStateStorageStrategy == 'cookieAndLocalStorage');
3096-
outQueue.setAnonymousTracking(configAnonymousServerTracking);
3099+
toggleAnonymousTracking(stateStorageStrategy);
30973100

30983101
initializeIdsAndCookies();
30993102

@@ -3103,19 +3106,15 @@ export function Tracker(functionName, namespace, version, mutSnowplowState, argm
31033106
/**
31043107
* Enables anonymous tracking (ie. tracker initialized without `anonymousTracking`)
31053108
*/
3106-
apiMethods.enableAnonymousTracking = function (anonymousArgs) {
3109+
apiMethods.enableAnonymousTracking = function (anonymousArgs, stateStorageStrategy) {
31073110
argmap.anonymousTracking = anonymousArgs || true;
31083111

3109-
configAnonymousTracking = getAnonymousTracking(argmap);
3110-
configAnonymousSessionTracking = getAnonymousSessionTracking(argmap);
3111-
configAnonymousServerTracking = getAnonymousServerTracking(argmap);
3112+
toggleAnonymousTracking(stateStorageStrategy);
31123113

31133114
// Reset the page view, if not tracking the session, so can't stitch user into new events on the page view id
31143115
if (!configAnonymousSessionTracking) {
31153116
resetPageView();
31163117
}
3117-
3118-
outQueue.setAnonymousTracking(configAnonymousServerTracking);
31193118
};
31203119

31213120
/**

0 commit comments

Comments
 (0)