@@ -156,7 +156,7 @@ export function startSessionStore<TrackingType extends string>(
156156 }
157157 if ( hasSessionInCache ( ) ) {
158158 if ( isSessionInCacheOutdated ( sessionState ) ) {
159- expireSessionInCache ( sessionState )
159+ expireSessionInCache ( )
160160 } else {
161161 sessionStateUpdateObservable . notify ( { previousState : sessionCache , newState : sessionState } )
162162 sessionCache = sessionState
@@ -170,9 +170,7 @@ export function startSessionStore<TrackingType extends string>(
170170 {
171171 process : ( sessionState ) => {
172172 if ( isSessionInNotStartedState ( sessionState ) ) {
173- if ( ! sessionState . anonymousId ) {
174- sessionState . anonymousId = generateUUID ( )
175- }
173+ sessionState . anonymousId = generateUUID ( )
176174 return getExpiredSessionState ( sessionState , configuration )
177175 }
178176 } ,
@@ -206,8 +204,8 @@ export function startSessionStore<TrackingType extends string>(
206204 return sessionCache . id !== sessionState . id || sessionCache [ productKey ] !== sessionState [ productKey ]
207205 }
208206
209- function expireSessionInCache ( sessionState : SessionState ) {
210- sessionCache = getExpiredSessionState ( sessionState , configuration )
207+ function expireSessionInCache ( ) {
208+ sessionCache = getExpiredSessionState ( sessionCache , configuration )
211209 expireObservable . notify ( )
212210 }
213211
@@ -236,9 +234,11 @@ export function startSessionStore<TrackingType extends string>(
236234 restartSession : startSession ,
237235 expire : ( hasConsent ?: boolean ) => {
238236 cancelExpandOrRenewSession ( )
239- const expiredSessionState = getExpiredSessionState ( sessionCache , configuration , hasConsent )
240- sessionStoreStrategy . expireSession ( expiredSessionState )
241- synchronizeSession ( expiredSessionState )
237+ if ( hasConsent === false && sessionCache ) {
238+ delete sessionCache . anonymousId
239+ }
240+ sessionStoreStrategy . expireSession ( sessionCache )
241+ synchronizeSession ( getExpiredSessionState ( sessionCache , configuration ) )
242242 } ,
243243 stop : ( ) => {
244244 clearInterval ( watchSessionTimeoutId )
0 commit comments