@@ -673,6 +673,20 @@ export function Tracker(functionName, namespace, version, mutSnowplowState, argm
673
673
}
674
674
}
675
675
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
+
676
690
/**
677
691
* Clears all cookie and local storage for id and ses values
678
692
*/
@@ -3080,20 +3094,9 @@ export function Tracker(functionName, namespace, version, mutSnowplowState, argm
3080
3094
* @param {string } stateStorageStrategy - Override for state storage
3081
3095
*/
3082
3096
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 ;
3090
3098
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 ) ;
3097
3100
3098
3101
initializeIdsAndCookies ( ) ;
3099
3102
@@ -3103,19 +3106,15 @@ export function Tracker(functionName, namespace, version, mutSnowplowState, argm
3103
3106
/**
3104
3107
* Enables anonymous tracking (ie. tracker initialized without `anonymousTracking`)
3105
3108
*/
3106
- apiMethods . enableAnonymousTracking = function ( anonymousArgs ) {
3109
+ apiMethods . enableAnonymousTracking = function ( anonymousArgs , stateStorageStrategy ) {
3107
3110
argmap . anonymousTracking = anonymousArgs || true ;
3108
3111
3109
- configAnonymousTracking = getAnonymousTracking ( argmap ) ;
3110
- configAnonymousSessionTracking = getAnonymousSessionTracking ( argmap ) ;
3111
- configAnonymousServerTracking = getAnonymousServerTracking ( argmap ) ;
3112
+ toggleAnonymousTracking ( stateStorageStrategy ) ;
3112
3113
3113
3114
// Reset the page view, if not tracking the session, so can't stitch user into new events on the page view id
3114
3115
if ( ! configAnonymousSessionTracking ) {
3115
3116
resetPageView ( ) ;
3116
3117
}
3117
-
3118
- outQueue . setAnonymousTracking ( configAnonymousServerTracking ) ;
3119
3118
} ;
3120
3119
3121
3120
/**
0 commit comments