@@ -28,6 +28,9 @@ import {
2828 moveElementToEnd ,
2929 parseNumber ,
3030 returnConvertedBoolean ,
31+ isValidAttributeValue ,
32+ findKeyInObject ,
33+ AttributeValue ,
3134} from './utils' ;
3235import { IMinifiedConsentJSONObject , SDKConsentState } from './consent' ;
3336import { ConfiguredKit , MPForwarder , UnregisteredKit } from './forwarders.interfaces' ;
@@ -40,6 +43,8 @@ import { CookieSyncDates, IPixelConfiguration } from './cookieSyncManager';
4043import { IMParticleWebSDKInstance } from './mp-instance' ;
4144import ForegroundTimer from './foregroundTimeTracker' ;
4245
46+ const { Messages } = Constants ;
47+
4348// This represents the runtime configuration of the SDK AFTER
4449// initialization has been complete and all settings and
4550// configurations have been stitched together.
@@ -122,6 +127,7 @@ function createSDKConfig(config: SDKInitConfig): SDKConfig {
122127// to TypeScript
123128export type ServerSettings = Dictionary ;
124129export type SessionAttributes = Dictionary ;
130+ export type LocalSessionAttributes = Dictionary ;
125131export type IntegrationAttribute = Dictionary < string > ;
126132export type IntegrationAttributes = Dictionary < IntegrationAttribute > ;
127133export type WrapperSDKTypes = 'flutter' | 'none' ;
@@ -146,7 +152,15 @@ export interface IFeatureFlags {
146152export interface IStore {
147153 isEnabled : boolean ;
148154 isInitialized : boolean ;
155+
156+ // Session Attributes are persistent attributes that are tied to the current session and
157+ // are uploaded then cleared when the session ends.
149158 sessionAttributes : SessionAttributes ;
159+
160+ // Local Session Attributes are persistent session attributes that are cleared when the
161+ // session ends, but are NOT uploaded to the server when the session ends.
162+ localSessionAttributes : LocalSessionAttributes ;
163+
150164 currentSessionMPIDs : MPID [ ] ;
151165 consentState : SDKConsentState | null ;
152166 sessionId : string | null ;
@@ -201,6 +215,8 @@ export interface IStore {
201215 setFirstSeenTime ?( mpid : MPID , time ?: number ) : void ;
202216 getLastSeenTime ?( mpid : MPID ) : number ;
203217 setLastSeenTime ?( mpid : MPID , time ?: number ) : void ;
218+ getLocalSessionAttributes ?( ) : LocalSessionAttributes ;
219+ setLocalSessionAttribute ?( key : string , value : AttributeValue ) : void ;
204220 getUserAttributes ?( mpid : MPID ) : UserAttributes ;
205221 setUserAttributes ?( mpid : MPID , attributes : UserAttributes ) : void ;
206222 getUserIdentities ?( mpid : MPID ) : UserIdentities ;
@@ -230,6 +246,7 @@ export default function Store(
230246 const defaultStore : Partial < IStore > = {
231247 isEnabled : true ,
232248 sessionAttributes : { } ,
249+ localSessionAttributes : { } ,
233250 currentSessionMPIDs : [ ] ,
234251 consentState : null ,
235252 sessionId : null ,
@@ -615,6 +632,15 @@ export default function Store(
615632 this . _setPersistence ( mpid , 'lst' , time ) ;
616633 } ;
617634
635+ this . getLocalSessionAttributes = ( ) : LocalSessionAttributes =>
636+ this . localSessionAttributes || { } ;
637+
638+ this . setLocalSessionAttribute = ( key : string , value : AttributeValue ) => {
639+ this . localSessionAttributes [ key ] = value ;
640+ this . persistenceData . gs . lsa = { ...( this . persistenceData . gs . lsa || { } ) , [ key ] : value } ;
641+ mpInstance . _Persistence . savePersistence ( this . persistenceData ) ;
642+ }
643+
618644 this . syncPersistenceData = ( ) => {
619645 const persistenceData = mpInstance . _Persistence . getPersistence ( ) ;
620646
@@ -660,6 +686,7 @@ export default function Store(
660686 this . sessionId = null ;
661687 this . dateLastEventSent = null ;
662688 this . sessionAttributes = { } ;
689+ this . localSessionAttributes = { } ;
663690 mpInstance . _Persistence . update ( ) ;
664691 } ;
665692
0 commit comments