@mparticle/web-sdk 2.58.0 → 2.59.0

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/dist/mparticle.js CHANGED
@@ -203,7 +203,7 @@ var mParticle = (function () {
203
203
  Base64: Base64$1
204
204
  };
205
205
 
206
- var version = "2.58.0";
206
+ var version = "2.59.0";
207
207
 
208
208
  var Constants = {
209
209
  sdkVersion: version,
@@ -2212,6 +2212,26 @@ var mParticle = (function () {
2212
2212
  }
2213
2213
  return SessionStorageVault;
2214
2214
  }(BaseVault);
2215
+ // DisabledVault is used when persistence is disabled by privacy flags.
2216
+ var DisabledVault = /** @class */function (_super) {
2217
+ __extends(DisabledVault, _super);
2218
+ function DisabledVault(storageKey, options) {
2219
+ var _this = _super.call(this, storageKey, window.localStorage, options) || this;
2220
+ _this.contents = null;
2221
+ _this.storageObject.removeItem(_this._storageKey);
2222
+ return _this;
2223
+ }
2224
+ DisabledVault.prototype.store = function (_item) {
2225
+ this.contents = null;
2226
+ };
2227
+ DisabledVault.prototype.retrieve = function () {
2228
+ return this.contents;
2229
+ };
2230
+ DisabledVault.prototype.purge = function () {
2231
+ this.contents = null;
2232
+ };
2233
+ return DisabledVault;
2234
+ }(BaseVault);
2215
2235
 
2216
2236
  var AsyncUploader = /** @class */function () {
2217
2237
  function AsyncUploader(url) {
@@ -2374,6 +2394,7 @@ var mParticle = (function () {
2374
2394
  */
2375
2395
  function BatchUploader(mpInstance, uploadInterval) {
2376
2396
  var _a;
2397
+ var _b;
2377
2398
  this.offlineStorageEnabled = false;
2378
2399
  this.lastASTEventTime = 0;
2379
2400
  this.AST_DEBOUNCE_MS = 1000; // 1 second debounce
@@ -2392,7 +2413,9 @@ var mParticle = (function () {
2392
2413
  // Cache Offline Storage Availability boolean
2393
2414
  // so that we don't have to check it every time
2394
2415
  this.offlineStorageEnabled = this.isOfflineStorageAvailable();
2395
- if (this.offlineStorageEnabled) {
2416
+ // When noFunctional is true, prevent events/batches storage
2417
+ var noFunctional = (_b = mpInstance._CookieConsentManager) === null || _b === void 0 ? void 0 : _b.getNoFunctional();
2418
+ if (this.offlineStorageEnabled && !noFunctional) {
2396
2419
  this.eventVault = new SessionStorageVault("".concat(mpInstance._Store.storageName, "-events"), {
2397
2420
  logger: mpInstance.Logger
2398
2421
  });
@@ -2402,9 +2425,9 @@ var mParticle = (function () {
2402
2425
  // Load Events from Session Storage in case we have any in storage
2403
2426
  (_a = this.eventsQueuedForProcessing).push.apply(_a, this.eventVault.retrieve());
2404
2427
  }
2405
- var _b = this.mpInstance._Store,
2406
- SDKConfig = _b.SDKConfig,
2407
- devToken = _b.devToken;
2428
+ var _c = this.mpInstance._Store,
2429
+ SDKConfig = _c.SDKConfig,
2430
+ devToken = _c.devToken;
2408
2431
  var baseUrl = this.mpInstance._Helpers.createServiceUrl(SDKConfig.v3SecureServiceUrl, devToken);
2409
2432
  this.uploadUrl = "".concat(baseUrl, "/events");
2410
2433
  this.uploader = window.fetch ? new FetchUploader(this.uploadUrl) : new XHRUploader(this.uploadUrl);
@@ -2767,6 +2790,181 @@ var mParticle = (function () {
2767
2790
  return BatchUploader;
2768
2791
  }();
2769
2792
 
2793
+ var _a = Constants.IdentityMethods,
2794
+ Identify$2 = _a.Identify,
2795
+ Modify$4 = _a.Modify,
2796
+ Login$2 = _a.Login,
2797
+ Logout$2 = _a.Logout;
2798
+ var CACHE_HEADER = 'x-mp-max-age';
2799
+ var cacheOrClearIdCache = function cacheOrClearIdCache(method, knownIdentities, idCache, identityResponse, parsingCachedResponse) {
2800
+ // when parsing a response that has already been cached, simply return instead of attempting another cache
2801
+ if (parsingCachedResponse) {
2802
+ return;
2803
+ }
2804
+ // default the expire timestamp to one day in milliseconds unless a header comes back
2805
+ var expireTimestamp = getExpireTimestamp(identityResponse === null || identityResponse === void 0 ? void 0 : identityResponse.cacheMaxAge);
2806
+ switch (method) {
2807
+ case Login$2:
2808
+ case Identify$2:
2809
+ cacheIdentityRequest(method, knownIdentities, expireTimestamp, idCache, identityResponse);
2810
+ break;
2811
+ case Modify$4:
2812
+ case Logout$2:
2813
+ idCache.purge();
2814
+ break;
2815
+ }
2816
+ };
2817
+ var cacheIdentityRequest = function cacheIdentityRequest(method, identities, expireTimestamp, idCache, identityResponse) {
2818
+ var responseText = identityResponse.responseText,
2819
+ status = identityResponse.status;
2820
+ var cache = idCache.retrieve() || {};
2821
+ var cacheKey = concatenateIdentities(method, identities);
2822
+ var hashedKey = generateHash(cacheKey);
2823
+ var mpid = responseText.mpid,
2824
+ is_logged_in = responseText.is_logged_in;
2825
+ var cachedResponseBody = {
2826
+ mpid: mpid,
2827
+ is_logged_in: is_logged_in
2828
+ };
2829
+ cache[hashedKey] = {
2830
+ responseText: JSON.stringify(cachedResponseBody),
2831
+ status: status,
2832
+ expireTimestamp: expireTimestamp
2833
+ };
2834
+ idCache.store(cache);
2835
+ };
2836
+ // We need to ensure that identities are concatenated in a deterministic way, so
2837
+ // we sort the identities based on their enum.
2838
+ // we create an array, set the user identity at the index of the user identity type
2839
+ var concatenateIdentities = function concatenateIdentities(method, userIdentities) {
2840
+ var DEVICE_APPLICATION_STAMP = 'device_application_stamp';
2841
+ // set DAS first since it is not an official identity type
2842
+ var cacheKey = "".concat(method, ":").concat(DEVICE_APPLICATION_STAMP, "=").concat(userIdentities.device_application_stamp, ";");
2843
+ var idLength = Object.keys(userIdentities).length;
2844
+ var concatenatedIdentities = '';
2845
+ if (idLength) {
2846
+ var userIDArray = new Array();
2847
+ // create an array where each index is equal to the user identity type
2848
+ for (var key in userIdentities) {
2849
+ if (key === DEVICE_APPLICATION_STAMP) {
2850
+ continue;
2851
+ } else {
2852
+ userIDArray[Types.IdentityType.getIdentityType(key)] = userIdentities[key];
2853
+ }
2854
+ }
2855
+ concatenatedIdentities = userIDArray.reduce(function (prevValue, currentValue, index) {
2856
+ var idName = Types.IdentityType.getIdentityName(index);
2857
+ return "".concat(prevValue).concat(idName, "=").concat(currentValue, ";");
2858
+ }, cacheKey);
2859
+ }
2860
+ return concatenatedIdentities;
2861
+ };
2862
+ var hasValidCachedIdentity = function hasValidCachedIdentity(method, proposedUserIdentities, idCache) {
2863
+ // There is an edge case where multiple identity calls are taking place
2864
+ // before identify fires, so there may not be a cache. See what happens when
2865
+ // the ? in idCache is removed to the following test
2866
+ // "queued events contain login mpid instead of identify mpid when calling
2867
+ // login immediately after mParticle initializes"
2868
+ var cache = idCache === null || idCache === void 0 ? void 0 : idCache.retrieve();
2869
+ // if there is no cache, then there is no valid cached identity
2870
+ if (!cache) {
2871
+ return false;
2872
+ }
2873
+ var cacheKey = concatenateIdentities(method, proposedUserIdentities);
2874
+ var hashedKey = generateHash(cacheKey);
2875
+ // if cache doesn't have the cacheKey, there is no valid cached identity
2876
+ if (!cache.hasOwnProperty(hashedKey)) {
2877
+ return false;
2878
+ }
2879
+ // If there is a valid cache key, compare the expireTimestamp to the current time.
2880
+ // If the current time is greater than the expireTimestamp, it is not a valid
2881
+ // cached identity.
2882
+ var expireTimestamp = cache[hashedKey].expireTimestamp;
2883
+ if (expireTimestamp < new Date().getTime()) {
2884
+ return false;
2885
+ } else {
2886
+ return true;
2887
+ }
2888
+ };
2889
+ var getCachedIdentity = function getCachedIdentity(method, proposedUserIdentities, idCache) {
2890
+ var cacheKey = concatenateIdentities(method, proposedUserIdentities);
2891
+ var hashedKey = generateHash(cacheKey);
2892
+ var cache = idCache.retrieve();
2893
+ var cachedIdentity = cache ? cache[hashedKey] : null;
2894
+ return {
2895
+ responseText: parseIdentityResponse(cachedIdentity.responseText),
2896
+ expireTimestamp: cachedIdentity.expireTimestamp,
2897
+ status: cachedIdentity.status
2898
+ };
2899
+ };
2900
+ // https://go.mparticle.com/work/SQDSDKS-6079
2901
+ var createKnownIdentities = function createKnownIdentities(identityApiData, deviceId) {
2902
+ var identitiesResult = {};
2903
+ if (isObject(identityApiData === null || identityApiData === void 0 ? void 0 : identityApiData.userIdentities)) {
2904
+ for (var identity in identityApiData.userIdentities) {
2905
+ identitiesResult[identity] = identityApiData.userIdentities[identity];
2906
+ }
2907
+ }
2908
+ identitiesResult.device_application_stamp = deviceId;
2909
+ return identitiesResult;
2910
+ };
2911
+ var removeExpiredIdentityCacheDates = function removeExpiredIdentityCacheDates(idCache) {
2912
+ var cache = idCache.retrieve() || {};
2913
+ var currentTime = new Date().getTime();
2914
+ // Iterate over the cache and remove any key/value pairs that are expired
2915
+ for (var key in cache) {
2916
+ if (cache[key].expireTimestamp < currentTime) {
2917
+ delete cache[key];
2918
+ }
2919
+ }
2920
+ idCache.store(cache);
2921
+ };
2922
+ var tryCacheIdentity = function tryCacheIdentity(knownIdentities, idCache, parseIdentityResponse, mpid, callback, identityApiData, identityMethod) {
2923
+ // https://go.mparticle.com/work/SQDSDKS-6095
2924
+ var shouldReturnCachedIdentity = hasValidCachedIdentity(identityMethod, knownIdentities, idCache);
2925
+ // If Identity is cached, then immediately parse the identity response
2926
+ if (shouldReturnCachedIdentity) {
2927
+ var cachedIdentity = getCachedIdentity(identityMethod, knownIdentities, idCache);
2928
+ parseIdentityResponse(cachedIdentity, mpid, callback, identityApiData, identityMethod, knownIdentities, true);
2929
+ return true;
2930
+ }
2931
+ return false;
2932
+ };
2933
+ var getExpireTimestamp = function getExpireTimestamp(maxAge) {
2934
+ if (maxAge === void 0) {
2935
+ maxAge = ONE_DAY_IN_SECONDS;
2936
+ }
2937
+ return new Date().getTime() + maxAge * MILLIS_IN_ONE_SEC;
2938
+ };
2939
+ var parseIdentityResponse = function parseIdentityResponse(responseText) {
2940
+ return responseText ? JSON.parse(responseText) : {};
2941
+ };
2942
+ var hasIdentityRequestChanged = function hasIdentityRequestChanged(currentUser, newIdentityRequest) {
2943
+ if (!currentUser || !(newIdentityRequest === null || newIdentityRequest === void 0 ? void 0 : newIdentityRequest.userIdentities)) {
2944
+ return false;
2945
+ }
2946
+ var currentUserIdentities = currentUser.getUserIdentities().userIdentities;
2947
+ var newIdentities = newIdentityRequest.userIdentities;
2948
+ return JSON.stringify(currentUserIdentities) !== JSON.stringify(newIdentities);
2949
+ };
2950
+ /**
2951
+ * Checks if deviceId or other user identifiers (like email) were explicitly provided
2952
+ * by the partner via config.deviceId or config.identifyRequest.userIdentities.
2953
+ * When noFunctional is true, then cookies are blocked, so the partner must explicitly
2954
+ * pass deviceId or other identifiers to prevent new users from being created on each page load.
2955
+ *
2956
+ * @param store - The SDK store (provides SDKConfig.deviceId and SDKConfig.identifyRequest.userIdentities)
2957
+ * @returns true if deviceId or other identifiers were explicitly provided in config, false otherwise
2958
+ */
2959
+ var hasExplicitIdentifier = function hasExplicitIdentifier(store) {
2960
+ var _a, _b, _c;
2961
+ var userIdentities = (_b = (_a = store === null || store === void 0 ? void 0 : store.SDKConfig) === null || _a === void 0 ? void 0 : _a.identifyRequest) === null || _b === void 0 ? void 0 : _b.userIdentities;
2962
+ if (userIdentities && isObject(userIdentities) && !isEmpty(userIdentities) && Object.values(userIdentities).some(Boolean)) {
2963
+ return true;
2964
+ }
2965
+ return !!((_c = store === null || store === void 0 ? void 0 : store.SDKConfig) === null || _c === void 0 ? void 0 : _c.deviceId);
2966
+ };
2967
+
2770
2968
  function APIClient(mpInstance, kitBlocker) {
2771
2969
  this.uploader = null;
2772
2970
  var self = this;
@@ -2802,6 +3000,28 @@ var mParticle = (function () {
2802
3000
  }
2803
3001
  });
2804
3002
  };
3003
+ // When noFunctional is set and there are no identities passed, the SDK will not fully initialize.
3004
+ // In this case, there will be no MPID, but we still want kits to initialize and forward the event to kits.
3005
+ // The original event is queued for the MP server upload path so it can be sent once an MPID is returned.
3006
+ // Returns true if the event was handled by this path (caller should return early).
3007
+ var handleNoFunctionalPreMpidEvent = function handleNoFunctionalPreMpidEvent(event, mpid) {
3008
+ var _a;
3009
+ var noFunctionalWithoutId = ((_a = mpInstance._CookieConsentManager) === null || _a === void 0 ? void 0 : _a.getNoFunctional()) && !hasExplicitIdentifier(mpInstance._Store);
3010
+ if (!noFunctionalWithoutId || mpid || !mpInstance._Store.configurationLoaded || mpInstance._Store.requireDelay) {
3011
+ return false;
3012
+ }
3013
+ var forwarderEvent = event;
3014
+ if (kitBlocker === null || kitBlocker === void 0 ? void 0 : kitBlocker.kitBlockingEnabled) {
3015
+ forwarderEvent = kitBlocker.createBlockedEvent(event);
3016
+ }
3017
+ if (forwarderEvent) {
3018
+ mpInstance._Forwarders.sendEventToForwarders(forwarderEvent);
3019
+ event.AlreadySentToForwarders = true;
3020
+ }
3021
+ mpInstance.Logger.verbose('noFunctional event forwarded to kits and queued for MP server upload when MPID is available.');
3022
+ mpInstance._Store.eventQueue.push(event);
3023
+ return true;
3024
+ };
2805
3025
  this.sendEventToServer = function (event, _options) {
2806
3026
  var defaultOptions = {
2807
3027
  shouldUploadEvent: true
@@ -2817,8 +3037,12 @@ var mParticle = (function () {
2817
3037
  mpid = currentUser.getMPID();
2818
3038
  }
2819
3039
  mpInstance._Store.requireDelay = mpInstance._Helpers.isDelayedByIntegration(mpInstance._preInit.integrationDelays, mpInstance._Store.integrationDelayTimeoutStart, Date.now());
2820
- // We queue events if there is no MPID (MPID is null, or === 0), or there are integrations that that require this to stall because integration attributes
2821
- // need to be set, or if we are still fetching the config (self hosted only), and so require delaying events
3040
+ if (handleNoFunctionalPreMpidEvent(event, mpid)) {
3041
+ return;
3042
+ }
3043
+ // We queue events if there is no MPID (MPID is null, or === 0), or there are integrations that
3044
+ // require this to stall because integration attributes need to be set, or if we are still
3045
+ // fetching the config (self hosted only), and so require delaying events
2822
3046
  if (!mpid || mpInstance._Store.requireDelay || !mpInstance._Store.configurationLoaded) {
2823
3047
  mpInstance.Logger.verbose('Event was added to eventQueue. eventQueue will be processed once a valid MPID is returned or there is no more integration imposed delay.');
2824
3048
  mpInstance._Store.eventQueue.push(event);
@@ -2840,8 +3064,10 @@ var mParticle = (function () {
2840
3064
  event = kitBlocker.createBlockedEvent(event);
2841
3065
  }
2842
3066
  // We need to check event again, because kitblocking
2843
- // can nullify the event
2844
- if (event) {
3067
+ // can nullify the event.
3068
+ // Skip if forwarders were already called in the noFunctional pre-MPID path
3069
+ // to prevent double-sending when the event queue is later flushed.
3070
+ if (event && !event.AlreadySentToForwarders) {
2845
3071
  mpInstance._Forwarders.sendEventToForwarders(event);
2846
3072
  }
2847
3073
  }
@@ -2900,7 +3126,7 @@ var mParticle = (function () {
2900
3126
  };
2901
3127
  }
2902
3128
 
2903
- var Modify$4 = Constants.IdentityMethods.Modify;
3129
+ var Modify$3 = Constants.IdentityMethods.Modify;
2904
3130
  var Validators = {
2905
3131
  // From ./utils
2906
3132
  // Utility Functions for backwards compatability
@@ -2940,7 +3166,7 @@ var mParticle = (function () {
2940
3166
  copyUserAttributes: 1
2941
3167
  };
2942
3168
  if (identityApiData) {
2943
- if (method === Modify$4) {
3169
+ if (method === Modify$3) {
2944
3170
  if (isObject(identityApiData.userIdentities) && !Object.keys(identityApiData.userIdentities).length || !isObject(identityApiData.userIdentities)) {
2945
3171
  return {
2946
3172
  valid: false,
@@ -3506,12 +3732,18 @@ var mParticle = (function () {
3506
3732
  var self = this;
3507
3733
  // Public
3508
3734
  this.attemptCookieSync = function (mpid, mpidIsNotInCookies) {
3509
- var _a = mpInstance._Store,
3510
- pixelConfigurations = _a.pixelConfigurations,
3511
- webviewBridgeEnabled = _a.webviewBridgeEnabled;
3735
+ var _a;
3736
+ var _b = mpInstance._Store,
3737
+ pixelConfigurations = _b.pixelConfigurations,
3738
+ webviewBridgeEnabled = _b.webviewBridgeEnabled;
3512
3739
  if (!mpid || webviewBridgeEnabled) {
3513
3740
  return;
3514
3741
  }
3742
+ // When noFunctional is true, persistence is not saved, so we cannot track cookie sync
3743
+ // dates. Skip cookie sync to avoid running it on every page load.
3744
+ if ((_a = mpInstance._CookieConsentManager) === null || _a === void 0 ? void 0 : _a.getNoFunctional()) {
3745
+ return;
3746
+ }
3515
3747
  var persistence = mpInstance._Persistence.getPersistence();
3516
3748
  if (isEmpty(persistence)) {
3517
3749
  return;
@@ -3583,172 +3815,15 @@ var mParticle = (function () {
3583
3815
  return new Date().getTime() > new Date(lastSyncDate).getTime() + frequencyCap * DAYS_IN_MILLISECONDS;
3584
3816
  };
3585
3817
 
3586
- var _a = Constants.IdentityMethods,
3587
- Identify$2 = _a.Identify,
3588
- Modify$3 = _a.Modify,
3589
- Login$2 = _a.Login,
3590
- Logout$2 = _a.Logout;
3591
- var CACHE_HEADER = 'x-mp-max-age';
3592
- var cacheOrClearIdCache = function cacheOrClearIdCache(method, knownIdentities, idCache, identityResponse, parsingCachedResponse) {
3593
- // when parsing a response that has already been cached, simply return instead of attempting another cache
3594
- if (parsingCachedResponse) {
3595
- return;
3596
- }
3597
- // default the expire timestamp to one day in milliseconds unless a header comes back
3598
- var expireTimestamp = getExpireTimestamp(identityResponse === null || identityResponse === void 0 ? void 0 : identityResponse.cacheMaxAge);
3599
- switch (method) {
3600
- case Login$2:
3601
- case Identify$2:
3602
- cacheIdentityRequest(method, knownIdentities, expireTimestamp, idCache, identityResponse);
3603
- break;
3604
- case Modify$3:
3605
- case Logout$2:
3606
- idCache.purge();
3607
- break;
3608
- }
3609
- };
3610
- var cacheIdentityRequest = function cacheIdentityRequest(method, identities, expireTimestamp, idCache, identityResponse) {
3611
- var responseText = identityResponse.responseText,
3612
- status = identityResponse.status;
3613
- var cache = idCache.retrieve() || {};
3614
- var cacheKey = concatenateIdentities(method, identities);
3615
- var hashedKey = generateHash(cacheKey);
3616
- var mpid = responseText.mpid,
3617
- is_logged_in = responseText.is_logged_in;
3618
- var cachedResponseBody = {
3619
- mpid: mpid,
3620
- is_logged_in: is_logged_in
3621
- };
3622
- cache[hashedKey] = {
3623
- responseText: JSON.stringify(cachedResponseBody),
3624
- status: status,
3625
- expireTimestamp: expireTimestamp
3626
- };
3627
- idCache.store(cache);
3628
- };
3629
- // We need to ensure that identities are concatenated in a deterministic way, so
3630
- // we sort the identities based on their enum.
3631
- // we create an array, set the user identity at the index of the user identity type
3632
- var concatenateIdentities = function concatenateIdentities(method, userIdentities) {
3633
- var DEVICE_APPLICATION_STAMP = 'device_application_stamp';
3634
- // set DAS first since it is not an official identity type
3635
- var cacheKey = "".concat(method, ":").concat(DEVICE_APPLICATION_STAMP, "=").concat(userIdentities.device_application_stamp, ";");
3636
- var idLength = Object.keys(userIdentities).length;
3637
- var concatenatedIdentities = '';
3638
- if (idLength) {
3639
- var userIDArray = new Array();
3640
- // create an array where each index is equal to the user identity type
3641
- for (var key in userIdentities) {
3642
- if (key === DEVICE_APPLICATION_STAMP) {
3643
- continue;
3644
- } else {
3645
- userIDArray[Types.IdentityType.getIdentityType(key)] = userIdentities[key];
3646
- }
3647
- }
3648
- concatenatedIdentities = userIDArray.reduce(function (prevValue, currentValue, index) {
3649
- var idName = Types.IdentityType.getIdentityName(index);
3650
- return "".concat(prevValue).concat(idName, "=").concat(currentValue, ";");
3651
- }, cacheKey);
3652
- }
3653
- return concatenatedIdentities;
3654
- };
3655
- var hasValidCachedIdentity = function hasValidCachedIdentity(method, proposedUserIdentities, idCache) {
3656
- // There is an edge case where multiple identity calls are taking place
3657
- // before identify fires, so there may not be a cache. See what happens when
3658
- // the ? in idCache is removed to the following test
3659
- // "queued events contain login mpid instead of identify mpid when calling
3660
- // login immediately after mParticle initializes"
3661
- var cache = idCache === null || idCache === void 0 ? void 0 : idCache.retrieve();
3662
- // if there is no cache, then there is no valid cached identity
3663
- if (!cache) {
3664
- return false;
3665
- }
3666
- var cacheKey = concatenateIdentities(method, proposedUserIdentities);
3667
- var hashedKey = generateHash(cacheKey);
3668
- // if cache doesn't have the cacheKey, there is no valid cached identity
3669
- if (!cache.hasOwnProperty(hashedKey)) {
3670
- return false;
3671
- }
3672
- // If there is a valid cache key, compare the expireTimestamp to the current time.
3673
- // If the current time is greater than the expireTimestamp, it is not a valid
3674
- // cached identity.
3675
- var expireTimestamp = cache[hashedKey].expireTimestamp;
3676
- if (expireTimestamp < new Date().getTime()) {
3677
- return false;
3678
- } else {
3679
- return true;
3680
- }
3681
- };
3682
- var getCachedIdentity = function getCachedIdentity(method, proposedUserIdentities, idCache) {
3683
- var cacheKey = concatenateIdentities(method, proposedUserIdentities);
3684
- var hashedKey = generateHash(cacheKey);
3685
- var cache = idCache.retrieve();
3686
- var cachedIdentity = cache ? cache[hashedKey] : null;
3687
- return {
3688
- responseText: parseIdentityResponse(cachedIdentity.responseText),
3689
- expireTimestamp: cachedIdentity.expireTimestamp,
3690
- status: cachedIdentity.status
3691
- };
3692
- };
3693
- // https://go.mparticle.com/work/SQDSDKS-6079
3694
- var createKnownIdentities = function createKnownIdentities(identityApiData, deviceId) {
3695
- var identitiesResult = {};
3696
- if (isObject(identityApiData === null || identityApiData === void 0 ? void 0 : identityApiData.userIdentities)) {
3697
- for (var identity in identityApiData.userIdentities) {
3698
- identitiesResult[identity] = identityApiData.userIdentities[identity];
3699
- }
3700
- }
3701
- identitiesResult.device_application_stamp = deviceId;
3702
- return identitiesResult;
3703
- };
3704
- var removeExpiredIdentityCacheDates = function removeExpiredIdentityCacheDates(idCache) {
3705
- var cache = idCache.retrieve() || {};
3706
- var currentTime = new Date().getTime();
3707
- // Iterate over the cache and remove any key/value pairs that are expired
3708
- for (var key in cache) {
3709
- if (cache[key].expireTimestamp < currentTime) {
3710
- delete cache[key];
3711
- }
3712
- }
3713
- idCache.store(cache);
3714
- };
3715
- var tryCacheIdentity = function tryCacheIdentity(knownIdentities, idCache, parseIdentityResponse, mpid, callback, identityApiData, identityMethod) {
3716
- // https://go.mparticle.com/work/SQDSDKS-6095
3717
- var shouldReturnCachedIdentity = hasValidCachedIdentity(identityMethod, knownIdentities, idCache);
3718
- // If Identity is cached, then immediately parse the identity response
3719
- if (shouldReturnCachedIdentity) {
3720
- var cachedIdentity = getCachedIdentity(identityMethod, knownIdentities, idCache);
3721
- parseIdentityResponse(cachedIdentity, mpid, callback, identityApiData, identityMethod, knownIdentities, true);
3722
- return true;
3723
- }
3724
- return false;
3725
- };
3726
- var getExpireTimestamp = function getExpireTimestamp(maxAge) {
3727
- if (maxAge === void 0) {
3728
- maxAge = ONE_DAY_IN_SECONDS;
3729
- }
3730
- return new Date().getTime() + maxAge * MILLIS_IN_ONE_SEC;
3731
- };
3732
- var parseIdentityResponse = function parseIdentityResponse(responseText) {
3733
- return responseText ? JSON.parse(responseText) : {};
3734
- };
3735
- var hasIdentityRequestChanged = function hasIdentityRequestChanged(currentUser, newIdentityRequest) {
3736
- if (!currentUser || !(newIdentityRequest === null || newIdentityRequest === void 0 ? void 0 : newIdentityRequest.userIdentities)) {
3737
- return false;
3738
- }
3739
- var currentUserIdentities = currentUser.getUserIdentities().userIdentities;
3740
- var newIdentities = newIdentityRequest.userIdentities;
3741
- return JSON.stringify(currentUserIdentities) !== JSON.stringify(newIdentities);
3742
- };
3743
-
3744
3818
  var Messages$6 = Constants.Messages;
3745
3819
  function SessionManager(mpInstance) {
3746
3820
  var self = this;
3747
3821
  this.initialize = function () {
3822
+ var _a;
3748
3823
  if (mpInstance._Store.sessionId) {
3749
- var _a = mpInstance._Store,
3750
- dateLastEventSent = _a.dateLastEventSent,
3751
- SDKConfig = _a.SDKConfig;
3824
+ var _b = mpInstance._Store,
3825
+ dateLastEventSent = _b.dateLastEventSent,
3826
+ SDKConfig = _b.SDKConfig;
3752
3827
  var sessionTimeout = SDKConfig.sessionTimeout;
3753
3828
  if (hasSessionTimedOut(dateLastEventSent === null || dateLastEventSent === void 0 ? void 0 : dateLastEventSent.getTime(), sessionTimeout)) {
3754
3829
  self.endSession();
@@ -3758,7 +3833,8 @@ var mParticle = (function () {
3758
3833
  // https://go.mparticle.com/work/SQDSDKS-6323
3759
3834
  var currentUser = mpInstance.Identity.getCurrentUser();
3760
3835
  var sdkIdentityRequest = SDKConfig.identifyRequest;
3761
- if (hasIdentityRequestChanged(currentUser, sdkIdentityRequest)) {
3836
+ var shouldSuppressIdentify = ((_a = mpInstance._CookieConsentManager) === null || _a === void 0 ? void 0 : _a.getNoFunctional()) && !hasExplicitIdentifier(mpInstance._Store);
3837
+ if (!shouldSuppressIdentify && hasIdentityRequestChanged(currentUser, sdkIdentityRequest)) {
3762
3838
  mpInstance.Identity.identify(sdkIdentityRequest, SDKConfig.identityCallback);
3763
3839
  mpInstance._Store.identifyCalled = true;
3764
3840
  mpInstance._Store.SDKConfig.identityCallback = null;
@@ -3776,6 +3852,7 @@ var mParticle = (function () {
3776
3852
  return mpInstance._Store.sessionId;
3777
3853
  };
3778
3854
  this.startNewSession = function () {
3855
+ var _a;
3779
3856
  mpInstance.Logger.verbose(Messages$6.InformationMessages.StartingNewSession);
3780
3857
  if (mpInstance._Helpers.canLog()) {
3781
3858
  mpInstance._Store.sessionId = mpInstance._Helpers.generateUniqueId().toUpperCase();
@@ -3790,7 +3867,8 @@ var mParticle = (function () {
3790
3867
  mpInstance._Store.dateLastEventSent = date;
3791
3868
  }
3792
3869
  self.setSessionTimer();
3793
- if (!mpInstance._Store.identifyCalled) {
3870
+ var shouldSuppressIdentify = ((_a = mpInstance._CookieConsentManager) === null || _a === void 0 ? void 0 : _a.getNoFunctional()) && !hasExplicitIdentifier(mpInstance._Store);
3871
+ if (!mpInstance._Store.identifyCalled && !shouldSuppressIdentify) {
3794
3872
  mpInstance.Identity.identify(mpInstance._Store.SDKConfig.identifyRequest, mpInstance._Store.SDKConfig.identityCallback);
3795
3873
  mpInstance._Store.identifyCalled = true;
3796
3874
  mpInstance._Store.SDKConfig.identityCallback = null;
@@ -4316,14 +4394,20 @@ var mParticle = (function () {
4316
4394
  }
4317
4395
 
4318
4396
  var ForegroundTimeTracker = /** @class */function () {
4319
- function ForegroundTimeTracker(timerKey) {
4397
+ function ForegroundTimeTracker(timerKey, noFunctional) {
4398
+ if (noFunctional === void 0) {
4399
+ noFunctional = false;
4400
+ }
4401
+ this.noFunctional = noFunctional;
4320
4402
  this.isTrackerActive = false;
4321
4403
  this.localStorageName = '';
4322
4404
  this.startTime = 0;
4323
4405
  this.totalTime = 0;
4324
4406
  this.localStorageName = "mprtcl-tos-".concat(timerKey);
4325
4407
  this.timerVault = new LocalStorageVault(this.localStorageName);
4326
- this.loadTimeFromStorage();
4408
+ if (!this.noFunctional) {
4409
+ this.loadTimeFromStorage();
4410
+ }
4327
4411
  this.addHandlers();
4328
4412
  if (document.hidden === false) {
4329
4413
  this.startTracking();
@@ -4376,7 +4460,7 @@ var mParticle = (function () {
4376
4460
  }
4377
4461
  };
4378
4462
  ForegroundTimeTracker.prototype.updateTimeInPersistence = function () {
4379
- if (this.isTrackerActive) {
4463
+ if (this.isTrackerActive && !this.noFunctional) {
4380
4464
  this.timerVault.store(Math.round(this.totalTime));
4381
4465
  }
4382
4466
  };
@@ -4774,6 +4858,7 @@ var mParticle = (function () {
4774
4858
  mpInstance._Persistence.update();
4775
4859
  };
4776
4860
  this.processConfig = function (config) {
4861
+ var _a;
4777
4862
  var workspaceToken = config.workspaceToken,
4778
4863
  requiredWebviewBridgeName = config.requiredWebviewBridgeName;
4779
4864
  // We should reprocess the flags and baseUrls in case they have changed when we request an updated config
@@ -4789,7 +4874,8 @@ var mParticle = (function () {
4789
4874
  }
4790
4875
  if (workspaceToken) {
4791
4876
  _this.SDKConfig.workspaceToken = workspaceToken;
4792
- mpInstance._timeOnSiteTimer = new ForegroundTimeTracker(workspaceToken);
4877
+ var noFunctional = ((_a = config === null || config === void 0 ? void 0 : config.launcherOptions) === null || _a === void 0 ? void 0 : _a.noFunctional) === true;
4878
+ mpInstance._timeOnSiteTimer = new ForegroundTimeTracker(workspaceToken, noFunctional);
4793
4879
  } else {
4794
4880
  mpInstance.Logger.warning('You should have a workspaceToken on your config object for security purposes.');
4795
4881
  }
@@ -5123,9 +5209,15 @@ var mParticle = (function () {
5123
5209
 
5124
5210
  // https://go.mparticle.com/work/SQDSDKS-6021
5125
5211
  this.setLocalStorage = function () {
5212
+ var _mpInstance$_CookieCo;
5126
5213
  if (!mpInstance._Store.isLocalStorageAvailable) {
5127
5214
  return;
5128
5215
  }
5216
+
5217
+ // Block mprtcl-v4 localStorage when noFunctional is true
5218
+ if ((_mpInstance$_CookieCo = mpInstance._CookieConsentManager) !== null && _mpInstance$_CookieCo !== void 0 && _mpInstance$_CookieCo.getNoFunctional()) {
5219
+ return;
5220
+ }
5129
5221
  var key = mpInstance._Store.storageName,
5130
5222
  localStorageData = self.getLocalStorage() || {},
5131
5223
  currentUser = mpInstance.Identity.getCurrentUser(),
@@ -5251,6 +5343,11 @@ var mParticle = (function () {
5251
5343
  // https://go.mparticle.com/work/SQDSDKS-5022
5252
5344
  // https://go.mparticle.com/work/SQDSDKS-6021
5253
5345
  this.setCookie = function () {
5346
+ var _mpInstance$_CookieCo2;
5347
+ // Block mprtcl-v4 cookies when noFunctional is true
5348
+ if ((_mpInstance$_CookieCo2 = mpInstance._CookieConsentManager) !== null && _mpInstance$_CookieCo2 !== void 0 && _mpInstance$_CookieCo2.getNoFunctional()) {
5349
+ return;
5350
+ }
5254
5351
  var mpid,
5255
5352
  currentUser = mpInstance.Identity.getCurrentUser();
5256
5353
  if (currentUser) {
@@ -5526,6 +5623,11 @@ var mParticle = (function () {
5526
5623
 
5527
5624
  // https://go.mparticle.com/work/SQDSDKS-6021
5528
5625
  this.savePersistence = function (persistence) {
5626
+ var _mpInstance$_CookieCo3;
5627
+ // Block mprtcl-v4 persistence when noFunctional is true
5628
+ if ((_mpInstance$_CookieCo3 = mpInstance._CookieConsentManager) !== null && _mpInstance$_CookieCo3 !== void 0 && _mpInstance$_CookieCo3.getNoFunctional()) {
5629
+ return;
5630
+ }
5529
5631
  var encodedPersistence = self.encodePersistence(JSON.stringify(persistence)),
5530
5632
  date = new Date(),
5531
5633
  key = mpInstance._Store.storageName,
@@ -10466,6 +10568,19 @@ var mParticle = (function () {
10466
10568
  self._preInit.readyQueue = processReadyQueue(self._preInit.readyQueue);
10467
10569
  }
10468
10570
  };
10571
+ /**
10572
+ * Drains the ready queue for noFunctional sessions with no explicit identity.
10573
+ */
10574
+ this.processQueueOnNoFunctional = function () {
10575
+ var _a, _b;
10576
+ if ((_a = self._Store) === null || _a === void 0 ? void 0 : _a.isInitialized) {
10577
+ return;
10578
+ }
10579
+ var noFunctionalWithoutId = ((_b = self._CookieConsentManager) === null || _b === void 0 ? void 0 : _b.getNoFunctional()) && !hasExplicitIdentifier(self._Store);
10580
+ if (noFunctionalWithoutId) {
10581
+ self._preInit.readyQueue = processReadyQueue(self._preInit.readyQueue);
10582
+ }
10583
+ };
10469
10584
  // required for forwarders once they reference the mparticle instance
10470
10585
  this.IdentityType = IdentityType;
10471
10586
  this.EventType = EventType;
@@ -10563,8 +10678,9 @@ var mParticle = (function () {
10563
10678
  * @param {Function} f Callback to execute
10564
10679
  */
10565
10680
  this.ready = function (f) {
10566
- var _a, _b;
10567
- var shouldExecute = isFunction(f) && (((_a = self._Store) === null || _a === void 0 ? void 0 : _a.isInitialized) || ((_b = self._Store) === null || _b === void 0 ? void 0 : _b.identityCallFailed) && self._RoktManager.isReady());
10681
+ var _a, _b, _c;
10682
+ var noFunctionalWithoutId = ((_a = self._CookieConsentManager) === null || _a === void 0 ? void 0 : _a.getNoFunctional()) && !hasExplicitIdentifier(self._Store);
10683
+ var shouldExecute = isFunction(f) && (((_b = self._Store) === null || _b === void 0 ? void 0 : _b.isInitialized) || ((_c = self._Store) === null || _c === void 0 ? void 0 : _c.identityCallFailed) && self._RoktManager.isReady() || noFunctionalWithoutId);
10568
10684
  if (shouldExecute) {
10569
10685
  f();
10570
10686
  } else {
@@ -11168,10 +11284,14 @@ var mParticle = (function () {
11168
11284
  * @param {String or Number} value value for session attribute
11169
11285
  */
11170
11286
  this.setSessionAttribute = function (key, value) {
11171
- var queued = queueIfNotInitialized(function () {
11172
- self.setSessionAttribute(key, value);
11173
- }, self);
11174
- if (queued) return;
11287
+ var _a;
11288
+ var skipQueue = ((_a = self._CookieConsentManager) === null || _a === void 0 ? void 0 : _a.getNoFunctional()) && !hasExplicitIdentifier(self._Store);
11289
+ if (!skipQueue) {
11290
+ var queued = queueIfNotInitialized(function () {
11291
+ self.setSessionAttribute(key, value);
11292
+ }, self);
11293
+ if (queued) return;
11294
+ }
11175
11295
  // Logs to cookie
11176
11296
  // And logs to in-memory object
11177
11297
  // Example: mParticle.setSessionAttribute('location', '33431');
@@ -11369,7 +11489,7 @@ var mParticle = (function () {
11369
11489
  }
11370
11490
  // Some (server) config settings need to be returned before they are set on SDKConfig in a self hosted environment
11371
11491
  function completeSDKInitialization(apiKey, config, mpInstance) {
11372
- var _a;
11492
+ var _a, _b;
11373
11493
  var kitBlocker = createKitBlocker(config, mpInstance);
11374
11494
  var getFeatureFlag = mpInstance._Helpers.getFeatureFlag;
11375
11495
  mpInstance._APIClient = new APIClient(mpInstance, kitBlocker);
@@ -11443,6 +11563,9 @@ var mParticle = (function () {
11443
11563
  mpInstance._Store.isInitialized = true;
11444
11564
  mpInstance._preInit.readyQueue = processReadyQueue(mpInstance._preInit.readyQueue);
11445
11565
  }
11566
+ // For noFunctional sessions with no identity, drain any pre-init ready callbacks
11567
+ // that were queued before _CookieConsentManager was available to evaluate the condition.
11568
+ (_b = mpInstance.processQueueOnNoFunctional) === null || _b === void 0 ? void 0 : _b.call(mpInstance);
11446
11569
  // https://go.mparticle.com/work/SQDSDKS-6040
11447
11570
  if (mpInstance._Store.isFirstRun) {
11448
11571
  mpInstance._Store.isFirstRun = false;
@@ -11508,6 +11631,14 @@ var mParticle = (function () {
11508
11631
  return kitBlocker;
11509
11632
  }
11510
11633
  function createIdentityCache(mpInstance) {
11634
+ var _a;
11635
+ // Identity expects mpInstance._Identity.idCache to always exist. DisabledVault
11636
+ // ensures no identity response data is written to localStorage when noFunctional is true
11637
+ if ((_a = mpInstance._CookieConsentManager) === null || _a === void 0 ? void 0 : _a.getNoFunctional()) {
11638
+ return new DisabledVault("".concat(mpInstance._Store.storageName, "-id-cache"), {
11639
+ logger: mpInstance.Logger
11640
+ });
11641
+ }
11511
11642
  return new LocalStorageVault("".concat(mpInstance._Store.storageName, "-id-cache"), {
11512
11643
  logger: mpInstance.Logger
11513
11644
  });
@@ -11570,18 +11701,21 @@ var mParticle = (function () {
11570
11701
  }
11571
11702
  }
11572
11703
  function queueIfNotInitialized(func, self) {
11573
- var _a;
11574
- // Core SDK methods must wait for Store initialization
11575
- if (!((_a = self._Store) === null || _a === void 0 ? void 0 : _a.isInitialized)) {
11576
- self._preInit.readyQueue.push(function () {
11577
- var _a;
11578
- if ((_a = self._Store) === null || _a === void 0 ? void 0 : _a.isInitialized) {
11579
- func();
11580
- }
11581
- });
11582
- return true;
11704
+ var _a, _b;
11705
+ // When noFunctional is true with no explicit identifier, the SDK will never
11706
+ // receive an MPID. Let these calls through so events can still reach forwarders immediately.
11707
+ // sendEventToServer handles queuing for the MP server upload path separately.
11708
+ var noFunctionalWithoutId = ((_a = self._CookieConsentManager) === null || _a === void 0 ? void 0 : _a.getNoFunctional()) && !hasExplicitIdentifier(self._Store);
11709
+ if (((_b = self._Store) === null || _b === void 0 ? void 0 : _b.isInitialized) || noFunctionalWithoutId) {
11710
+ return false;
11583
11711
  }
11584
- return false;
11712
+ self._preInit.readyQueue.push(function () {
11713
+ var _a;
11714
+ if ((_a = self._Store) === null || _a === void 0 ? void 0 : _a.isInitialized) {
11715
+ func();
11716
+ }
11717
+ });
11718
+ return true;
11585
11719
  }
11586
11720
 
11587
11721
  // This file is used ONLY for the mParticle ESLint plugin. It should NOT be used otherwise!