@rudderstack/analytics-js 3.35.0 → 3.35.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +10 -0
- package/dist/npm/index.d.cts +2 -2
- package/dist/npm/index.d.mts +2 -2
- package/dist/npm/legacy/bundled/cjs/index.cjs +29 -19
- package/dist/npm/legacy/bundled/esm/index.mjs +29 -19
- package/dist/npm/legacy/bundled/umd/index.js +29 -19
- package/dist/npm/legacy/cjs/index.cjs +29 -19
- package/dist/npm/legacy/content-script/cjs/index.cjs +29 -19
- package/dist/npm/legacy/content-script/esm/index.mjs +29 -19
- package/dist/npm/legacy/content-script/umd/index.js +29 -19
- package/dist/npm/legacy/esm/index.mjs +29 -19
- package/dist/npm/legacy/lite/cjs/index.cjs +29 -19
- package/dist/npm/legacy/lite/esm/index.mjs +29 -19
- package/dist/npm/legacy/lite/umd/index.js +29 -19
- package/dist/npm/legacy/umd/index.js +29 -19
- package/dist/npm/modern/bundled/cjs/index.cjs +29 -19
- package/dist/npm/modern/bundled/esm/index.mjs +29 -19
- package/dist/npm/modern/bundled/umd/index.js +29 -19
- package/dist/npm/modern/cjs/index.cjs +28 -18
- package/dist/npm/modern/content-script/cjs/index.cjs +29 -19
- package/dist/npm/modern/content-script/esm/index.mjs +29 -19
- package/dist/npm/modern/content-script/umd/index.js +29 -19
- package/dist/npm/modern/esm/index.mjs +28 -18
- package/dist/npm/modern/lite/cjs/index.cjs +29 -19
- package/dist/npm/modern/lite/esm/index.mjs +29 -19
- package/dist/npm/modern/lite/umd/index.js +29 -19
- package/dist/npm/modern/umd/index.js +28 -18
- package/package.json +1 -1
|
@@ -911,7 +911,7 @@ Object.getOwnPropertyNames(err).forEach(function(key){if(key!=='message'&&key!==
|
|
|
911
911
|
}}});return newError;}catch(_unused2){return new Error("".concat(issue,": ").concat(stringifyWithoutCircular(err)));}};var dispatchErrorEvent=function dispatchErrorEvent(error){if(isTypeOfError(error)){var errStack=getStacktrace(error);if(errStack){// eslint-disable-next-line no-param-reassign
|
|
912
912
|
error.stack="".concat(errStack,"\n").concat(MANUAL_ERROR_IDENTIFIER);}}globalThis.dispatchEvent(new ErrorEvent('error',{error:error,bubbles:true,cancelable:true,composed:true}));};
|
|
913
913
|
|
|
914
|
-
var APP_NAME='RudderLabs JavaScript SDK';var APP_VERSION='3.35.
|
|
914
|
+
var APP_NAME='RudderLabs JavaScript SDK';var APP_VERSION='3.35.1';var APP_NAMESPACE='com.rudderlabs.javascript';var MODULE_TYPE='npm';var BUILD_VARIANT='legacy-content-script';var ADBLOCK_PAGE_CATEGORY='RudderJS-Initiated';var ADBLOCK_PAGE_NAME='ad-block page request';var ADBLOCK_PAGE_PATH='/ad-blocked';var GLOBAL_PRELOAD_BUFFER='preloadedEventsBuffer';var CONSENT_TRACK_EVENT_NAME='Consent Management Interaction';
|
|
915
915
|
|
|
916
916
|
var QUERY_PARAM_TRAIT_PREFIX='ajs_trait_';var QUERY_PARAM_PROPERTY_PREFIX='ajs_prop_';var QUERY_PARAM_ANONYMOUS_ID_KEY='ajs_aid';var QUERY_PARAM_USER_ID_KEY='ajs_uid';var QUERY_PARAM_TRACK_EVENT_NAME_KEY='ajs_event';
|
|
917
917
|
|
|
@@ -1425,7 +1425,7 @@ var runningQueueIdsByName=new Map();var RetryQueue=/*#__PURE__*/function(){/**
|
|
|
1425
1425
|
* Constructs a RetryQueue backed by localStorage
|
|
1426
1426
|
*
|
|
1427
1427
|
* @param {String} name The name of the queue. Will be used to find abandoned queues and retry their items
|
|
1428
|
-
* @param {QueueOpts} [options] Optional argument to override `maxItems`, `maxAttempts`, `minRetryDelay
|
|
1428
|
+
* @param {QueueOpts} [options] Optional argument to override `maxItems`, `maxAttempts`, `minRetryDelay`, `maxRetryDelay`, `backoffFactor` and `backoffJitter`.
|
|
1429
1429
|
* @param {QueueProcessCallback} queueProcessCb The function to call in order to process an item added to the queue
|
|
1430
1430
|
* @param {IStoreManager} storeManager The store manager instance to use
|
|
1431
1431
|
* @param {StorageType} [storageType] The storage type to use. Defaults to LOCAL_STORAGE
|
|
@@ -4158,18 +4158,18 @@ var _excluded=["context"];/*
|
|
|
4158
4158
|
* Analytics class with lifecycle based on state ad user triggered events
|
|
4159
4159
|
*/var Analytics=/*#__PURE__*/function(){/**
|
|
4160
4160
|
* Initialize services and components or use default ones if singletons
|
|
4161
|
-
*/function Analytics(){_classCallCheck(this,Analytics);this.preloadBuffer=new BufferQueue();this.initialized=false;this.errorHandler=defaultErrorHandler;this.logger=defaultLogger;this.customContextStore=new CustomContextStore(state.customContext,this.logger);this.externalSrcLoader=new ExternalSrcLoader(this.logger);this.httpClient=defaultHttpClient;this.httpClient.init(this.errorHandler);this.capabilitiesManager=new CapabilitiesManager(this.httpClient,this.errorHandler,this.logger);}/**
|
|
4161
|
+
*/function Analytics(){_classCallCheck(this,Analytics);this.preloadBuffer=new BufferQueue();this.initialized=false;this.isDrainingBuffer=false;this.errorHandler=defaultErrorHandler;this.logger=defaultLogger;this.customContextStore=new CustomContextStore(state.customContext,this.logger);this.externalSrcLoader=new ExternalSrcLoader(this.logger);this.httpClient=defaultHttpClient;this.httpClient.init(this.errorHandler);this.capabilitiesManager=new CapabilitiesManager(this.httpClient,this.errorHandler,this.logger);}/**
|
|
4162
4162
|
* Start application lifecycle if not already started
|
|
4163
4163
|
*/return _createClass(Analytics,[{key:"load",value:function load(writeKey,dataPlaneUrl){var _state$loadOptions$va;var loadOptions=arguments.length>2&&arguments[2]!==undefined?arguments[2]:{};if(state.lifecycle.status.value){return;}if(!isWriteKeyValid(writeKey)){this.logger.error(WRITE_KEY_VALIDATION_ERROR(ANALYTICS_CORE,writeKey));return;}if(!isDataPlaneUrlValid(dataPlaneUrl)){this.logger.error(DATA_PLANE_URL_VALIDATION_ERROR(ANALYTICS_CORE,dataPlaneUrl));return;}var customContext=loadOptions.context,loadOptionsWithoutContext=_objectWithoutProperties(loadOptions,_excluded);var sanitizedLoadOptions=getSanitizedValue(loadOptionsWithoutContext);if(customContext!==undefined){this.customContextStore.set(customContext);}// Set initial state values
|
|
4164
4164
|
n(function(){state.lifecycle.writeKey.value=clone(writeKey);state.lifecycle.dataPlaneUrl.value=clone(dataPlaneUrl);state.loadOptions.value=normalizeLoadOptions(state.loadOptions.value,sanitizedLoadOptions);state.lifecycle.status.value='mounted';});// set log level as early as possible
|
|
4165
4165
|
this.logger.setMinLogLevel((_state$loadOptions$va=state.loadOptions.value.logLevel)!==null&&_state$loadOptions$va!==void 0?_state$loadOptions$va:POST_LOAD_LOG_LEVEL);// Expose state to global objects
|
|
4166
4166
|
setExposedGlobal('state',state,writeKey);// Configure initial config of any services or components here
|
|
4167
4167
|
// State application lifecycle
|
|
4168
|
-
this.startLifecycle();}},{key:"setCustomContext",value:function setCustomContext(context){if(
|
|
4168
|
+
this.startLifecycle();}},{key:"setCustomContext",value:function setCustomContext(context){var isBufferedInvocation=arguments.length>1&&arguments[1]!==undefined?arguments[1]:false;if(this.shouldBuffer(isBufferedInvocation)){state.eventBuffer.toBeProcessedArray.value=[].concat(_toConsumableArray(state.eventBuffer.toBeProcessedArray.value),[['setCustomContext',context]]);return;}this.customContextStore.set(context);}},{key:"getCustomContext",value:function getCustomContext(){return this.customContextStore.get();}},{key:"clearCustomContext",value:function clearCustomContext(){var isBufferedInvocation=arguments.length>0&&arguments[0]!==undefined?arguments[0]:false;if(this.shouldBuffer(isBufferedInvocation)){state.eventBuffer.toBeProcessedArray.value=[].concat(_toConsumableArray(state.eventBuffer.toBeProcessedArray.value),[['clearCustomContext']]);return;}this.customContextStore.clear();}// Start lifecycle methods
|
|
4169
4169
|
/**
|
|
4170
4170
|
* Orchestrate the lifecycle of the application phases/status
|
|
4171
|
-
*/},{key:"startLifecycle",value:function startLifecycle(){var _this=this;j(function(){try{switch(state.lifecycle.status.value){case 'mounted':_this.onMounted();break;case 'browserCapabilitiesReady':_this.onBrowserCapabilitiesReady();break;case 'configured':_this.onConfigured();break;case 'pluginsLoading':break;case 'pluginsReady':_this.onPluginsReady();break;case 'initialized':_this.onInitialized();break;case 'loaded':_this.onLoaded();break;case 'destinationsLoading':break;case 'destinationsReady':_this.onDestinationsReady();break;case 'ready':_this.onReady();break;case 'readyExecuted':default:break;}}catch(err){var issue='Failed to load the SDK';_this.errorHandler.onError({error:err,context:ANALYTICS_CORE,customMessage:issue,groupingHash:issue});}});}},{key:"onBrowserCapabilitiesReady",value:function onBrowserCapabilitiesReady(){// initialize the preloaded events enqueuing
|
|
4172
|
-
retrievePreloadBufferEvents(this);this.prepareInternalServices();this.loadConfig();}},{key:"onLoaded",value:function onLoaded(){
|
|
4171
|
+
*/},{key:"startLifecycle",value:function startLifecycle(){var _this=this;j(function(){try{switch(state.lifecycle.status.value){case 'mounted':_this.onMounted();break;case 'browserCapabilitiesReady':_this.onBrowserCapabilitiesReady();break;case 'configured':_this.onConfigured();break;case 'pluginsLoading':break;case 'pluginsReady':_this.onPluginsReady();break;case 'initialized':_this.onInitialized();break;case 'loaded':_this.onLoaded();break;case 'destinationsLoading':break;case 'destinationsReady':_this.onDestinationsReady();break;case 'ready':_this.onReady();break;case 'readyExecuted':default:break;}}catch(err){var issue='Failed to load the SDK';void _this.errorHandler.onError({error:err,context:ANALYTICS_CORE,customMessage:issue,groupingHash:issue});}});}},{key:"onBrowserCapabilitiesReady",value:function onBrowserCapabilitiesReady(){// initialize the preloaded events enqueuing
|
|
4172
|
+
retrievePreloadBufferEvents(this);this.prepareInternalServices();this.loadConfig();}},{key:"onLoaded",value:function onLoaded(){// Short-circuit the life cycle and move to the ready state if pre-consent behavior is enabled
|
|
4173
4173
|
if(state.consents.preConsent.value.enabled===true){state.lifecycle.status.value='ready';}else {this.loadDestinations();}}/**
|
|
4174
4174
|
* Load browser polyfill if required
|
|
4175
4175
|
*/},{key:"onMounted",value:function onMounted(){this.capabilitiesManager.init();}/**
|
|
@@ -4190,9 +4190,12 @@ state.lifecycle.status.value='initialized';}/**
|
|
|
4190
4190
|
// registerCustomPlugins(state.loadOptions.value.customPlugins);
|
|
4191
4191
|
}/**
|
|
4192
4192
|
* Trigger onLoaded callback if any is provided in config & emit initialised event
|
|
4193
|
-
*/},{key:"onInitialized",value:function onInitialized(){//
|
|
4194
|
-
|
|
4195
|
-
|
|
4193
|
+
*/},{key:"onInitialized",value:function onInitialized(){// Preloaded calls were made before the ones buffered while initializing, so queue them first.
|
|
4194
|
+
// Exception: they stay behind any consent call made while initializing, so that consent still
|
|
4195
|
+
// applies to them as it always has (see SDK-5623)
|
|
4196
|
+
var callsDuringInitialization=state.eventBuffer.toBeProcessedArray.value;state.eventBuffer.toBeProcessedArray.value=[];this.processDataInPreloadBuffer();var lastConsentIndex=callsDuringInitialization.map(function(_ref){var _ref2=_slicedToArray(_ref,1),type=_ref2[0];return type;}).lastIndexOf('consent');state.eventBuffer.toBeProcessedArray.value=[].concat(_toConsumableArray(callsDuringInitialization.slice(0,lastConsentIndex+1)),_toConsumableArray(state.eventBuffer.toBeProcessedArray.value),_toConsumableArray(callsDuringInitialization.slice(lastConsentIndex+1)));// Set lifecycle state
|
|
4197
|
+
n(function(){state.lifecycle.loaded.value=true;state.lifecycle.status.value='loaded';});this.initialized=true;// Calls made while draining (e.g., from event callbacks) are queued behind the buffered ones
|
|
4198
|
+
this.isDrainingBuffer=true;try{this.processBufferedEvents();}finally{this.isDrainingBuffer=false;}// Execute onLoaded callback if provided in load options
|
|
4196
4199
|
var onLoadedCallbackFn=state.loadOptions.value.onLoaded;// TODO: we need to avoid passing the window object to the callback function
|
|
4197
4200
|
// as this will prevent us from supporting multiple SDK instances in the same page
|
|
4198
4201
|
safelyInvokeCallback(onLoadedCallbackFn,[globalThis.rudderanalytics],LOAD_API,this.logger);// Emit an event to use as substitute to the onLoaded callback
|
|
@@ -4205,7 +4208,11 @@ dispatchSDKEvent('RSA_Ready');}/**
|
|
|
4205
4208
|
*/},{key:"processBufferedEvents",value:function processBufferedEvents(){// This logic has been intentionally implemented without a simple
|
|
4206
4209
|
// for-loop as the individual events that are processed may
|
|
4207
4210
|
// add more events to the buffer (this is needed for the consent API)
|
|
4208
|
-
var bufferedEvents=state.eventBuffer.toBeProcessedArray.value;while(bufferedEvents.length>0){var bufferedEvent=bufferedEvents.shift();state.eventBuffer.toBeProcessedArray.value=bufferedEvents;if(bufferedEvent){
|
|
4211
|
+
var bufferedEvents=state.eventBuffer.toBeProcessedArray.value;while(bufferedEvents.length>0){var bufferedEvent=bufferedEvents.shift();state.eventBuffer.toBeProcessedArray.value=bufferedEvents;if(bufferedEvent){// A failing call must not stop the rest of the buffer or the load notifications
|
|
4212
|
+
try{this.processBufferedEvent(bufferedEvent);}catch(err){var issue='Failed to process a buffered API call';void this.errorHandler.onError({error:err,context:ANALYTICS_CORE,customMessage:issue,groupingHash:issue});}}bufferedEvents=state.eventBuffer.toBeProcessedArray.value;}}},{key:"processBufferedEvent",value:function processBufferedEvent(bufferedEvent){switch(bufferedEvent[0]){case 'setCustomContext':this.setCustomContext(bufferedEvent[1],true);break;case 'clearCustomContext':this.clearCustomContext(true);break;case 'ready':this.ready(bufferedEvent[1],true);break;case 'page':this.page(bufferedEvent[1],true,bufferedEvent[2]);break;case 'track':this.track(bufferedEvent[1],true,bufferedEvent[2]);break;case 'identify':this.identify(bufferedEvent[1],true,bufferedEvent[2]);break;case 'alias':this.alias(bufferedEvent[1],true,bufferedEvent[2]);break;case 'group':this.group(bufferedEvent[1],true,bufferedEvent[2]);break;case 'reset':this.reset(bufferedEvent[1],true);break;case 'setAnonymousId':this.setAnonymousId(bufferedEvent[1],bufferedEvent[2],true);break;case 'startSession':this.startSession(bufferedEvent[1],true);break;case 'endSession':this.endSession(true);break;case 'consent':this.consent(bufferedEvent[1],true);break;case 'addCustomIntegration':this.addCustomIntegration(bufferedEvent[1],bufferedEvent[2],true);break;default:{var unsupportedEvent=bufferedEvent;return unsupportedEvent;}}}/**
|
|
4213
|
+
* Whether an API call must be queued instead of executed now: either the SDK is not loaded yet,
|
|
4214
|
+
* or the buffer is being drained and this call was not replayed from it
|
|
4215
|
+
*/},{key:"shouldBuffer",value:function shouldBuffer(isBufferedInvocation){return !state.lifecycle.loaded.value||this.isDrainingBuffer&&!isBufferedInvocation;}},{key:"getInvocationContext",value:function getInvocationContext(preservedCustomContext){var _ref3;if(preservedCustomContext===undefined){return this.customContextStore.get();}var preparedContext=prepareCustomContextUpdate(preservedCustomContext,this.logger);return (_ref3=preparedContext)!==null&&_ref3!==void 0?_ref3:{};}/**
|
|
4209
4216
|
* Load device mode destinations
|
|
4210
4217
|
*/},{key:"loadDestinations",value:function loadDestinations(){var _this$pluginsManager4,_this$pluginsManager5;// If the integrations load is already triggered or completed, skip the rest of the logic
|
|
4211
4218
|
if(state.lifecycle.status.value==='destinationsLoading'||state.nativeDestinations.clientDestinationsReady.value===true){return;}// Set in state the desired activeDestinations to inject in DOM
|
|
@@ -4218,28 +4225,31 @@ j(function(){var areAllDestinationsReady=state.nativeDestinations.initializedDes
|
|
|
4218
4225
|
// Mark the ready status if not already done
|
|
4219
4226
|
if(state.lifecycle.status.value!=='ready'){n(function(){state.lifecycle.status.value='ready';});}}// End lifecycle methods
|
|
4220
4227
|
// Start consumer exposed methods
|
|
4221
|
-
},{key:"ready",value:function ready(callback){var type='ready';if(
|
|
4228
|
+
},{key:"ready",value:function ready(callback){var isBufferedInvocation=arguments.length>1&&arguments[1]!==undefined?arguments[1]:false;var type='ready';if(this.shouldBuffer(isBufferedInvocation)){state.eventBuffer.toBeProcessedArray.value=[].concat(_toConsumableArray(state.eventBuffer.toBeProcessedArray.value),[[type,callback]]);return;}this.errorHandler.leaveBreadcrumb("New ".concat(type," invocation"));if(!isFunction(callback)){this.logger.error(INVALID_CALLBACK_FN_ERROR(READY_API));return;}/**
|
|
4222
4229
|
* If destinations are loaded or no integration is available for loading
|
|
4223
4230
|
* execute the callback immediately else push the callbacks to a queue that
|
|
4224
4231
|
* will be executed after loading completes
|
|
4225
|
-
*/if(state.lifecycle.status.value==='readyExecuted'){safelyInvokeCallback(callback,[],READY_API,this.logger);}else {state.eventBuffer.readyCallbacksArray.value=[].concat(_toConsumableArray(state.eventBuffer.readyCallbacksArray.value),[callback]);}}},{key:"page",value:function page(payload){var _this$eventManager2;var isBufferedInvocation=arguments.length>1&&arguments[1]!==undefined?arguments[1]:false;var preservedCustomContext=arguments.length>2?arguments[2]:undefined;var type='page';if(
|
|
4232
|
+
*/if(state.lifecycle.status.value==='readyExecuted'){safelyInvokeCallback(callback,[],READY_API,this.logger);}else {state.eventBuffer.readyCallbacksArray.value=[].concat(_toConsumableArray(state.eventBuffer.readyCallbacksArray.value),[callback]);}}},{key:"page",value:function page(payload){var _this$eventManager2;var isBufferedInvocation=arguments.length>1&&arguments[1]!==undefined?arguments[1]:false;var preservedCustomContext=arguments.length>2?arguments[2]:undefined;var type='page';if(this.shouldBuffer(isBufferedInvocation)){state.eventBuffer.toBeProcessedArray.value=[].concat(_toConsumableArray(state.eventBuffer.toBeProcessedArray.value),[[type,payload]]);return;}var invocationContext=this.getInvocationContext(preservedCustomContext);this.errorHandler.leaveBreadcrumb("New ".concat(type," event"));state.metrics.triggered.value+=1;(_this$eventManager2=this.eventManager)===null||_this$eventManager2===void 0||_this$eventManager2.addEvent({type:'page',category:payload.category,name:payload.name,properties:payload.properties,options:payload.options,callback:payload.callback},invocationContext);// TODO: Maybe we should alter the behavior to send the ad-block page event even if the SDK is still loaded. It'll be pushed into the to be processed queue.
|
|
4226
4233
|
// Send automatic ad blocked page event if ad-blockers are detected on the page
|
|
4227
4234
|
// Check page category to avoid infinite loop
|
|
4228
4235
|
if(state.capabilities.isAdBlocked.value===true&&payload.category!==ADBLOCK_PAGE_CATEGORY){this.page(pageArgumentsToCallOptions(ADBLOCK_PAGE_CATEGORY,ADBLOCK_PAGE_NAME,{// 'title' is intentionally omitted as it does not make sense
|
|
4229
4236
|
// in v3 implementation
|
|
4230
|
-
path:ADBLOCK_PAGE_PATH},state.loadOptions.value.sendAdblockPageOptions),isBufferedInvocation,invocationContext);}}},{key:"track",value:function track(payload){var _this$eventManager3;var preservedCustomContext=arguments.length>2?arguments[2]:undefined;var type='track';if(
|
|
4231
|
-
|
|
4232
|
-
if(!isNull(payload.
|
|
4233
|
-
if(!
|
|
4237
|
+
path:ADBLOCK_PAGE_PATH},state.loadOptions.value.sendAdblockPageOptions),isBufferedInvocation,invocationContext);}}},{key:"track",value:function track(payload){var _this$eventManager3;var isBufferedInvocation=arguments.length>1&&arguments[1]!==undefined?arguments[1]:false;var preservedCustomContext=arguments.length>2?arguments[2]:undefined;var type='track';if(this.shouldBuffer(isBufferedInvocation)){state.eventBuffer.toBeProcessedArray.value=[].concat(_toConsumableArray(state.eventBuffer.toBeProcessedArray.value),[[type,payload]]);return;}var invocationContext=this.getInvocationContext(preservedCustomContext);this.errorHandler.leaveBreadcrumb("New ".concat(type," event - ").concat(payload.name));state.metrics.triggered.value+=1;(_this$eventManager3=this.eventManager)===null||_this$eventManager3===void 0||_this$eventManager3.addEvent({type:type,name:payload.name||undefined,properties:payload.properties,options:payload.options,callback:payload.callback},invocationContext);}},{key:"identify",value:function identify(payload){var _this$userSessionMana3,_this$eventManager4;var isBufferedInvocation=arguments.length>1&&arguments[1]!==undefined?arguments[1]:false;var preservedCustomContext=arguments.length>2?arguments[2]:undefined;var type='identify';if(this.shouldBuffer(isBufferedInvocation)){state.eventBuffer.toBeProcessedArray.value=[].concat(_toConsumableArray(state.eventBuffer.toBeProcessedArray.value),[[type,payload]]);return;}var invocationContext=this.getInvocationContext(preservedCustomContext);this.errorHandler.leaveBreadcrumb("New ".concat(type," event"));state.metrics.triggered.value+=1;var shouldResetSession=Boolean(payload.userId&&state.session.userId.value&&payload.userId!==state.session.userId.value);if(shouldResetSession){// Part of this identify call, so it must not be deferred behind other buffered calls
|
|
4238
|
+
this.reset(undefined,true);}// `null` value indicates that previous user ID needs to be retained
|
|
4239
|
+
if(!isNull(payload.userId)){var _this$userSessionMana2;(_this$userSessionMana2=this.userSessionManager)===null||_this$userSessionMana2===void 0||_this$userSessionMana2.setUserId(payload.userId);}(_this$userSessionMana3=this.userSessionManager)===null||_this$userSessionMana3===void 0||_this$userSessionMana3.setUserTraits(payload.traits);(_this$eventManager4=this.eventManager)===null||_this$eventManager4===void 0||_this$eventManager4.addEvent({type:type,userId:payload.userId,traits:payload.traits,options:payload.options,callback:payload.callback},invocationContext);}},{key:"alias",value:function alias(payload){var _payload$from,_this$userSessionMana4,_this$eventManager5;var isBufferedInvocation=arguments.length>1&&arguments[1]!==undefined?arguments[1]:false;var preservedCustomContext=arguments.length>2?arguments[2]:undefined;var type='alias';if(this.shouldBuffer(isBufferedInvocation)){state.eventBuffer.toBeProcessedArray.value=[].concat(_toConsumableArray(state.eventBuffer.toBeProcessedArray.value),[[type,payload]]);return;}var invocationContext=this.getInvocationContext(preservedCustomContext);this.errorHandler.leaveBreadcrumb("New ".concat(type," event"));state.metrics.triggered.value+=1;var previousId=(_payload$from=payload.from)!==null&&_payload$from!==void 0?_payload$from:this.getUserId()||((_this$userSessionMana4=this.userSessionManager)===null||_this$userSessionMana4===void 0?void 0:_this$userSessionMana4.getAnonymousId());(_this$eventManager5=this.eventManager)===null||_this$eventManager5===void 0||_this$eventManager5.addEvent({type:type,to:payload.to,from:previousId,options:payload.options,callback:payload.callback},invocationContext);}},{key:"group",value:function group(payload){var _this$userSessionMana6,_this$eventManager6;var isBufferedInvocation=arguments.length>1&&arguments[1]!==undefined?arguments[1]:false;var preservedCustomContext=arguments.length>2?arguments[2]:undefined;var type='group';if(this.shouldBuffer(isBufferedInvocation)){state.eventBuffer.toBeProcessedArray.value=[].concat(_toConsumableArray(state.eventBuffer.toBeProcessedArray.value),[[type,payload]]);return;}var invocationContext=this.getInvocationContext(preservedCustomContext);this.errorHandler.leaveBreadcrumb("New ".concat(type," event"));state.metrics.triggered.value+=1;// `null` value indicates that previous group ID needs to be retained
|
|
4240
|
+
if(!isNull(payload.groupId)){var _this$userSessionMana5;(_this$userSessionMana5=this.userSessionManager)===null||_this$userSessionMana5===void 0||_this$userSessionMana5.setGroupId(payload.groupId);}(_this$userSessionMana6=this.userSessionManager)===null||_this$userSessionMana6===void 0||_this$userSessionMana6.setGroupTraits(payload.traits);(_this$eventManager6=this.eventManager)===null||_this$eventManager6===void 0||_this$eventManager6.addEvent({type:type,groupId:payload.groupId,traits:payload.traits,options:payload.options,callback:payload.callback},invocationContext);}},{key:"reset",value:function reset(options){var _this$userSessionMana7;var isBufferedInvocation=arguments.length>1&&arguments[1]!==undefined?arguments[1]:false;var type='reset';if(this.shouldBuffer(isBufferedInvocation)){state.eventBuffer.toBeProcessedArray.value=[].concat(_toConsumableArray(state.eventBuffer.toBeProcessedArray.value),[[type,options]]);return;}this.errorHandler.leaveBreadcrumb("New ".concat(type," invocation"));(_this$userSessionMana7=this.userSessionManager)===null||_this$userSessionMana7===void 0||_this$userSessionMana7.reset(options);}},{key:"getAnonymousId",value:function getAnonymousId(options){var _this$userSessionMana8;return (_this$userSessionMana8=this.userSessionManager)===null||_this$userSessionMana8===void 0?void 0:_this$userSessionMana8.getAnonymousId(options);}},{key:"setAnonymousId",value:function setAnonymousId(anonymousId,rudderAmpLinkerParam){var _this$userSessionMana9;var isBufferedInvocation=arguments.length>2&&arguments[2]!==undefined?arguments[2]:false;var type='setAnonymousId';// Buffering is needed as setting the anonymous ID may require invoking the GoogleLinker plugin
|
|
4241
|
+
if(this.shouldBuffer(isBufferedInvocation)){state.eventBuffer.toBeProcessedArray.value=[].concat(_toConsumableArray(state.eventBuffer.toBeProcessedArray.value),[[type,anonymousId,rudderAmpLinkerParam]]);return;}this.errorHandler.leaveBreadcrumb("New ".concat(type," invocation"));(_this$userSessionMana9=this.userSessionManager)===null||_this$userSessionMana9===void 0||_this$userSessionMana9.setAnonymousId(anonymousId,rudderAmpLinkerParam);}// eslint-disable-next-line class-methods-use-this
|
|
4234
4242
|
},{key:"getUserId",value:function getUserId(){return state.session.userId.value;}// eslint-disable-next-line class-methods-use-this
|
|
4235
4243
|
},{key:"getUserTraits",value:function getUserTraits(){return state.session.userTraits.value;}// eslint-disable-next-line class-methods-use-this
|
|
4236
4244
|
},{key:"getGroupId",value:function getGroupId(){return state.session.groupId.value;}// eslint-disable-next-line class-methods-use-this
|
|
4237
|
-
},{key:"getGroupTraits",value:function getGroupTraits(){return state.session.groupTraits.value;}},{key:"startSession",value:function startSession(sessionId){var _this$userSessionMana0;var type='startSession';if(
|
|
4238
|
-
},{key:"getSessionId",value:function getSessionId(){var _this$userSessionMana10;var sessionId=(_this$userSessionMana10=this.userSessionManager)===null||_this$userSessionMana10===void 0?void 0:_this$userSessionMana10.getSessionId();return sessionId!==null&&sessionId!==void 0?sessionId:null;}},{key:"consent",value:function consent(options){var _this4=this,_this$storeManager2,_this$userSessionMana11,_this$eventManager7;var isBufferedInvocation=arguments.length>1&&arguments[1]!==undefined?arguments[1]:false;var type='consent';if(
|
|
4245
|
+
},{key:"getGroupTraits",value:function getGroupTraits(){return state.session.groupTraits.value;}},{key:"startSession",value:function startSession(sessionId){var _this$userSessionMana0;var isBufferedInvocation=arguments.length>1&&arguments[1]!==undefined?arguments[1]:false;var type='startSession';if(this.shouldBuffer(isBufferedInvocation)){state.eventBuffer.toBeProcessedArray.value=[].concat(_toConsumableArray(state.eventBuffer.toBeProcessedArray.value),[[type,sessionId]]);return;}this.errorHandler.leaveBreadcrumb("New ".concat(type," invocation"));(_this$userSessionMana0=this.userSessionManager)===null||_this$userSessionMana0===void 0||_this$userSessionMana0.start(sessionId);}},{key:"endSession",value:function endSession(){var _this$userSessionMana1;var isBufferedInvocation=arguments.length>0&&arguments[0]!==undefined?arguments[0]:false;var type='endSession';if(this.shouldBuffer(isBufferedInvocation)){state.eventBuffer.toBeProcessedArray.value=[].concat(_toConsumableArray(state.eventBuffer.toBeProcessedArray.value),[[type]]);return;}this.errorHandler.leaveBreadcrumb("New ".concat(type," invocation"));(_this$userSessionMana1=this.userSessionManager)===null||_this$userSessionMana1===void 0||_this$userSessionMana1.end();}// eslint-disable-next-line class-methods-use-this
|
|
4246
|
+
},{key:"getSessionId",value:function getSessionId(){var _this$userSessionMana10;var sessionId=(_this$userSessionMana10=this.userSessionManager)===null||_this$userSessionMana10===void 0?void 0:_this$userSessionMana10.getSessionId();return sessionId!==null&&sessionId!==void 0?sessionId:null;}},{key:"consent",value:function consent(options){var _this4=this,_this$storeManager2,_this$userSessionMana11,_this$eventManager7;var isBufferedInvocation=arguments.length>1&&arguments[1]!==undefined?arguments[1]:false;var type='consent';if(this.shouldBuffer(isBufferedInvocation)){state.eventBuffer.toBeProcessedArray.value=[].concat(_toConsumableArray(state.eventBuffer.toBeProcessedArray.value),[[type,options]]);return;}this.errorHandler.leaveBreadcrumb("New consent invocation");n(function(){state.consents.preConsent.value=_objectSpread2(_objectSpread2({},state.consents.preConsent.value),{},{enabled:false});state.consents.postConsent.value=getValidPostConsentOptions(options,_this4.logger);var _getConsentManagement=getConsentManagementData(state.consents.postConsent.value.consentManagement,_this4.logger),initialized=_getConsentManagement.initialized,consentsData=_getConsentManagement.consentsData;state.consents.initialized.value=initialized;state.consents.data.value=consentsData;});// Update consents data in state
|
|
4239
4247
|
if(state.consents.enabled.value&&!state.consents.initialized.value){var _this$pluginsManager6;(_this$pluginsManager6=this.pluginsManager)===null||_this$pluginsManager6===void 0||_this$pluginsManager6.invokeSingle("consentManager.updateConsentsInfo",state,this.storeManager,this.logger);}// Re-init store manager
|
|
4240
4248
|
(_this$storeManager2=this.storeManager)===null||_this$storeManager2===void 0||_this$storeManager2.initializeStorageState();// Re-init user session manager
|
|
4241
4249
|
(_this$userSessionMana11=this.userSessionManager)===null||_this$userSessionMana11===void 0||_this$userSessionMana11.syncStorageDataToState();// Resume event manager to process the events to destinations
|
|
4242
|
-
(_this$eventManager7=this.eventManager)===null||_this$eventManager7===void 0||_this$eventManager7.resume()
|
|
4250
|
+
(_this$eventManager7=this.eventManager)===null||_this$eventManager7===void 0||_this$eventManager7.resume();// While replaying, defer to the 'loaded' lifecycle handler so that custom integrations
|
|
4251
|
+
// added later in the buffer are registered before destinations are loaded
|
|
4252
|
+
if(!this.isDrainingBuffer){this.loadDestinations();}this.sendTrackingEvents(isBufferedInvocation);}},{key:"sendTrackingEvents",value:function sendTrackingEvents(isBufferedInvocation){// If isBufferedInvocation is true, then the tracking events will be added to the end of the
|
|
4243
4253
|
// events buffer array so that any other preload events (mainly from query string API) will be processed first.
|
|
4244
4254
|
if(state.consents.postConsent.value.trackConsent){var trackOptions=trackArgumentsToCallOptions(CONSENT_TRACK_EVENT_NAME);if(isBufferedInvocation){state.eventBuffer.toBeProcessedArray.value=[].concat(_toConsumableArray(state.eventBuffer.toBeProcessedArray.value),[['track',trackOptions,this.customContextStore.get()]]);}else {this.track(trackOptions);}}if(state.consents.postConsent.value.sendPageEvent){var pageOptions=pageArgumentsToCallOptions();if(isBufferedInvocation){state.eventBuffer.toBeProcessedArray.value=[].concat(_toConsumableArray(state.eventBuffer.toBeProcessedArray.value),[['page',pageOptions,this.customContextStore.get()]]);}else {this.page(pageOptions);}}}},{key:"setAuthToken",value:function setAuthToken(token){var _this$userSessionMana12;(_this$userSessionMana12=this.userSessionManager)===null||_this$userSessionMana12===void 0||_this$userSessionMana12.setAuthToken(token);}/**
|
|
4245
4255
|
* Add a custom integration for a custom destination.
|
|
@@ -917,7 +917,7 @@
|
|
|
917
917
|
}}});return newError;}catch(_unused2){return new Error("".concat(issue,": ").concat(stringifyWithoutCircular(err)));}};var dispatchErrorEvent=function dispatchErrorEvent(error){if(isTypeOfError(error)){var errStack=getStacktrace(error);if(errStack){// eslint-disable-next-line no-param-reassign
|
|
918
918
|
error.stack="".concat(errStack,"\n").concat(MANUAL_ERROR_IDENTIFIER);}}globalThis.dispatchEvent(new ErrorEvent('error',{error:error,bubbles:true,cancelable:true,composed:true}));};
|
|
919
919
|
|
|
920
|
-
var APP_NAME='RudderLabs JavaScript SDK';var APP_VERSION='3.35.
|
|
920
|
+
var APP_NAME='RudderLabs JavaScript SDK';var APP_VERSION='3.35.1';var APP_NAMESPACE='com.rudderlabs.javascript';var MODULE_TYPE='npm';var BUILD_VARIANT='legacy-content-script';var ADBLOCK_PAGE_CATEGORY='RudderJS-Initiated';var ADBLOCK_PAGE_NAME='ad-block page request';var ADBLOCK_PAGE_PATH='/ad-blocked';var GLOBAL_PRELOAD_BUFFER='preloadedEventsBuffer';var CONSENT_TRACK_EVENT_NAME='Consent Management Interaction';
|
|
921
921
|
|
|
922
922
|
var QUERY_PARAM_TRAIT_PREFIX='ajs_trait_';var QUERY_PARAM_PROPERTY_PREFIX='ajs_prop_';var QUERY_PARAM_ANONYMOUS_ID_KEY='ajs_aid';var QUERY_PARAM_USER_ID_KEY='ajs_uid';var QUERY_PARAM_TRACK_EVENT_NAME_KEY='ajs_event';
|
|
923
923
|
|
|
@@ -1431,7 +1431,7 @@
|
|
|
1431
1431
|
* Constructs a RetryQueue backed by localStorage
|
|
1432
1432
|
*
|
|
1433
1433
|
* @param {String} name The name of the queue. Will be used to find abandoned queues and retry their items
|
|
1434
|
-
* @param {QueueOpts} [options] Optional argument to override `maxItems`, `maxAttempts`, `minRetryDelay
|
|
1434
|
+
* @param {QueueOpts} [options] Optional argument to override `maxItems`, `maxAttempts`, `minRetryDelay`, `maxRetryDelay`, `backoffFactor` and `backoffJitter`.
|
|
1435
1435
|
* @param {QueueProcessCallback} queueProcessCb The function to call in order to process an item added to the queue
|
|
1436
1436
|
* @param {IStoreManager} storeManager The store manager instance to use
|
|
1437
1437
|
* @param {StorageType} [storageType] The storage type to use. Defaults to LOCAL_STORAGE
|
|
@@ -4164,18 +4164,18 @@
|
|
|
4164
4164
|
* Analytics class with lifecycle based on state ad user triggered events
|
|
4165
4165
|
*/var Analytics=/*#__PURE__*/function(){/**
|
|
4166
4166
|
* Initialize services and components or use default ones if singletons
|
|
4167
|
-
*/function Analytics(){_classCallCheck(this,Analytics);this.preloadBuffer=new BufferQueue();this.initialized=false;this.errorHandler=defaultErrorHandler;this.logger=defaultLogger;this.customContextStore=new CustomContextStore(state.customContext,this.logger);this.externalSrcLoader=new ExternalSrcLoader(this.logger);this.httpClient=defaultHttpClient;this.httpClient.init(this.errorHandler);this.capabilitiesManager=new CapabilitiesManager(this.httpClient,this.errorHandler,this.logger);}/**
|
|
4167
|
+
*/function Analytics(){_classCallCheck(this,Analytics);this.preloadBuffer=new BufferQueue();this.initialized=false;this.isDrainingBuffer=false;this.errorHandler=defaultErrorHandler;this.logger=defaultLogger;this.customContextStore=new CustomContextStore(state.customContext,this.logger);this.externalSrcLoader=new ExternalSrcLoader(this.logger);this.httpClient=defaultHttpClient;this.httpClient.init(this.errorHandler);this.capabilitiesManager=new CapabilitiesManager(this.httpClient,this.errorHandler,this.logger);}/**
|
|
4168
4168
|
* Start application lifecycle if not already started
|
|
4169
4169
|
*/return _createClass(Analytics,[{key:"load",value:function load(writeKey,dataPlaneUrl){var _state$loadOptions$va;var loadOptions=arguments.length>2&&arguments[2]!==undefined?arguments[2]:{};if(state.lifecycle.status.value){return;}if(!isWriteKeyValid(writeKey)){this.logger.error(WRITE_KEY_VALIDATION_ERROR(ANALYTICS_CORE,writeKey));return;}if(!isDataPlaneUrlValid(dataPlaneUrl)){this.logger.error(DATA_PLANE_URL_VALIDATION_ERROR(ANALYTICS_CORE,dataPlaneUrl));return;}var customContext=loadOptions.context,loadOptionsWithoutContext=_objectWithoutProperties(loadOptions,_excluded);var sanitizedLoadOptions=getSanitizedValue(loadOptionsWithoutContext);if(customContext!==undefined){this.customContextStore.set(customContext);}// Set initial state values
|
|
4170
4170
|
n(function(){state.lifecycle.writeKey.value=clone(writeKey);state.lifecycle.dataPlaneUrl.value=clone(dataPlaneUrl);state.loadOptions.value=normalizeLoadOptions(state.loadOptions.value,sanitizedLoadOptions);state.lifecycle.status.value='mounted';});// set log level as early as possible
|
|
4171
4171
|
this.logger.setMinLogLevel((_state$loadOptions$va=state.loadOptions.value.logLevel)!==null&&_state$loadOptions$va!==void 0?_state$loadOptions$va:POST_LOAD_LOG_LEVEL);// Expose state to global objects
|
|
4172
4172
|
setExposedGlobal('state',state,writeKey);// Configure initial config of any services or components here
|
|
4173
4173
|
// State application lifecycle
|
|
4174
|
-
this.startLifecycle();}},{key:"setCustomContext",value:function setCustomContext(context){if(
|
|
4174
|
+
this.startLifecycle();}},{key:"setCustomContext",value:function setCustomContext(context){var isBufferedInvocation=arguments.length>1&&arguments[1]!==undefined?arguments[1]:false;if(this.shouldBuffer(isBufferedInvocation)){state.eventBuffer.toBeProcessedArray.value=[].concat(_toConsumableArray(state.eventBuffer.toBeProcessedArray.value),[['setCustomContext',context]]);return;}this.customContextStore.set(context);}},{key:"getCustomContext",value:function getCustomContext(){return this.customContextStore.get();}},{key:"clearCustomContext",value:function clearCustomContext(){var isBufferedInvocation=arguments.length>0&&arguments[0]!==undefined?arguments[0]:false;if(this.shouldBuffer(isBufferedInvocation)){state.eventBuffer.toBeProcessedArray.value=[].concat(_toConsumableArray(state.eventBuffer.toBeProcessedArray.value),[['clearCustomContext']]);return;}this.customContextStore.clear();}// Start lifecycle methods
|
|
4175
4175
|
/**
|
|
4176
4176
|
* Orchestrate the lifecycle of the application phases/status
|
|
4177
|
-
*/},{key:"startLifecycle",value:function startLifecycle(){var _this=this;j(function(){try{switch(state.lifecycle.status.value){case 'mounted':_this.onMounted();break;case 'browserCapabilitiesReady':_this.onBrowserCapabilitiesReady();break;case 'configured':_this.onConfigured();break;case 'pluginsLoading':break;case 'pluginsReady':_this.onPluginsReady();break;case 'initialized':_this.onInitialized();break;case 'loaded':_this.onLoaded();break;case 'destinationsLoading':break;case 'destinationsReady':_this.onDestinationsReady();break;case 'ready':_this.onReady();break;case 'readyExecuted':default:break;}}catch(err){var issue='Failed to load the SDK';_this.errorHandler.onError({error:err,context:ANALYTICS_CORE,customMessage:issue,groupingHash:issue});}});}},{key:"onBrowserCapabilitiesReady",value:function onBrowserCapabilitiesReady(){// initialize the preloaded events enqueuing
|
|
4178
|
-
retrievePreloadBufferEvents(this);this.prepareInternalServices();this.loadConfig();}},{key:"onLoaded",value:function onLoaded(){
|
|
4177
|
+
*/},{key:"startLifecycle",value:function startLifecycle(){var _this=this;j(function(){try{switch(state.lifecycle.status.value){case 'mounted':_this.onMounted();break;case 'browserCapabilitiesReady':_this.onBrowserCapabilitiesReady();break;case 'configured':_this.onConfigured();break;case 'pluginsLoading':break;case 'pluginsReady':_this.onPluginsReady();break;case 'initialized':_this.onInitialized();break;case 'loaded':_this.onLoaded();break;case 'destinationsLoading':break;case 'destinationsReady':_this.onDestinationsReady();break;case 'ready':_this.onReady();break;case 'readyExecuted':default:break;}}catch(err){var issue='Failed to load the SDK';void _this.errorHandler.onError({error:err,context:ANALYTICS_CORE,customMessage:issue,groupingHash:issue});}});}},{key:"onBrowserCapabilitiesReady",value:function onBrowserCapabilitiesReady(){// initialize the preloaded events enqueuing
|
|
4178
|
+
retrievePreloadBufferEvents(this);this.prepareInternalServices();this.loadConfig();}},{key:"onLoaded",value:function onLoaded(){// Short-circuit the life cycle and move to the ready state if pre-consent behavior is enabled
|
|
4179
4179
|
if(state.consents.preConsent.value.enabled===true){state.lifecycle.status.value='ready';}else {this.loadDestinations();}}/**
|
|
4180
4180
|
* Load browser polyfill if required
|
|
4181
4181
|
*/},{key:"onMounted",value:function onMounted(){this.capabilitiesManager.init();}/**
|
|
@@ -4196,9 +4196,12 @@
|
|
|
4196
4196
|
// registerCustomPlugins(state.loadOptions.value.customPlugins);
|
|
4197
4197
|
}/**
|
|
4198
4198
|
* Trigger onLoaded callback if any is provided in config & emit initialised event
|
|
4199
|
-
*/},{key:"onInitialized",value:function onInitialized(){//
|
|
4200
|
-
|
|
4201
|
-
|
|
4199
|
+
*/},{key:"onInitialized",value:function onInitialized(){// Preloaded calls were made before the ones buffered while initializing, so queue them first.
|
|
4200
|
+
// Exception: they stay behind any consent call made while initializing, so that consent still
|
|
4201
|
+
// applies to them as it always has (see SDK-5623)
|
|
4202
|
+
var callsDuringInitialization=state.eventBuffer.toBeProcessedArray.value;state.eventBuffer.toBeProcessedArray.value=[];this.processDataInPreloadBuffer();var lastConsentIndex=callsDuringInitialization.map(function(_ref){var _ref2=_slicedToArray(_ref,1),type=_ref2[0];return type;}).lastIndexOf('consent');state.eventBuffer.toBeProcessedArray.value=[].concat(_toConsumableArray(callsDuringInitialization.slice(0,lastConsentIndex+1)),_toConsumableArray(state.eventBuffer.toBeProcessedArray.value),_toConsumableArray(callsDuringInitialization.slice(lastConsentIndex+1)));// Set lifecycle state
|
|
4203
|
+
n(function(){state.lifecycle.loaded.value=true;state.lifecycle.status.value='loaded';});this.initialized=true;// Calls made while draining (e.g., from event callbacks) are queued behind the buffered ones
|
|
4204
|
+
this.isDrainingBuffer=true;try{this.processBufferedEvents();}finally{this.isDrainingBuffer=false;}// Execute onLoaded callback if provided in load options
|
|
4202
4205
|
var onLoadedCallbackFn=state.loadOptions.value.onLoaded;// TODO: we need to avoid passing the window object to the callback function
|
|
4203
4206
|
// as this will prevent us from supporting multiple SDK instances in the same page
|
|
4204
4207
|
safelyInvokeCallback(onLoadedCallbackFn,[globalThis.rudderanalytics],LOAD_API,this.logger);// Emit an event to use as substitute to the onLoaded callback
|
|
@@ -4211,7 +4214,11 @@
|
|
|
4211
4214
|
*/},{key:"processBufferedEvents",value:function processBufferedEvents(){// This logic has been intentionally implemented without a simple
|
|
4212
4215
|
// for-loop as the individual events that are processed may
|
|
4213
4216
|
// add more events to the buffer (this is needed for the consent API)
|
|
4214
|
-
var bufferedEvents=state.eventBuffer.toBeProcessedArray.value;while(bufferedEvents.length>0){var bufferedEvent=bufferedEvents.shift();state.eventBuffer.toBeProcessedArray.value=bufferedEvents;if(bufferedEvent){
|
|
4217
|
+
var bufferedEvents=state.eventBuffer.toBeProcessedArray.value;while(bufferedEvents.length>0){var bufferedEvent=bufferedEvents.shift();state.eventBuffer.toBeProcessedArray.value=bufferedEvents;if(bufferedEvent){// A failing call must not stop the rest of the buffer or the load notifications
|
|
4218
|
+
try{this.processBufferedEvent(bufferedEvent);}catch(err){var issue='Failed to process a buffered API call';void this.errorHandler.onError({error:err,context:ANALYTICS_CORE,customMessage:issue,groupingHash:issue});}}bufferedEvents=state.eventBuffer.toBeProcessedArray.value;}}},{key:"processBufferedEvent",value:function processBufferedEvent(bufferedEvent){switch(bufferedEvent[0]){case 'setCustomContext':this.setCustomContext(bufferedEvent[1],true);break;case 'clearCustomContext':this.clearCustomContext(true);break;case 'ready':this.ready(bufferedEvent[1],true);break;case 'page':this.page(bufferedEvent[1],true,bufferedEvent[2]);break;case 'track':this.track(bufferedEvent[1],true,bufferedEvent[2]);break;case 'identify':this.identify(bufferedEvent[1],true,bufferedEvent[2]);break;case 'alias':this.alias(bufferedEvent[1],true,bufferedEvent[2]);break;case 'group':this.group(bufferedEvent[1],true,bufferedEvent[2]);break;case 'reset':this.reset(bufferedEvent[1],true);break;case 'setAnonymousId':this.setAnonymousId(bufferedEvent[1],bufferedEvent[2],true);break;case 'startSession':this.startSession(bufferedEvent[1],true);break;case 'endSession':this.endSession(true);break;case 'consent':this.consent(bufferedEvent[1],true);break;case 'addCustomIntegration':this.addCustomIntegration(bufferedEvent[1],bufferedEvent[2],true);break;default:{var unsupportedEvent=bufferedEvent;return unsupportedEvent;}}}/**
|
|
4219
|
+
* Whether an API call must be queued instead of executed now: either the SDK is not loaded yet,
|
|
4220
|
+
* or the buffer is being drained and this call was not replayed from it
|
|
4221
|
+
*/},{key:"shouldBuffer",value:function shouldBuffer(isBufferedInvocation){return !state.lifecycle.loaded.value||this.isDrainingBuffer&&!isBufferedInvocation;}},{key:"getInvocationContext",value:function getInvocationContext(preservedCustomContext){var _ref3;if(preservedCustomContext===undefined){return this.customContextStore.get();}var preparedContext=prepareCustomContextUpdate(preservedCustomContext,this.logger);return (_ref3=preparedContext)!==null&&_ref3!==void 0?_ref3:{};}/**
|
|
4215
4222
|
* Load device mode destinations
|
|
4216
4223
|
*/},{key:"loadDestinations",value:function loadDestinations(){var _this$pluginsManager4,_this$pluginsManager5;// If the integrations load is already triggered or completed, skip the rest of the logic
|
|
4217
4224
|
if(state.lifecycle.status.value==='destinationsLoading'||state.nativeDestinations.clientDestinationsReady.value===true){return;}// Set in state the desired activeDestinations to inject in DOM
|
|
@@ -4224,28 +4231,31 @@
|
|
|
4224
4231
|
// Mark the ready status if not already done
|
|
4225
4232
|
if(state.lifecycle.status.value!=='ready'){n(function(){state.lifecycle.status.value='ready';});}}// End lifecycle methods
|
|
4226
4233
|
// Start consumer exposed methods
|
|
4227
|
-
},{key:"ready",value:function ready(callback){var type='ready';if(
|
|
4234
|
+
},{key:"ready",value:function ready(callback){var isBufferedInvocation=arguments.length>1&&arguments[1]!==undefined?arguments[1]:false;var type='ready';if(this.shouldBuffer(isBufferedInvocation)){state.eventBuffer.toBeProcessedArray.value=[].concat(_toConsumableArray(state.eventBuffer.toBeProcessedArray.value),[[type,callback]]);return;}this.errorHandler.leaveBreadcrumb("New ".concat(type," invocation"));if(!isFunction(callback)){this.logger.error(INVALID_CALLBACK_FN_ERROR(READY_API));return;}/**
|
|
4228
4235
|
* If destinations are loaded or no integration is available for loading
|
|
4229
4236
|
* execute the callback immediately else push the callbacks to a queue that
|
|
4230
4237
|
* will be executed after loading completes
|
|
4231
|
-
*/if(state.lifecycle.status.value==='readyExecuted'){safelyInvokeCallback(callback,[],READY_API,this.logger);}else {state.eventBuffer.readyCallbacksArray.value=[].concat(_toConsumableArray(state.eventBuffer.readyCallbacksArray.value),[callback]);}}},{key:"page",value:function page(payload){var _this$eventManager2;var isBufferedInvocation=arguments.length>1&&arguments[1]!==undefined?arguments[1]:false;var preservedCustomContext=arguments.length>2?arguments[2]:undefined;var type='page';if(
|
|
4238
|
+
*/if(state.lifecycle.status.value==='readyExecuted'){safelyInvokeCallback(callback,[],READY_API,this.logger);}else {state.eventBuffer.readyCallbacksArray.value=[].concat(_toConsumableArray(state.eventBuffer.readyCallbacksArray.value),[callback]);}}},{key:"page",value:function page(payload){var _this$eventManager2;var isBufferedInvocation=arguments.length>1&&arguments[1]!==undefined?arguments[1]:false;var preservedCustomContext=arguments.length>2?arguments[2]:undefined;var type='page';if(this.shouldBuffer(isBufferedInvocation)){state.eventBuffer.toBeProcessedArray.value=[].concat(_toConsumableArray(state.eventBuffer.toBeProcessedArray.value),[[type,payload]]);return;}var invocationContext=this.getInvocationContext(preservedCustomContext);this.errorHandler.leaveBreadcrumb("New ".concat(type," event"));state.metrics.triggered.value+=1;(_this$eventManager2=this.eventManager)===null||_this$eventManager2===void 0||_this$eventManager2.addEvent({type:'page',category:payload.category,name:payload.name,properties:payload.properties,options:payload.options,callback:payload.callback},invocationContext);// TODO: Maybe we should alter the behavior to send the ad-block page event even if the SDK is still loaded. It'll be pushed into the to be processed queue.
|
|
4232
4239
|
// Send automatic ad blocked page event if ad-blockers are detected on the page
|
|
4233
4240
|
// Check page category to avoid infinite loop
|
|
4234
4241
|
if(state.capabilities.isAdBlocked.value===true&&payload.category!==ADBLOCK_PAGE_CATEGORY){this.page(pageArgumentsToCallOptions(ADBLOCK_PAGE_CATEGORY,ADBLOCK_PAGE_NAME,{// 'title' is intentionally omitted as it does not make sense
|
|
4235
4242
|
// in v3 implementation
|
|
4236
|
-
path:ADBLOCK_PAGE_PATH},state.loadOptions.value.sendAdblockPageOptions),isBufferedInvocation,invocationContext);}}},{key:"track",value:function track(payload){var _this$eventManager3;var preservedCustomContext=arguments.length>2?arguments[2]:undefined;var type='track';if(
|
|
4237
|
-
|
|
4238
|
-
if(!isNull(payload.
|
|
4239
|
-
if(!
|
|
4243
|
+
path:ADBLOCK_PAGE_PATH},state.loadOptions.value.sendAdblockPageOptions),isBufferedInvocation,invocationContext);}}},{key:"track",value:function track(payload){var _this$eventManager3;var isBufferedInvocation=arguments.length>1&&arguments[1]!==undefined?arguments[1]:false;var preservedCustomContext=arguments.length>2?arguments[2]:undefined;var type='track';if(this.shouldBuffer(isBufferedInvocation)){state.eventBuffer.toBeProcessedArray.value=[].concat(_toConsumableArray(state.eventBuffer.toBeProcessedArray.value),[[type,payload]]);return;}var invocationContext=this.getInvocationContext(preservedCustomContext);this.errorHandler.leaveBreadcrumb("New ".concat(type," event - ").concat(payload.name));state.metrics.triggered.value+=1;(_this$eventManager3=this.eventManager)===null||_this$eventManager3===void 0||_this$eventManager3.addEvent({type:type,name:payload.name||undefined,properties:payload.properties,options:payload.options,callback:payload.callback},invocationContext);}},{key:"identify",value:function identify(payload){var _this$userSessionMana3,_this$eventManager4;var isBufferedInvocation=arguments.length>1&&arguments[1]!==undefined?arguments[1]:false;var preservedCustomContext=arguments.length>2?arguments[2]:undefined;var type='identify';if(this.shouldBuffer(isBufferedInvocation)){state.eventBuffer.toBeProcessedArray.value=[].concat(_toConsumableArray(state.eventBuffer.toBeProcessedArray.value),[[type,payload]]);return;}var invocationContext=this.getInvocationContext(preservedCustomContext);this.errorHandler.leaveBreadcrumb("New ".concat(type," event"));state.metrics.triggered.value+=1;var shouldResetSession=Boolean(payload.userId&&state.session.userId.value&&payload.userId!==state.session.userId.value);if(shouldResetSession){// Part of this identify call, so it must not be deferred behind other buffered calls
|
|
4244
|
+
this.reset(undefined,true);}// `null` value indicates that previous user ID needs to be retained
|
|
4245
|
+
if(!isNull(payload.userId)){var _this$userSessionMana2;(_this$userSessionMana2=this.userSessionManager)===null||_this$userSessionMana2===void 0||_this$userSessionMana2.setUserId(payload.userId);}(_this$userSessionMana3=this.userSessionManager)===null||_this$userSessionMana3===void 0||_this$userSessionMana3.setUserTraits(payload.traits);(_this$eventManager4=this.eventManager)===null||_this$eventManager4===void 0||_this$eventManager4.addEvent({type:type,userId:payload.userId,traits:payload.traits,options:payload.options,callback:payload.callback},invocationContext);}},{key:"alias",value:function alias(payload){var _payload$from,_this$userSessionMana4,_this$eventManager5;var isBufferedInvocation=arguments.length>1&&arguments[1]!==undefined?arguments[1]:false;var preservedCustomContext=arguments.length>2?arguments[2]:undefined;var type='alias';if(this.shouldBuffer(isBufferedInvocation)){state.eventBuffer.toBeProcessedArray.value=[].concat(_toConsumableArray(state.eventBuffer.toBeProcessedArray.value),[[type,payload]]);return;}var invocationContext=this.getInvocationContext(preservedCustomContext);this.errorHandler.leaveBreadcrumb("New ".concat(type," event"));state.metrics.triggered.value+=1;var previousId=(_payload$from=payload.from)!==null&&_payload$from!==void 0?_payload$from:this.getUserId()||((_this$userSessionMana4=this.userSessionManager)===null||_this$userSessionMana4===void 0?void 0:_this$userSessionMana4.getAnonymousId());(_this$eventManager5=this.eventManager)===null||_this$eventManager5===void 0||_this$eventManager5.addEvent({type:type,to:payload.to,from:previousId,options:payload.options,callback:payload.callback},invocationContext);}},{key:"group",value:function group(payload){var _this$userSessionMana6,_this$eventManager6;var isBufferedInvocation=arguments.length>1&&arguments[1]!==undefined?arguments[1]:false;var preservedCustomContext=arguments.length>2?arguments[2]:undefined;var type='group';if(this.shouldBuffer(isBufferedInvocation)){state.eventBuffer.toBeProcessedArray.value=[].concat(_toConsumableArray(state.eventBuffer.toBeProcessedArray.value),[[type,payload]]);return;}var invocationContext=this.getInvocationContext(preservedCustomContext);this.errorHandler.leaveBreadcrumb("New ".concat(type," event"));state.metrics.triggered.value+=1;// `null` value indicates that previous group ID needs to be retained
|
|
4246
|
+
if(!isNull(payload.groupId)){var _this$userSessionMana5;(_this$userSessionMana5=this.userSessionManager)===null||_this$userSessionMana5===void 0||_this$userSessionMana5.setGroupId(payload.groupId);}(_this$userSessionMana6=this.userSessionManager)===null||_this$userSessionMana6===void 0||_this$userSessionMana6.setGroupTraits(payload.traits);(_this$eventManager6=this.eventManager)===null||_this$eventManager6===void 0||_this$eventManager6.addEvent({type:type,groupId:payload.groupId,traits:payload.traits,options:payload.options,callback:payload.callback},invocationContext);}},{key:"reset",value:function reset(options){var _this$userSessionMana7;var isBufferedInvocation=arguments.length>1&&arguments[1]!==undefined?arguments[1]:false;var type='reset';if(this.shouldBuffer(isBufferedInvocation)){state.eventBuffer.toBeProcessedArray.value=[].concat(_toConsumableArray(state.eventBuffer.toBeProcessedArray.value),[[type,options]]);return;}this.errorHandler.leaveBreadcrumb("New ".concat(type," invocation"));(_this$userSessionMana7=this.userSessionManager)===null||_this$userSessionMana7===void 0||_this$userSessionMana7.reset(options);}},{key:"getAnonymousId",value:function getAnonymousId(options){var _this$userSessionMana8;return (_this$userSessionMana8=this.userSessionManager)===null||_this$userSessionMana8===void 0?void 0:_this$userSessionMana8.getAnonymousId(options);}},{key:"setAnonymousId",value:function setAnonymousId(anonymousId,rudderAmpLinkerParam){var _this$userSessionMana9;var isBufferedInvocation=arguments.length>2&&arguments[2]!==undefined?arguments[2]:false;var type='setAnonymousId';// Buffering is needed as setting the anonymous ID may require invoking the GoogleLinker plugin
|
|
4247
|
+
if(this.shouldBuffer(isBufferedInvocation)){state.eventBuffer.toBeProcessedArray.value=[].concat(_toConsumableArray(state.eventBuffer.toBeProcessedArray.value),[[type,anonymousId,rudderAmpLinkerParam]]);return;}this.errorHandler.leaveBreadcrumb("New ".concat(type," invocation"));(_this$userSessionMana9=this.userSessionManager)===null||_this$userSessionMana9===void 0||_this$userSessionMana9.setAnonymousId(anonymousId,rudderAmpLinkerParam);}// eslint-disable-next-line class-methods-use-this
|
|
4240
4248
|
},{key:"getUserId",value:function getUserId(){return state.session.userId.value;}// eslint-disable-next-line class-methods-use-this
|
|
4241
4249
|
},{key:"getUserTraits",value:function getUserTraits(){return state.session.userTraits.value;}// eslint-disable-next-line class-methods-use-this
|
|
4242
4250
|
},{key:"getGroupId",value:function getGroupId(){return state.session.groupId.value;}// eslint-disable-next-line class-methods-use-this
|
|
4243
|
-
},{key:"getGroupTraits",value:function getGroupTraits(){return state.session.groupTraits.value;}},{key:"startSession",value:function startSession(sessionId){var _this$userSessionMana0;var type='startSession';if(
|
|
4244
|
-
},{key:"getSessionId",value:function getSessionId(){var _this$userSessionMana10;var sessionId=(_this$userSessionMana10=this.userSessionManager)===null||_this$userSessionMana10===void 0?void 0:_this$userSessionMana10.getSessionId();return sessionId!==null&&sessionId!==void 0?sessionId:null;}},{key:"consent",value:function consent(options){var _this4=this,_this$storeManager2,_this$userSessionMana11,_this$eventManager7;var isBufferedInvocation=arguments.length>1&&arguments[1]!==undefined?arguments[1]:false;var type='consent';if(
|
|
4251
|
+
},{key:"getGroupTraits",value:function getGroupTraits(){return state.session.groupTraits.value;}},{key:"startSession",value:function startSession(sessionId){var _this$userSessionMana0;var isBufferedInvocation=arguments.length>1&&arguments[1]!==undefined?arguments[1]:false;var type='startSession';if(this.shouldBuffer(isBufferedInvocation)){state.eventBuffer.toBeProcessedArray.value=[].concat(_toConsumableArray(state.eventBuffer.toBeProcessedArray.value),[[type,sessionId]]);return;}this.errorHandler.leaveBreadcrumb("New ".concat(type," invocation"));(_this$userSessionMana0=this.userSessionManager)===null||_this$userSessionMana0===void 0||_this$userSessionMana0.start(sessionId);}},{key:"endSession",value:function endSession(){var _this$userSessionMana1;var isBufferedInvocation=arguments.length>0&&arguments[0]!==undefined?arguments[0]:false;var type='endSession';if(this.shouldBuffer(isBufferedInvocation)){state.eventBuffer.toBeProcessedArray.value=[].concat(_toConsumableArray(state.eventBuffer.toBeProcessedArray.value),[[type]]);return;}this.errorHandler.leaveBreadcrumb("New ".concat(type," invocation"));(_this$userSessionMana1=this.userSessionManager)===null||_this$userSessionMana1===void 0||_this$userSessionMana1.end();}// eslint-disable-next-line class-methods-use-this
|
|
4252
|
+
},{key:"getSessionId",value:function getSessionId(){var _this$userSessionMana10;var sessionId=(_this$userSessionMana10=this.userSessionManager)===null||_this$userSessionMana10===void 0?void 0:_this$userSessionMana10.getSessionId();return sessionId!==null&&sessionId!==void 0?sessionId:null;}},{key:"consent",value:function consent(options){var _this4=this,_this$storeManager2,_this$userSessionMana11,_this$eventManager7;var isBufferedInvocation=arguments.length>1&&arguments[1]!==undefined?arguments[1]:false;var type='consent';if(this.shouldBuffer(isBufferedInvocation)){state.eventBuffer.toBeProcessedArray.value=[].concat(_toConsumableArray(state.eventBuffer.toBeProcessedArray.value),[[type,options]]);return;}this.errorHandler.leaveBreadcrumb("New consent invocation");n(function(){state.consents.preConsent.value=_objectSpread2(_objectSpread2({},state.consents.preConsent.value),{},{enabled:false});state.consents.postConsent.value=getValidPostConsentOptions(options,_this4.logger);var _getConsentManagement=getConsentManagementData(state.consents.postConsent.value.consentManagement,_this4.logger),initialized=_getConsentManagement.initialized,consentsData=_getConsentManagement.consentsData;state.consents.initialized.value=initialized;state.consents.data.value=consentsData;});// Update consents data in state
|
|
4245
4253
|
if(state.consents.enabled.value&&!state.consents.initialized.value){var _this$pluginsManager6;(_this$pluginsManager6=this.pluginsManager)===null||_this$pluginsManager6===void 0||_this$pluginsManager6.invokeSingle("consentManager.updateConsentsInfo",state,this.storeManager,this.logger);}// Re-init store manager
|
|
4246
4254
|
(_this$storeManager2=this.storeManager)===null||_this$storeManager2===void 0||_this$storeManager2.initializeStorageState();// Re-init user session manager
|
|
4247
4255
|
(_this$userSessionMana11=this.userSessionManager)===null||_this$userSessionMana11===void 0||_this$userSessionMana11.syncStorageDataToState();// Resume event manager to process the events to destinations
|
|
4248
|
-
(_this$eventManager7=this.eventManager)===null||_this$eventManager7===void 0||_this$eventManager7.resume()
|
|
4256
|
+
(_this$eventManager7=this.eventManager)===null||_this$eventManager7===void 0||_this$eventManager7.resume();// While replaying, defer to the 'loaded' lifecycle handler so that custom integrations
|
|
4257
|
+
// added later in the buffer are registered before destinations are loaded
|
|
4258
|
+
if(!this.isDrainingBuffer){this.loadDestinations();}this.sendTrackingEvents(isBufferedInvocation);}},{key:"sendTrackingEvents",value:function sendTrackingEvents(isBufferedInvocation){// If isBufferedInvocation is true, then the tracking events will be added to the end of the
|
|
4249
4259
|
// events buffer array so that any other preload events (mainly from query string API) will be processed first.
|
|
4250
4260
|
if(state.consents.postConsent.value.trackConsent){var trackOptions=trackArgumentsToCallOptions(CONSENT_TRACK_EVENT_NAME);if(isBufferedInvocation){state.eventBuffer.toBeProcessedArray.value=[].concat(_toConsumableArray(state.eventBuffer.toBeProcessedArray.value),[['track',trackOptions,this.customContextStore.get()]]);}else {this.track(trackOptions);}}if(state.consents.postConsent.value.sendPageEvent){var pageOptions=pageArgumentsToCallOptions();if(isBufferedInvocation){state.eventBuffer.toBeProcessedArray.value=[].concat(_toConsumableArray(state.eventBuffer.toBeProcessedArray.value),[['page',pageOptions,this.customContextStore.get()]]);}else {this.page(pageOptions);}}}},{key:"setAuthToken",value:function setAuthToken(token){var _this$userSessionMana12;(_this$userSessionMana12=this.userSessionManager)===null||_this$userSessionMana12===void 0||_this$userSessionMana12.setAuthToken(token);}/**
|
|
4251
4261
|
* Add a custom integration for a custom destination.
|
|
@@ -911,7 +911,7 @@ Object.getOwnPropertyNames(err).forEach(function(key){if(key!=='message'&&key!==
|
|
|
911
911
|
}}});return newError;}catch(_unused2){return new Error("".concat(issue,": ").concat(stringifyWithoutCircular(err)));}};var dispatchErrorEvent=function dispatchErrorEvent(error){if(isTypeOfError(error)){var errStack=getStacktrace(error);if(errStack){// eslint-disable-next-line no-param-reassign
|
|
912
912
|
error.stack="".concat(errStack,"\n").concat(MANUAL_ERROR_IDENTIFIER);}}globalThis.dispatchEvent(new ErrorEvent('error',{error:error,bubbles:true,cancelable:true,composed:true}));};
|
|
913
913
|
|
|
914
|
-
var APP_NAME='RudderLabs JavaScript SDK';var APP_VERSION='3.35.
|
|
914
|
+
var APP_NAME='RudderLabs JavaScript SDK';var APP_VERSION='3.35.1';var APP_NAMESPACE='com.rudderlabs.javascript';var MODULE_TYPE='npm';var BUILD_VARIANT='legacy';var ADBLOCK_PAGE_CATEGORY='RudderJS-Initiated';var ADBLOCK_PAGE_NAME='ad-block page request';var ADBLOCK_PAGE_PATH='/ad-blocked';var GLOBAL_PRELOAD_BUFFER='preloadedEventsBuffer';var CONSENT_TRACK_EVENT_NAME='Consent Management Interaction';
|
|
915
915
|
|
|
916
916
|
var QUERY_PARAM_TRAIT_PREFIX='ajs_trait_';var QUERY_PARAM_PROPERTY_PREFIX='ajs_prop_';var QUERY_PARAM_ANONYMOUS_ID_KEY='ajs_aid';var QUERY_PARAM_USER_ID_KEY='ajs_uid';var QUERY_PARAM_TRACK_EVENT_NAME_KEY='ajs_event';
|
|
917
917
|
|
|
@@ -1425,7 +1425,7 @@ var runningQueueIdsByName=new Map();var RetryQueue=/*#__PURE__*/function(){/**
|
|
|
1425
1425
|
* Constructs a RetryQueue backed by localStorage
|
|
1426
1426
|
*
|
|
1427
1427
|
* @param {String} name The name of the queue. Will be used to find abandoned queues and retry their items
|
|
1428
|
-
* @param {QueueOpts} [options] Optional argument to override `maxItems`, `maxAttempts`, `minRetryDelay
|
|
1428
|
+
* @param {QueueOpts} [options] Optional argument to override `maxItems`, `maxAttempts`, `minRetryDelay`, `maxRetryDelay`, `backoffFactor` and `backoffJitter`.
|
|
1429
1429
|
* @param {QueueProcessCallback} queueProcessCb The function to call in order to process an item added to the queue
|
|
1430
1430
|
* @param {IStoreManager} storeManager The store manager instance to use
|
|
1431
1431
|
* @param {StorageType} [storageType] The storage type to use. Defaults to LOCAL_STORAGE
|
|
@@ -4159,18 +4159,18 @@ var _excluded=["context"];/*
|
|
|
4159
4159
|
* Analytics class with lifecycle based on state ad user triggered events
|
|
4160
4160
|
*/var Analytics=/*#__PURE__*/function(){/**
|
|
4161
4161
|
* Initialize services and components or use default ones if singletons
|
|
4162
|
-
*/function Analytics(){_classCallCheck(this,Analytics);this.preloadBuffer=new BufferQueue();this.initialized=false;this.errorHandler=defaultErrorHandler;this.logger=defaultLogger;this.customContextStore=new CustomContextStore(state.customContext,this.logger);this.externalSrcLoader=new ExternalSrcLoader(this.logger);this.httpClient=defaultHttpClient;this.httpClient.init(this.errorHandler);this.capabilitiesManager=new CapabilitiesManager(this.httpClient,this.errorHandler,this.logger);}/**
|
|
4162
|
+
*/function Analytics(){_classCallCheck(this,Analytics);this.preloadBuffer=new BufferQueue();this.initialized=false;this.isDrainingBuffer=false;this.errorHandler=defaultErrorHandler;this.logger=defaultLogger;this.customContextStore=new CustomContextStore(state.customContext,this.logger);this.externalSrcLoader=new ExternalSrcLoader(this.logger);this.httpClient=defaultHttpClient;this.httpClient.init(this.errorHandler);this.capabilitiesManager=new CapabilitiesManager(this.httpClient,this.errorHandler,this.logger);}/**
|
|
4163
4163
|
* Start application lifecycle if not already started
|
|
4164
4164
|
*/return _createClass(Analytics,[{key:"load",value:function load(writeKey,dataPlaneUrl){var _state$loadOptions$va;var loadOptions=arguments.length>2&&arguments[2]!==undefined?arguments[2]:{};if(state.lifecycle.status.value){return;}if(!isWriteKeyValid(writeKey)){this.logger.error(WRITE_KEY_VALIDATION_ERROR(ANALYTICS_CORE,writeKey));return;}if(!isDataPlaneUrlValid(dataPlaneUrl)){this.logger.error(DATA_PLANE_URL_VALIDATION_ERROR(ANALYTICS_CORE,dataPlaneUrl));return;}var customContext=loadOptions.context,loadOptionsWithoutContext=_objectWithoutProperties(loadOptions,_excluded);var sanitizedLoadOptions=getSanitizedValue(loadOptionsWithoutContext);if(customContext!==undefined){this.customContextStore.set(customContext);}// Set initial state values
|
|
4165
4165
|
n(function(){state.lifecycle.writeKey.value=clone(writeKey);state.lifecycle.dataPlaneUrl.value=clone(dataPlaneUrl);state.loadOptions.value=normalizeLoadOptions(state.loadOptions.value,sanitizedLoadOptions);state.lifecycle.status.value='mounted';});// set log level as early as possible
|
|
4166
4166
|
this.logger.setMinLogLevel((_state$loadOptions$va=state.loadOptions.value.logLevel)!==null&&_state$loadOptions$va!==void 0?_state$loadOptions$va:POST_LOAD_LOG_LEVEL);// Expose state to global objects
|
|
4167
4167
|
setExposedGlobal('state',state,writeKey);// Configure initial config of any services or components here
|
|
4168
4168
|
// State application lifecycle
|
|
4169
|
-
this.startLifecycle();}},{key:"setCustomContext",value:function setCustomContext(context){if(
|
|
4169
|
+
this.startLifecycle();}},{key:"setCustomContext",value:function setCustomContext(context){var isBufferedInvocation=arguments.length>1&&arguments[1]!==undefined?arguments[1]:false;if(this.shouldBuffer(isBufferedInvocation)){state.eventBuffer.toBeProcessedArray.value=[].concat(_toConsumableArray(state.eventBuffer.toBeProcessedArray.value),[['setCustomContext',context]]);return;}this.customContextStore.set(context);}},{key:"getCustomContext",value:function getCustomContext(){return this.customContextStore.get();}},{key:"clearCustomContext",value:function clearCustomContext(){var isBufferedInvocation=arguments.length>0&&arguments[0]!==undefined?arguments[0]:false;if(this.shouldBuffer(isBufferedInvocation)){state.eventBuffer.toBeProcessedArray.value=[].concat(_toConsumableArray(state.eventBuffer.toBeProcessedArray.value),[['clearCustomContext']]);return;}this.customContextStore.clear();}// Start lifecycle methods
|
|
4170
4170
|
/**
|
|
4171
4171
|
* Orchestrate the lifecycle of the application phases/status
|
|
4172
|
-
*/},{key:"startLifecycle",value:function startLifecycle(){var _this=this;j(function(){try{switch(state.lifecycle.status.value){case 'mounted':_this.onMounted();break;case 'browserCapabilitiesReady':_this.onBrowserCapabilitiesReady();break;case 'configured':_this.onConfigured();break;case 'pluginsLoading':break;case 'pluginsReady':_this.onPluginsReady();break;case 'initialized':_this.onInitialized();break;case 'loaded':_this.onLoaded();break;case 'destinationsLoading':break;case 'destinationsReady':_this.onDestinationsReady();break;case 'ready':_this.onReady();break;case 'readyExecuted':default:break;}}catch(err){var issue='Failed to load the SDK';_this.errorHandler.onError({error:err,context:ANALYTICS_CORE,customMessage:issue,groupingHash:issue});}});}},{key:"onBrowserCapabilitiesReady",value:function onBrowserCapabilitiesReady(){// initialize the preloaded events enqueuing
|
|
4173
|
-
retrievePreloadBufferEvents(this);this.prepareInternalServices();this.loadConfig();}},{key:"onLoaded",value:function onLoaded(){
|
|
4172
|
+
*/},{key:"startLifecycle",value:function startLifecycle(){var _this=this;j(function(){try{switch(state.lifecycle.status.value){case 'mounted':_this.onMounted();break;case 'browserCapabilitiesReady':_this.onBrowserCapabilitiesReady();break;case 'configured':_this.onConfigured();break;case 'pluginsLoading':break;case 'pluginsReady':_this.onPluginsReady();break;case 'initialized':_this.onInitialized();break;case 'loaded':_this.onLoaded();break;case 'destinationsLoading':break;case 'destinationsReady':_this.onDestinationsReady();break;case 'ready':_this.onReady();break;case 'readyExecuted':default:break;}}catch(err){var issue='Failed to load the SDK';void _this.errorHandler.onError({error:err,context:ANALYTICS_CORE,customMessage:issue,groupingHash:issue});}});}},{key:"onBrowserCapabilitiesReady",value:function onBrowserCapabilitiesReady(){// initialize the preloaded events enqueuing
|
|
4173
|
+
retrievePreloadBufferEvents(this);this.prepareInternalServices();this.loadConfig();}},{key:"onLoaded",value:function onLoaded(){// Short-circuit the life cycle and move to the ready state if pre-consent behavior is enabled
|
|
4174
4174
|
if(state.consents.preConsent.value.enabled===true){state.lifecycle.status.value='ready';}else {this.loadDestinations();}}/**
|
|
4175
4175
|
* Load browser polyfill if required
|
|
4176
4176
|
*/},{key:"onMounted",value:function onMounted(){this.capabilitiesManager.init();}/**
|
|
@@ -4191,9 +4191,12 @@ state.lifecycle.status.value='initialized';}/**
|
|
|
4191
4191
|
// registerCustomPlugins(state.loadOptions.value.customPlugins);
|
|
4192
4192
|
}/**
|
|
4193
4193
|
* Trigger onLoaded callback if any is provided in config & emit initialised event
|
|
4194
|
-
*/},{key:"onInitialized",value:function onInitialized(){//
|
|
4195
|
-
|
|
4196
|
-
|
|
4194
|
+
*/},{key:"onInitialized",value:function onInitialized(){// Preloaded calls were made before the ones buffered while initializing, so queue them first.
|
|
4195
|
+
// Exception: they stay behind any consent call made while initializing, so that consent still
|
|
4196
|
+
// applies to them as it always has (see SDK-5623)
|
|
4197
|
+
var callsDuringInitialization=state.eventBuffer.toBeProcessedArray.value;state.eventBuffer.toBeProcessedArray.value=[];this.processDataInPreloadBuffer();var lastConsentIndex=callsDuringInitialization.map(function(_ref){var _ref2=_slicedToArray(_ref,1),type=_ref2[0];return type;}).lastIndexOf('consent');state.eventBuffer.toBeProcessedArray.value=[].concat(_toConsumableArray(callsDuringInitialization.slice(0,lastConsentIndex+1)),_toConsumableArray(state.eventBuffer.toBeProcessedArray.value),_toConsumableArray(callsDuringInitialization.slice(lastConsentIndex+1)));// Set lifecycle state
|
|
4198
|
+
n(function(){state.lifecycle.loaded.value=true;state.lifecycle.status.value='loaded';});this.initialized=true;// Calls made while draining (e.g., from event callbacks) are queued behind the buffered ones
|
|
4199
|
+
this.isDrainingBuffer=true;try{this.processBufferedEvents();}finally{this.isDrainingBuffer=false;}// Execute onLoaded callback if provided in load options
|
|
4197
4200
|
var onLoadedCallbackFn=state.loadOptions.value.onLoaded;// TODO: we need to avoid passing the window object to the callback function
|
|
4198
4201
|
// as this will prevent us from supporting multiple SDK instances in the same page
|
|
4199
4202
|
safelyInvokeCallback(onLoadedCallbackFn,[globalThis.rudderanalytics],LOAD_API,this.logger);// Emit an event to use as substitute to the onLoaded callback
|
|
@@ -4206,7 +4209,11 @@ dispatchSDKEvent('RSA_Ready');}/**
|
|
|
4206
4209
|
*/},{key:"processBufferedEvents",value:function processBufferedEvents(){// This logic has been intentionally implemented without a simple
|
|
4207
4210
|
// for-loop as the individual events that are processed may
|
|
4208
4211
|
// add more events to the buffer (this is needed for the consent API)
|
|
4209
|
-
var bufferedEvents=state.eventBuffer.toBeProcessedArray.value;while(bufferedEvents.length>0){var bufferedEvent=bufferedEvents.shift();state.eventBuffer.toBeProcessedArray.value=bufferedEvents;if(bufferedEvent){
|
|
4212
|
+
var bufferedEvents=state.eventBuffer.toBeProcessedArray.value;while(bufferedEvents.length>0){var bufferedEvent=bufferedEvents.shift();state.eventBuffer.toBeProcessedArray.value=bufferedEvents;if(bufferedEvent){// A failing call must not stop the rest of the buffer or the load notifications
|
|
4213
|
+
try{this.processBufferedEvent(bufferedEvent);}catch(err){var issue='Failed to process a buffered API call';void this.errorHandler.onError({error:err,context:ANALYTICS_CORE,customMessage:issue,groupingHash:issue});}}bufferedEvents=state.eventBuffer.toBeProcessedArray.value;}}},{key:"processBufferedEvent",value:function processBufferedEvent(bufferedEvent){switch(bufferedEvent[0]){case 'setCustomContext':this.setCustomContext(bufferedEvent[1],true);break;case 'clearCustomContext':this.clearCustomContext(true);break;case 'ready':this.ready(bufferedEvent[1],true);break;case 'page':this.page(bufferedEvent[1],true,bufferedEvent[2]);break;case 'track':this.track(bufferedEvent[1],true,bufferedEvent[2]);break;case 'identify':this.identify(bufferedEvent[1],true,bufferedEvent[2]);break;case 'alias':this.alias(bufferedEvent[1],true,bufferedEvent[2]);break;case 'group':this.group(bufferedEvent[1],true,bufferedEvent[2]);break;case 'reset':this.reset(bufferedEvent[1],true);break;case 'setAnonymousId':this.setAnonymousId(bufferedEvent[1],bufferedEvent[2],true);break;case 'startSession':this.startSession(bufferedEvent[1],true);break;case 'endSession':this.endSession(true);break;case 'consent':this.consent(bufferedEvent[1],true);break;case 'addCustomIntegration':this.addCustomIntegration(bufferedEvent[1],bufferedEvent[2],true);break;default:{var unsupportedEvent=bufferedEvent;return unsupportedEvent;}}}/**
|
|
4214
|
+
* Whether an API call must be queued instead of executed now: either the SDK is not loaded yet,
|
|
4215
|
+
* or the buffer is being drained and this call was not replayed from it
|
|
4216
|
+
*/},{key:"shouldBuffer",value:function shouldBuffer(isBufferedInvocation){return !state.lifecycle.loaded.value||this.isDrainingBuffer&&!isBufferedInvocation;}},{key:"getInvocationContext",value:function getInvocationContext(preservedCustomContext){var _ref3;if(preservedCustomContext===undefined){return this.customContextStore.get();}var preparedContext=prepareCustomContextUpdate(preservedCustomContext,this.logger);return (_ref3=preparedContext)!==null&&_ref3!==void 0?_ref3:{};}/**
|
|
4210
4217
|
* Load device mode destinations
|
|
4211
4218
|
*/},{key:"loadDestinations",value:function loadDestinations(){var _this$pluginsManager4,_this$pluginsManager5;// If the integrations load is already triggered or completed, skip the rest of the logic
|
|
4212
4219
|
if(state.lifecycle.status.value==='destinationsLoading'||state.nativeDestinations.clientDestinationsReady.value===true){return;}// Set in state the desired activeDestinations to inject in DOM
|
|
@@ -4219,28 +4226,31 @@ j(function(){var areAllDestinationsReady=state.nativeDestinations.initializedDes
|
|
|
4219
4226
|
// Mark the ready status if not already done
|
|
4220
4227
|
if(state.lifecycle.status.value!=='ready'){n(function(){state.lifecycle.status.value='ready';});}}// End lifecycle methods
|
|
4221
4228
|
// Start consumer exposed methods
|
|
4222
|
-
},{key:"ready",value:function ready(callback){var type='ready';if(
|
|
4229
|
+
},{key:"ready",value:function ready(callback){var isBufferedInvocation=arguments.length>1&&arguments[1]!==undefined?arguments[1]:false;var type='ready';if(this.shouldBuffer(isBufferedInvocation)){state.eventBuffer.toBeProcessedArray.value=[].concat(_toConsumableArray(state.eventBuffer.toBeProcessedArray.value),[[type,callback]]);return;}this.errorHandler.leaveBreadcrumb("New ".concat(type," invocation"));if(!isFunction(callback)){this.logger.error(INVALID_CALLBACK_FN_ERROR(READY_API));return;}/**
|
|
4223
4230
|
* If destinations are loaded or no integration is available for loading
|
|
4224
4231
|
* execute the callback immediately else push the callbacks to a queue that
|
|
4225
4232
|
* will be executed after loading completes
|
|
4226
|
-
*/if(state.lifecycle.status.value==='readyExecuted'){safelyInvokeCallback(callback,[],READY_API,this.logger);}else {state.eventBuffer.readyCallbacksArray.value=[].concat(_toConsumableArray(state.eventBuffer.readyCallbacksArray.value),[callback]);}}},{key:"page",value:function page(payload){var _this$eventManager2;var isBufferedInvocation=arguments.length>1&&arguments[1]!==undefined?arguments[1]:false;var preservedCustomContext=arguments.length>2?arguments[2]:undefined;var type='page';if(
|
|
4233
|
+
*/if(state.lifecycle.status.value==='readyExecuted'){safelyInvokeCallback(callback,[],READY_API,this.logger);}else {state.eventBuffer.readyCallbacksArray.value=[].concat(_toConsumableArray(state.eventBuffer.readyCallbacksArray.value),[callback]);}}},{key:"page",value:function page(payload){var _this$eventManager2;var isBufferedInvocation=arguments.length>1&&arguments[1]!==undefined?arguments[1]:false;var preservedCustomContext=arguments.length>2?arguments[2]:undefined;var type='page';if(this.shouldBuffer(isBufferedInvocation)){state.eventBuffer.toBeProcessedArray.value=[].concat(_toConsumableArray(state.eventBuffer.toBeProcessedArray.value),[[type,payload]]);return;}var invocationContext=this.getInvocationContext(preservedCustomContext);this.errorHandler.leaveBreadcrumb("New ".concat(type," event"));state.metrics.triggered.value+=1;(_this$eventManager2=this.eventManager)===null||_this$eventManager2===void 0||_this$eventManager2.addEvent({type:'page',category:payload.category,name:payload.name,properties:payload.properties,options:payload.options,callback:payload.callback},invocationContext);// TODO: Maybe we should alter the behavior to send the ad-block page event even if the SDK is still loaded. It'll be pushed into the to be processed queue.
|
|
4227
4234
|
// Send automatic ad blocked page event if ad-blockers are detected on the page
|
|
4228
4235
|
// Check page category to avoid infinite loop
|
|
4229
4236
|
if(state.capabilities.isAdBlocked.value===true&&payload.category!==ADBLOCK_PAGE_CATEGORY){this.page(pageArgumentsToCallOptions(ADBLOCK_PAGE_CATEGORY,ADBLOCK_PAGE_NAME,{// 'title' is intentionally omitted as it does not make sense
|
|
4230
4237
|
// in v3 implementation
|
|
4231
|
-
path:ADBLOCK_PAGE_PATH},state.loadOptions.value.sendAdblockPageOptions),isBufferedInvocation,invocationContext);}}},{key:"track",value:function track(payload){var _this$eventManager3;var preservedCustomContext=arguments.length>2?arguments[2]:undefined;var type='track';if(
|
|
4232
|
-
|
|
4233
|
-
if(!isNull(payload.
|
|
4234
|
-
if(!
|
|
4238
|
+
path:ADBLOCK_PAGE_PATH},state.loadOptions.value.sendAdblockPageOptions),isBufferedInvocation,invocationContext);}}},{key:"track",value:function track(payload){var _this$eventManager3;var isBufferedInvocation=arguments.length>1&&arguments[1]!==undefined?arguments[1]:false;var preservedCustomContext=arguments.length>2?arguments[2]:undefined;var type='track';if(this.shouldBuffer(isBufferedInvocation)){state.eventBuffer.toBeProcessedArray.value=[].concat(_toConsumableArray(state.eventBuffer.toBeProcessedArray.value),[[type,payload]]);return;}var invocationContext=this.getInvocationContext(preservedCustomContext);this.errorHandler.leaveBreadcrumb("New ".concat(type," event - ").concat(payload.name));state.metrics.triggered.value+=1;(_this$eventManager3=this.eventManager)===null||_this$eventManager3===void 0||_this$eventManager3.addEvent({type:type,name:payload.name||undefined,properties:payload.properties,options:payload.options,callback:payload.callback},invocationContext);}},{key:"identify",value:function identify(payload){var _this$userSessionMana3,_this$eventManager4;var isBufferedInvocation=arguments.length>1&&arguments[1]!==undefined?arguments[1]:false;var preservedCustomContext=arguments.length>2?arguments[2]:undefined;var type='identify';if(this.shouldBuffer(isBufferedInvocation)){state.eventBuffer.toBeProcessedArray.value=[].concat(_toConsumableArray(state.eventBuffer.toBeProcessedArray.value),[[type,payload]]);return;}var invocationContext=this.getInvocationContext(preservedCustomContext);this.errorHandler.leaveBreadcrumb("New ".concat(type," event"));state.metrics.triggered.value+=1;var shouldResetSession=Boolean(payload.userId&&state.session.userId.value&&payload.userId!==state.session.userId.value);if(shouldResetSession){// Part of this identify call, so it must not be deferred behind other buffered calls
|
|
4239
|
+
this.reset(undefined,true);}// `null` value indicates that previous user ID needs to be retained
|
|
4240
|
+
if(!isNull(payload.userId)){var _this$userSessionMana2;(_this$userSessionMana2=this.userSessionManager)===null||_this$userSessionMana2===void 0||_this$userSessionMana2.setUserId(payload.userId);}(_this$userSessionMana3=this.userSessionManager)===null||_this$userSessionMana3===void 0||_this$userSessionMana3.setUserTraits(payload.traits);(_this$eventManager4=this.eventManager)===null||_this$eventManager4===void 0||_this$eventManager4.addEvent({type:type,userId:payload.userId,traits:payload.traits,options:payload.options,callback:payload.callback},invocationContext);}},{key:"alias",value:function alias(payload){var _payload$from,_this$userSessionMana4,_this$eventManager5;var isBufferedInvocation=arguments.length>1&&arguments[1]!==undefined?arguments[1]:false;var preservedCustomContext=arguments.length>2?arguments[2]:undefined;var type='alias';if(this.shouldBuffer(isBufferedInvocation)){state.eventBuffer.toBeProcessedArray.value=[].concat(_toConsumableArray(state.eventBuffer.toBeProcessedArray.value),[[type,payload]]);return;}var invocationContext=this.getInvocationContext(preservedCustomContext);this.errorHandler.leaveBreadcrumb("New ".concat(type," event"));state.metrics.triggered.value+=1;var previousId=(_payload$from=payload.from)!==null&&_payload$from!==void 0?_payload$from:this.getUserId()||((_this$userSessionMana4=this.userSessionManager)===null||_this$userSessionMana4===void 0?void 0:_this$userSessionMana4.getAnonymousId());(_this$eventManager5=this.eventManager)===null||_this$eventManager5===void 0||_this$eventManager5.addEvent({type:type,to:payload.to,from:previousId,options:payload.options,callback:payload.callback},invocationContext);}},{key:"group",value:function group(payload){var _this$userSessionMana6,_this$eventManager6;var isBufferedInvocation=arguments.length>1&&arguments[1]!==undefined?arguments[1]:false;var preservedCustomContext=arguments.length>2?arguments[2]:undefined;var type='group';if(this.shouldBuffer(isBufferedInvocation)){state.eventBuffer.toBeProcessedArray.value=[].concat(_toConsumableArray(state.eventBuffer.toBeProcessedArray.value),[[type,payload]]);return;}var invocationContext=this.getInvocationContext(preservedCustomContext);this.errorHandler.leaveBreadcrumb("New ".concat(type," event"));state.metrics.triggered.value+=1;// `null` value indicates that previous group ID needs to be retained
|
|
4241
|
+
if(!isNull(payload.groupId)){var _this$userSessionMana5;(_this$userSessionMana5=this.userSessionManager)===null||_this$userSessionMana5===void 0||_this$userSessionMana5.setGroupId(payload.groupId);}(_this$userSessionMana6=this.userSessionManager)===null||_this$userSessionMana6===void 0||_this$userSessionMana6.setGroupTraits(payload.traits);(_this$eventManager6=this.eventManager)===null||_this$eventManager6===void 0||_this$eventManager6.addEvent({type:type,groupId:payload.groupId,traits:payload.traits,options:payload.options,callback:payload.callback},invocationContext);}},{key:"reset",value:function reset(options){var _this$userSessionMana7;var isBufferedInvocation=arguments.length>1&&arguments[1]!==undefined?arguments[1]:false;var type='reset';if(this.shouldBuffer(isBufferedInvocation)){state.eventBuffer.toBeProcessedArray.value=[].concat(_toConsumableArray(state.eventBuffer.toBeProcessedArray.value),[[type,options]]);return;}this.errorHandler.leaveBreadcrumb("New ".concat(type," invocation"));(_this$userSessionMana7=this.userSessionManager)===null||_this$userSessionMana7===void 0||_this$userSessionMana7.reset(options);}},{key:"getAnonymousId",value:function getAnonymousId(options){var _this$userSessionMana8;return (_this$userSessionMana8=this.userSessionManager)===null||_this$userSessionMana8===void 0?void 0:_this$userSessionMana8.getAnonymousId(options);}},{key:"setAnonymousId",value:function setAnonymousId(anonymousId,rudderAmpLinkerParam){var _this$userSessionMana9;var isBufferedInvocation=arguments.length>2&&arguments[2]!==undefined?arguments[2]:false;var type='setAnonymousId';// Buffering is needed as setting the anonymous ID may require invoking the GoogleLinker plugin
|
|
4242
|
+
if(this.shouldBuffer(isBufferedInvocation)){state.eventBuffer.toBeProcessedArray.value=[].concat(_toConsumableArray(state.eventBuffer.toBeProcessedArray.value),[[type,anonymousId,rudderAmpLinkerParam]]);return;}this.errorHandler.leaveBreadcrumb("New ".concat(type," invocation"));(_this$userSessionMana9=this.userSessionManager)===null||_this$userSessionMana9===void 0||_this$userSessionMana9.setAnonymousId(anonymousId,rudderAmpLinkerParam);}// eslint-disable-next-line class-methods-use-this
|
|
4235
4243
|
},{key:"getUserId",value:function getUserId(){return state.session.userId.value;}// eslint-disable-next-line class-methods-use-this
|
|
4236
4244
|
},{key:"getUserTraits",value:function getUserTraits(){return state.session.userTraits.value;}// eslint-disable-next-line class-methods-use-this
|
|
4237
4245
|
},{key:"getGroupId",value:function getGroupId(){return state.session.groupId.value;}// eslint-disable-next-line class-methods-use-this
|
|
4238
|
-
},{key:"getGroupTraits",value:function getGroupTraits(){return state.session.groupTraits.value;}},{key:"startSession",value:function startSession(sessionId){var _this$userSessionMana0;var type='startSession';if(
|
|
4239
|
-
},{key:"getSessionId",value:function getSessionId(){var _this$userSessionMana10;var sessionId=(_this$userSessionMana10=this.userSessionManager)===null||_this$userSessionMana10===void 0?void 0:_this$userSessionMana10.getSessionId();return sessionId!==null&&sessionId!==void 0?sessionId:null;}},{key:"consent",value:function consent(options){var _this4=this,_this$storeManager2,_this$userSessionMana11,_this$eventManager7;var isBufferedInvocation=arguments.length>1&&arguments[1]!==undefined?arguments[1]:false;var type='consent';if(
|
|
4246
|
+
},{key:"getGroupTraits",value:function getGroupTraits(){return state.session.groupTraits.value;}},{key:"startSession",value:function startSession(sessionId){var _this$userSessionMana0;var isBufferedInvocation=arguments.length>1&&arguments[1]!==undefined?arguments[1]:false;var type='startSession';if(this.shouldBuffer(isBufferedInvocation)){state.eventBuffer.toBeProcessedArray.value=[].concat(_toConsumableArray(state.eventBuffer.toBeProcessedArray.value),[[type,sessionId]]);return;}this.errorHandler.leaveBreadcrumb("New ".concat(type," invocation"));(_this$userSessionMana0=this.userSessionManager)===null||_this$userSessionMana0===void 0||_this$userSessionMana0.start(sessionId);}},{key:"endSession",value:function endSession(){var _this$userSessionMana1;var isBufferedInvocation=arguments.length>0&&arguments[0]!==undefined?arguments[0]:false;var type='endSession';if(this.shouldBuffer(isBufferedInvocation)){state.eventBuffer.toBeProcessedArray.value=[].concat(_toConsumableArray(state.eventBuffer.toBeProcessedArray.value),[[type]]);return;}this.errorHandler.leaveBreadcrumb("New ".concat(type," invocation"));(_this$userSessionMana1=this.userSessionManager)===null||_this$userSessionMana1===void 0||_this$userSessionMana1.end();}// eslint-disable-next-line class-methods-use-this
|
|
4247
|
+
},{key:"getSessionId",value:function getSessionId(){var _this$userSessionMana10;var sessionId=(_this$userSessionMana10=this.userSessionManager)===null||_this$userSessionMana10===void 0?void 0:_this$userSessionMana10.getSessionId();return sessionId!==null&&sessionId!==void 0?sessionId:null;}},{key:"consent",value:function consent(options){var _this4=this,_this$storeManager2,_this$userSessionMana11,_this$eventManager7;var isBufferedInvocation=arguments.length>1&&arguments[1]!==undefined?arguments[1]:false;var type='consent';if(this.shouldBuffer(isBufferedInvocation)){state.eventBuffer.toBeProcessedArray.value=[].concat(_toConsumableArray(state.eventBuffer.toBeProcessedArray.value),[[type,options]]);return;}this.errorHandler.leaveBreadcrumb("New consent invocation");n(function(){state.consents.preConsent.value=_objectSpread2(_objectSpread2({},state.consents.preConsent.value),{},{enabled:false});state.consents.postConsent.value=getValidPostConsentOptions(options,_this4.logger);var _getConsentManagement=getConsentManagementData(state.consents.postConsent.value.consentManagement,_this4.logger),initialized=_getConsentManagement.initialized,consentsData=_getConsentManagement.consentsData;state.consents.initialized.value=initialized;state.consents.data.value=consentsData;});// Update consents data in state
|
|
4240
4248
|
if(state.consents.enabled.value&&!state.consents.initialized.value){var _this$pluginsManager6;(_this$pluginsManager6=this.pluginsManager)===null||_this$pluginsManager6===void 0||_this$pluginsManager6.invokeSingle("consentManager.updateConsentsInfo",state,this.storeManager,this.logger);}// Re-init store manager
|
|
4241
4249
|
(_this$storeManager2=this.storeManager)===null||_this$storeManager2===void 0||_this$storeManager2.initializeStorageState();// Re-init user session manager
|
|
4242
4250
|
(_this$userSessionMana11=this.userSessionManager)===null||_this$userSessionMana11===void 0||_this$userSessionMana11.syncStorageDataToState();// Resume event manager to process the events to destinations
|
|
4243
|
-
(_this$eventManager7=this.eventManager)===null||_this$eventManager7===void 0||_this$eventManager7.resume()
|
|
4251
|
+
(_this$eventManager7=this.eventManager)===null||_this$eventManager7===void 0||_this$eventManager7.resume();// While replaying, defer to the 'loaded' lifecycle handler so that custom integrations
|
|
4252
|
+
// added later in the buffer are registered before destinations are loaded
|
|
4253
|
+
if(!this.isDrainingBuffer){this.loadDestinations();}this.sendTrackingEvents(isBufferedInvocation);}},{key:"sendTrackingEvents",value:function sendTrackingEvents(isBufferedInvocation){// If isBufferedInvocation is true, then the tracking events will be added to the end of the
|
|
4244
4254
|
// events buffer array so that any other preload events (mainly from query string API) will be processed first.
|
|
4245
4255
|
if(state.consents.postConsent.value.trackConsent){var trackOptions=trackArgumentsToCallOptions(CONSENT_TRACK_EVENT_NAME);if(isBufferedInvocation){state.eventBuffer.toBeProcessedArray.value=[].concat(_toConsumableArray(state.eventBuffer.toBeProcessedArray.value),[['track',trackOptions,this.customContextStore.get()]]);}else {this.track(trackOptions);}}if(state.consents.postConsent.value.sendPageEvent){var pageOptions=pageArgumentsToCallOptions();if(isBufferedInvocation){state.eventBuffer.toBeProcessedArray.value=[].concat(_toConsumableArray(state.eventBuffer.toBeProcessedArray.value),[['page',pageOptions,this.customContextStore.get()]]);}else {this.page(pageOptions);}}}},{key:"setAuthToken",value:function setAuthToken(token){var _this$userSessionMana12;(_this$userSessionMana12=this.userSessionManager)===null||_this$userSessionMana12===void 0||_this$userSessionMana12.setAuthToken(token);}/**
|
|
4246
4256
|
* Add a custom integration for a custom destination.
|