@mparticle/web-sdk 2.14.0 → 2.15.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
@@ -719,7 +719,7 @@ var mParticle = (function () {
719
719
  TriggerUploadType: TriggerUploadType
720
720
  };
721
721
 
722
- var version = "2.14.0";
722
+ var version = "2.15.0";
723
723
 
724
724
  var Constants = {
725
725
  sdkVersion: version,
@@ -2691,7 +2691,8 @@ var mParticle = (function () {
2691
2691
  var astEventData = {
2692
2692
  application_transition_type: dist_3.applicationInitialized,
2693
2693
  is_first_run: sdkEvent.IsFirstRun,
2694
- is_upgrade: false
2694
+ is_upgrade: false,
2695
+ launch_referral: sdkEvent.LaunchReferral
2695
2696
  };
2696
2697
  astEventData = Object.assign(astEventData, commonEventData);
2697
2698
  return {
@@ -4447,10 +4448,14 @@ var mParticle = (function () {
4447
4448
  if (mpInstance._Consent.isEnabledForUserConsent(filteringConsentRuleValues, mpInstance.Identity.getCurrentUser())) {
4448
4449
  var img = document.createElement('img');
4449
4450
  mpInstance.Logger.verbose(Messages$2.InformationMessages.CookieSync);
4450
- img.src = url;
4451
- cookieSyncDates[moduleId.toString()] = new Date().getTime();
4452
4451
 
4453
- mpInstance._Persistence.saveUserCookieSyncDatesToPersistence(mpid, cookieSyncDates);
4452
+ img.onload = function () {
4453
+ cookieSyncDates[moduleId.toString()] = new Date().getTime();
4454
+
4455
+ mpInstance._Persistence.saveUserCookieSyncDatesToPersistence(mpid, cookieSyncDates);
4456
+ };
4457
+
4458
+ img.src = url;
4454
4459
  }
4455
4460
  };
4456
4461
  }
@@ -5201,6 +5206,10 @@ var mParticle = (function () {
5201
5206
  this.SDKConfig = createSDKConfig(config); // Set configuration to default settings
5202
5207
 
5203
5208
  if (config) {
5209
+ if (config.deviceId) {
5210
+ this.deviceId = config.deviceId;
5211
+ }
5212
+
5204
5213
  if (config.hasOwnProperty('isDevelopmentMode')) {
5205
5214
  this.SDKConfig.isDevelopmentMode = mpInstance._Helpers.returnConvertedBoolean(config.isDevelopmentMode);
5206
5215
  } else {
@@ -6405,6 +6414,11 @@ var mParticle = (function () {
6405
6414
  return mpInstance._Store.deviceId;
6406
6415
  };
6407
6416
 
6417
+ this.setDeviceId = function (guid) {
6418
+ mpInstance._Store.deviceId = guid;
6419
+ self.update();
6420
+ };
6421
+
6408
6422
  this.resetPersistence = function () {
6409
6423
  removeLocalStorage(StorageNames$1.localStorageName);
6410
6424
  removeLocalStorage(StorageNames$1.localStorageNameV3);
@@ -6625,7 +6639,7 @@ var mParticle = (function () {
6625
6639
  event.EventCategory = mpInstance._Ecommerce.convertPromotionActionToEventType(promotionType);
6626
6640
  event.PromotionAction = {
6627
6641
  PromotionActionType: promotionType,
6628
- PromotionList: [promotion]
6642
+ PromotionList: Array.isArray(promotion) ? promotion : [promotion]
6629
6643
  };
6630
6644
  self.logCommerceEvent(event, attrs, eventOptions);
6631
6645
  }
@@ -7262,9 +7276,10 @@ var mParticle = (function () {
7262
7276
  filterUserIdentities(clonedEvent, mpInstance._Store.activeForwarders[i].userIdentityFilters); // Check user attribute filtering rules
7263
7277
 
7264
7278
  clonedEvent.UserAttributes = mpInstance._Helpers.filterUserAttributes(clonedEvent.UserAttributes, mpInstance._Store.activeForwarders[i].userAttributeFilters);
7265
- mpInstance.Logger.verbose('Sending message to forwarder: ' + mpInstance._Store.activeForwarders[i].name);
7266
7279
 
7267
7280
  if (mpInstance._Store.activeForwarders[i].process) {
7281
+ mpInstance.Logger.verbose('Sending message to forwarder: ' + mpInstance._Store.activeForwarders[i].name);
7282
+
7268
7283
  var result = mpInstance._Store.activeForwarders[i].process(clonedEvent);
7269
7284
 
7270
7285
  if (result) {
@@ -7657,6 +7672,7 @@ var mParticle = (function () {
7657
7672
 
7658
7673
  if (eventObject.EventDataType === MessageType$1.AppStateTransition) {
7659
7674
  eventObject.IsFirstRun = mpInstance._Store.isFirstRun;
7675
+ eventObject.LaunchReferral = window.location.href || null;
7660
7676
  }
7661
7677
 
7662
7678
  eventObject.CurrencyCode = mpInstance._Store.currencyCode;
@@ -7722,7 +7738,7 @@ var mParticle = (function () {
7722
7738
  dto.fr = event.IsFirstRun;
7723
7739
  dto.iu = false;
7724
7740
  dto.at = ApplicationTransitionType$1.AppInit;
7725
- dto.lr = window.location.href || null;
7741
+ dto.lr = event.LaunchReferral;
7726
7742
  dto.attrs = null;
7727
7743
  }
7728
7744
 
@@ -10219,10 +10235,14 @@ var mParticle = (function () {
10219
10235
 
10220
10236
 
10221
10237
  this.reset = function (instance) {
10222
- instance._Persistence.resetPersistence();
10238
+ try {
10239
+ instance._Persistence.resetPersistence();
10223
10240
 
10224
- if (instance._Store) {
10225
- delete instance._Store;
10241
+ if (instance._Store) {
10242
+ delete instance._Store;
10243
+ }
10244
+ } catch (error) {
10245
+ console.error('Cannot reset mParticle', error);
10226
10246
  }
10227
10247
  };
10228
10248
 
@@ -10258,7 +10278,7 @@ var mParticle = (function () {
10258
10278
 
10259
10279
 
10260
10280
  this.ready = function (f) {
10261
- if (self._Store.isInitialized && typeof f === 'function') {
10281
+ if (self.isInitialized() && typeof f === 'function') {
10262
10282
  f();
10263
10283
  } else {
10264
10284
  self._preInit.readyQueue.push(f);
@@ -10282,10 +10302,39 @@ var mParticle = (function () {
10282
10302
 
10283
10303
 
10284
10304
  this.setAppVersion = function (version) {
10305
+ var queued = queueIfNotInitialized(function () {
10306
+ self.setAppVersion(version);
10307
+ }, self);
10308
+ if (queued) return;
10285
10309
  self._Store.SDKConfig.appVersion = version;
10286
10310
 
10287
10311
  self._Persistence.update();
10288
10312
  };
10313
+ /**
10314
+ * Sets the device id
10315
+ * @method setDeviceId
10316
+ * @param {String} name device ID (UUIDv4-formatted string)
10317
+ */
10318
+
10319
+
10320
+ this.setDeviceId = function (guid) {
10321
+ var queued = queueIfNotInitialized(function () {
10322
+ self.setDeviceId(guid);
10323
+ }, self);
10324
+ if (queued) return;
10325
+
10326
+ this._Persistence.setDeviceId(guid);
10327
+ };
10328
+ /**
10329
+ * Returns a boolean for whether or not the SDKhas been fully initialized
10330
+ * @method isInitialized
10331
+ * @return {Boolean} a boolean for whether or not the SDK has been fully initialized
10332
+ */
10333
+
10334
+
10335
+ this.isInitialized = function () {
10336
+ return self._Store ? self._Store.isInitialized : false;
10337
+ };
10289
10338
  /**
10290
10339
  * Gets the app name
10291
10340
  * @method getAppName
@@ -10304,6 +10353,10 @@ var mParticle = (function () {
10304
10353
 
10305
10354
 
10306
10355
  this.setAppName = function (name) {
10356
+ var queued = queueIfNotInitialized(function () {
10357
+ self.setAppName(name);
10358
+ }, self);
10359
+ if (queued) return;
10307
10360
  self._Store.SDKConfig.appName = name;
10308
10361
  };
10309
10362
  /**
@@ -10352,6 +10405,11 @@ var mParticle = (function () {
10352
10405
 
10353
10406
 
10354
10407
  this.setPosition = function (lat, lng) {
10408
+ var queued = queueIfNotInitialized(function () {
10409
+ self.setPosition(lat, lng);
10410
+ }, self);
10411
+ if (queued) return;
10412
+
10355
10413
  self._SessionManager.resetSessionTimer();
10356
10414
 
10357
10415
  if (typeof lat === 'number' && typeof lng === 'number') {
@@ -10390,12 +10448,10 @@ var mParticle = (function () {
10390
10448
 
10391
10449
 
10392
10450
  this.logBaseEvent = function (event, eventOptions) {
10393
- if (!self._Store.isInitialized) {
10394
- self.ready(function () {
10395
- self.logBaseEvent(event, eventOptions);
10396
- });
10397
- return;
10398
- }
10451
+ var queued = queueIfNotInitialized(function () {
10452
+ self.logBaseEvent(event, eventOptions);
10453
+ }, self);
10454
+ if (queued) return;
10399
10455
 
10400
10456
  self._SessionManager.resetSessionTimer();
10401
10457
 
@@ -10427,12 +10483,10 @@ var mParticle = (function () {
10427
10483
 
10428
10484
 
10429
10485
  this.logEvent = function (eventName, eventType, eventInfo, customFlags, eventOptions) {
10430
- if (!self._Store.isInitialized) {
10431
- self.ready(function () {
10432
- self.logEvent(eventName, eventType, eventInfo, customFlags, eventOptions);
10433
- });
10434
- return;
10435
- }
10486
+ var queued = queueIfNotInitialized(function () {
10487
+ self.logEvent(eventName, eventType, eventInfo, customFlags, eventOptions);
10488
+ }, self);
10489
+ if (queued) return;
10436
10490
 
10437
10491
  self._SessionManager.resetSessionTimer();
10438
10492
 
@@ -10473,12 +10527,10 @@ var mParticle = (function () {
10473
10527
 
10474
10528
 
10475
10529
  this.logError = function (error, attrs) {
10476
- if (!self._Store.isInitialized) {
10477
- self.ready(function () {
10478
- self.logError(error, attrs);
10479
- });
10480
- return;
10481
- }
10530
+ var queued = queueIfNotInitialized(function () {
10531
+ self.logError(error, attrs);
10532
+ }, self);
10533
+ if (queued) return;
10482
10534
 
10483
10535
  self._SessionManager.resetSessionTimer();
10484
10536
 
@@ -10550,12 +10602,10 @@ var mParticle = (function () {
10550
10602
 
10551
10603
 
10552
10604
  this.logPageView = function (eventName, attrs, customFlags, eventOptions) {
10553
- if (!self._Store.isInitialized) {
10554
- self.ready(function () {
10555
- self.logPageView(eventName, attrs, customFlags, eventOptions);
10556
- });
10557
- return;
10558
- }
10605
+ var queued = queueIfNotInitialized(function () {
10606
+ self.logPageView(eventName, attrs, customFlags, eventOptions);
10607
+ }, self);
10608
+ if (queued) return;
10559
10609
 
10560
10610
  self._SessionManager.resetSessionTimer();
10561
10611
 
@@ -10723,12 +10773,10 @@ var mParticle = (function () {
10723
10773
  * @param {String} code The currency code
10724
10774
  */
10725
10775
  setCurrencyCode: function setCurrencyCode(code) {
10726
- if (!self._Store.isInitialized) {
10727
- self.ready(function () {
10728
- self.eCommerce.setCurrencyCode(code);
10729
- });
10730
- return;
10731
- }
10776
+ var queued = queueIfNotInitialized(function () {
10777
+ self.eCommerce.setCurrencyCode(code);
10778
+ }, self);
10779
+ if (queued) return;
10732
10780
 
10733
10781
  if (typeof code !== 'string') {
10734
10782
  self.Logger.error('Code must be a string');
@@ -10835,12 +10883,10 @@ var mParticle = (function () {
10835
10883
  * @param {Object} [eventOptions] For Event-level Configuration Options
10836
10884
  */
10837
10885
  logProductAction: function logProductAction(productActionType, product, attrs, customFlags, transactionAttributes, eventOptions) {
10838
- if (!self._Store.isInitialized) {
10839
- self.ready(function () {
10840
- self.eCommerce.logProductAction(productActionType, product, attrs, customFlags, transactionAttributes, eventOptions);
10841
- });
10842
- return;
10843
- }
10886
+ var queued = queueIfNotInitialized(function () {
10887
+ self.eCommerce.logProductAction(productActionType, product, attrs, customFlags, transactionAttributes, eventOptions);
10888
+ }, self);
10889
+ if (queued) return;
10844
10890
 
10845
10891
  self._SessionManager.resetSessionTimer();
10846
10892
 
@@ -10889,12 +10935,10 @@ var mParticle = (function () {
10889
10935
  * @param {Object} [eventOptions] For Event-level Configuration Options
10890
10936
  */
10891
10937
  logPromotion: function logPromotion(type, promotion, attrs, customFlags, eventOptions) {
10892
- if (!self._Store.isInitialized) {
10893
- self.ready(function () {
10894
- self.eCommerce.logPromotion(type, promotion, attrs, customFlags, eventOptions);
10895
- });
10896
- return;
10897
- }
10938
+ var queued = queueIfNotInitialized(function () {
10939
+ self.eCommerce.logPromotion(type, promotion, attrs, customFlags, eventOptions);
10940
+ }, self);
10941
+ if (queued) return;
10898
10942
 
10899
10943
  self._SessionManager.resetSessionTimer();
10900
10944
 
@@ -10911,12 +10955,10 @@ var mParticle = (function () {
10911
10955
  * @param {Object} [eventOptions] For Event-level Configuration Options
10912
10956
  */
10913
10957
  logImpression: function logImpression(impression, attrs, customFlags, eventOptions) {
10914
- if (!self._Store.isInitialized) {
10915
- self.ready(function () {
10916
- self.eCommerce.logImpression(impression, attrs, customFlags, eventOptions);
10917
- });
10918
- return;
10919
- }
10958
+ var queued = queueIfNotInitialized(function () {
10959
+ self.eCommerce.logImpression(impression, attrs, customFlags, eventOptions);
10960
+ }, self);
10961
+ if (queued) return;
10920
10962
 
10921
10963
  self._SessionManager.resetSessionTimer();
10922
10964
 
@@ -10960,16 +11002,13 @@ var mParticle = (function () {
10960
11002
  */
10961
11003
 
10962
11004
  this.setSessionAttribute = function (key, value) {
10963
- if (!self._Store.isInitialized) {
10964
- self.ready(function () {
10965
- self.setSessionAttribute(key, value);
10966
- });
10967
- return;
10968
- } // Logs to cookie
11005
+ var queued = queueIfNotInitialized(function () {
11006
+ self.setSessionAttribute(key, value);
11007
+ }, self);
11008
+ if (queued) return; // Logs to cookie
10969
11009
  // And logs to in-memory object
10970
11010
  // Example: mParticle.setSessionAttribute('location', '33431');
10971
11011
 
10972
-
10973
11012
  if (self._Helpers.canLog()) {
10974
11013
  if (!self._Helpers.Validators.isValidAttributeValue(value)) {
10975
11014
  self.Logger.error(Messages$9.ErrorMessages.BadAttribute);
@@ -11009,12 +11048,10 @@ var mParticle = (function () {
11009
11048
 
11010
11049
 
11011
11050
  this.setOptOut = function (isOptingOut) {
11012
- if (!self._Store.isInitialized) {
11013
- self.ready(function () {
11014
- self.setOptOut(isOptingOut);
11015
- });
11016
- return;
11017
- }
11051
+ var queued = queueIfNotInitialized(function () {
11052
+ self.setOptOut(isOptingOut);
11053
+ }, self);
11054
+ if (queued) return;
11018
11055
 
11019
11056
  self._SessionManager.resetSessionTimer();
11020
11057
 
@@ -11052,12 +11089,10 @@ var mParticle = (function () {
11052
11089
 
11053
11090
 
11054
11091
  this.setIntegrationAttribute = function (integrationId, attrs) {
11055
- if (!self._Store.isInitialized) {
11056
- self.ready(function () {
11057
- self.setIntegrationAttribute(integrationId, attrs);
11058
- });
11059
- return;
11060
- }
11092
+ var queued = queueIfNotInitialized(function () {
11093
+ self.setIntegrationAttribute(integrationId, attrs);
11094
+ }, self);
11095
+ if (queued) return;
11061
11096
 
11062
11097
  if (typeof integrationId !== 'number') {
11063
11098
  self.Logger.error('integrationId must be a number');
@@ -11373,6 +11408,17 @@ var mParticle = (function () {
11373
11408
  }
11374
11409
  }
11375
11410
 
11411
+ function queueIfNotInitialized(func, self) {
11412
+ if (!self.isInitialized()) {
11413
+ self.ready(function () {
11414
+ func();
11415
+ });
11416
+ return true;
11417
+ }
11418
+
11419
+ return false;
11420
+ }
11421
+
11376
11422
  var _BatchValidator = /*#__PURE__*/ function () {
11377
11423
  function _BatchValidator() {
11378
11424
  classCallCheck(this, _BatchValidator);
@@ -11506,6 +11552,14 @@ var mParticle = (function () {
11506
11552
  return self.getInstance().getDeviceId();
11507
11553
  };
11508
11554
 
11555
+ this.setDeviceId = function (guid) {
11556
+ return self.getInstance().setDeviceId(guid);
11557
+ };
11558
+
11559
+ this.isInitialized = function () {
11560
+ return self.getInstance().isInitialized();
11561
+ };
11562
+
11509
11563
  this.startNewSession = function () {
11510
11564
  self.getInstance().startNewSession();
11511
11565
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mparticle/web-sdk",
3
- "version": "2.14.0",
3
+ "version": "2.15.0",
4
4
  "description": "mParticle core SDK for web applications",
5
5
  "license": "Apache-2.0",
6
6
  "keywords": [
@@ -84,7 +84,7 @@
84
84
  "cross-env": "^7.0.3",
85
85
  "eslint": "^7.25.0",
86
86
  "eslint-config-prettier": "8.3.0",
87
- "eslint-plugin-prettier": "3.4.0",
87
+ "eslint-plugin-prettier": "3.4.1",
88
88
  "fetch-mock": "^7.5.1",
89
89
  "gts": "^3.1.0",
90
90
  "karma": "^6.3.2",
@@ -144,13 +144,14 @@ export default function cookieSyncManager(mpInstance) {
144
144
  var img = document.createElement('img');
145
145
 
146
146
  mpInstance.Logger.verbose(Messages.InformationMessages.CookieSync);
147
-
147
+ img.onload = function() {
148
+ cookieSyncDates[moduleId.toString()] = new Date().getTime();
149
+ mpInstance._Persistence.saveUserCookieSyncDatesToPersistence(
150
+ mpid,
151
+ cookieSyncDates
152
+ );
153
+ };
148
154
  img.src = url;
149
- cookieSyncDates[moduleId.toString()] = new Date().getTime();
150
- mpInstance._Persistence.saveUserCookieSyncDatesToPersistence(
151
- mpid,
152
- cookieSyncDates
153
- );
154
155
  }
155
156
  };
156
157
  }
package/src/events.js CHANGED
@@ -273,7 +273,9 @@ export default function Events(mpInstance) {
273
273
  );
274
274
  event.PromotionAction = {
275
275
  PromotionActionType: promotionType,
276
- PromotionList: [promotion],
276
+ PromotionList: Array.isArray(promotion)
277
+ ? promotion
278
+ : [promotion],
277
279
  };
278
280
 
279
281
  self.logCommerceEvent(event, attrs, eventOptions);
package/src/forwarders.js CHANGED
@@ -369,12 +369,11 @@ export default function Forwarders(mpInstance, kitBlocker) {
369
369
  mpInstance._Store.activeForwarders[i].userAttributeFilters
370
370
  );
371
371
 
372
- mpInstance.Logger.verbose(
373
- 'Sending message to forwarder: ' +
374
- mpInstance._Store.activeForwarders[i].name
375
- );
376
-
377
372
  if (mpInstance._Store.activeForwarders[i].process) {
373
+ mpInstance.Logger.verbose(
374
+ 'Sending message to forwarder: ' +
375
+ mpInstance._Store.activeForwarders[i].name
376
+ );
378
377
  var result = mpInstance._Store.activeForwarders[i].process(
379
378
  clonedEvent
380
379
  );