@mparticle/web-sdk 2.14.1 → 2.15.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/dist/mparticle.js CHANGED
@@ -719,7 +719,7 @@ var mParticle = (function () {
719
719
  TriggerUploadType: TriggerUploadType
720
720
  };
721
721
 
722
- var version = "2.14.1";
722
+ var version = "2.15.1";
723
723
 
724
724
  var Constants = {
725
725
  sdkVersion: version,
@@ -4448,10 +4448,14 @@ var mParticle = (function () {
4448
4448
  if (mpInstance._Consent.isEnabledForUserConsent(filteringConsentRuleValues, mpInstance.Identity.getCurrentUser())) {
4449
4449
  var img = document.createElement('img');
4450
4450
  mpInstance.Logger.verbose(Messages$2.InformationMessages.CookieSync);
4451
- img.src = url;
4452
- cookieSyncDates[moduleId.toString()] = new Date().getTime();
4453
4451
 
4454
- 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;
4455
4459
  }
4456
4460
  };
4457
4461
  }
@@ -5202,6 +5206,10 @@ var mParticle = (function () {
5202
5206
  this.SDKConfig = createSDKConfig(config); // Set configuration to default settings
5203
5207
 
5204
5208
  if (config) {
5209
+ if (config.deviceId) {
5210
+ this.deviceId = config.deviceId;
5211
+ }
5212
+
5205
5213
  if (config.hasOwnProperty('isDevelopmentMode')) {
5206
5214
  this.SDKConfig.isDevelopmentMode = mpInstance._Helpers.returnConvertedBoolean(config.isDevelopmentMode);
5207
5215
  } else {
@@ -5826,8 +5834,8 @@ var mParticle = (function () {
5826
5834
  for (i = 0, l = cookies.length; i < l; i++) {
5827
5835
  try {
5828
5836
  parts = cookies[i].split('=');
5829
- name = mpInstance._Helpers.decoded(parts.shift());
5830
- cookie = mpInstance._Helpers.decoded(parts.join('='));
5837
+ name = parts.shift();
5838
+ cookie = parts.join('=');
5831
5839
  } catch (e) {
5832
5840
  mpInstance.Logger.verbose('Unable to parse cookie: ' + name + '. Skipping.');
5833
5841
  }
@@ -6406,6 +6414,11 @@ var mParticle = (function () {
6406
6414
  return mpInstance._Store.deviceId;
6407
6415
  };
6408
6416
 
6417
+ this.setDeviceId = function (guid) {
6418
+ mpInstance._Store.deviceId = guid;
6419
+ self.update();
6420
+ };
6421
+
6409
6422
  this.resetPersistence = function () {
6410
6423
  removeLocalStorage(StorageNames$1.localStorageName);
6411
6424
  removeLocalStorage(StorageNames$1.localStorageNameV3);
@@ -6655,7 +6668,16 @@ var mParticle = (function () {
6655
6668
  };
6656
6669
 
6657
6670
  this.logCommerceEvent = function (commerceEvent, attrs, options) {
6658
- mpInstance.Logger.verbose(Messages$6.InformationMessages.StartingLogCommerceEvent);
6671
+ mpInstance.Logger.verbose(Messages$6.InformationMessages.StartingLogCommerceEvent); // If a developer typos the ProductActionType, the event category will be
6672
+ // null, resulting in kit forwarding errors on the server.
6673
+ // The check for `ProductAction` is required to denote that these are
6674
+ // ProductAction events, and not impression or promotions
6675
+
6676
+ if (commerceEvent.ProductAction && commerceEvent.EventCategory === null) {
6677
+ mpInstance.Logger.error('Commerce event not sent. The mParticle.ProductActionType you passed was invalid. Re-check your code.');
6678
+ return;
6679
+ }
6680
+
6659
6681
  attrs = mpInstance._Helpers.sanitizeAttributes(attrs, commerceEvent.EventName);
6660
6682
 
6661
6683
  if (mpInstance._Helpers.canLog()) {
@@ -7263,9 +7285,10 @@ var mParticle = (function () {
7263
7285
  filterUserIdentities(clonedEvent, mpInstance._Store.activeForwarders[i].userIdentityFilters); // Check user attribute filtering rules
7264
7286
 
7265
7287
  clonedEvent.UserAttributes = mpInstance._Helpers.filterUserAttributes(clonedEvent.UserAttributes, mpInstance._Store.activeForwarders[i].userAttributeFilters);
7266
- mpInstance.Logger.verbose('Sending message to forwarder: ' + mpInstance._Store.activeForwarders[i].name);
7267
7288
 
7268
7289
  if (mpInstance._Store.activeForwarders[i].process) {
7290
+ mpInstance.Logger.verbose('Sending message to forwarder: ' + mpInstance._Store.activeForwarders[i].name);
7291
+
7269
7292
  var result = mpInstance._Store.activeForwarders[i].process(clonedEvent);
7270
7293
 
7271
7294
  if (result) {
@@ -10221,10 +10244,14 @@ var mParticle = (function () {
10221
10244
 
10222
10245
 
10223
10246
  this.reset = function (instance) {
10224
- instance._Persistence.resetPersistence();
10247
+ try {
10248
+ instance._Persistence.resetPersistence();
10225
10249
 
10226
- if (instance._Store) {
10227
- delete instance._Store;
10250
+ if (instance._Store) {
10251
+ delete instance._Store;
10252
+ }
10253
+ } catch (error) {
10254
+ console.error('Cannot reset mParticle', error);
10228
10255
  }
10229
10256
  };
10230
10257
 
@@ -10260,7 +10287,7 @@ var mParticle = (function () {
10260
10287
 
10261
10288
 
10262
10289
  this.ready = function (f) {
10263
- if (self._Store.isInitialized && typeof f === 'function') {
10290
+ if (self.isInitialized() && typeof f === 'function') {
10264
10291
  f();
10265
10292
  } else {
10266
10293
  self._preInit.readyQueue.push(f);
@@ -10284,10 +10311,39 @@ var mParticle = (function () {
10284
10311
 
10285
10312
 
10286
10313
  this.setAppVersion = function (version) {
10314
+ var queued = queueIfNotInitialized(function () {
10315
+ self.setAppVersion(version);
10316
+ }, self);
10317
+ if (queued) return;
10287
10318
  self._Store.SDKConfig.appVersion = version;
10288
10319
 
10289
10320
  self._Persistence.update();
10290
10321
  };
10322
+ /**
10323
+ * Sets the device id
10324
+ * @method setDeviceId
10325
+ * @param {String} name device ID (UUIDv4-formatted string)
10326
+ */
10327
+
10328
+
10329
+ this.setDeviceId = function (guid) {
10330
+ var queued = queueIfNotInitialized(function () {
10331
+ self.setDeviceId(guid);
10332
+ }, self);
10333
+ if (queued) return;
10334
+
10335
+ this._Persistence.setDeviceId(guid);
10336
+ };
10337
+ /**
10338
+ * Returns a boolean for whether or not the SDKhas been fully initialized
10339
+ * @method isInitialized
10340
+ * @return {Boolean} a boolean for whether or not the SDK has been fully initialized
10341
+ */
10342
+
10343
+
10344
+ this.isInitialized = function () {
10345
+ return self._Store ? self._Store.isInitialized : false;
10346
+ };
10291
10347
  /**
10292
10348
  * Gets the app name
10293
10349
  * @method getAppName
@@ -10306,6 +10362,10 @@ var mParticle = (function () {
10306
10362
 
10307
10363
 
10308
10364
  this.setAppName = function (name) {
10365
+ var queued = queueIfNotInitialized(function () {
10366
+ self.setAppName(name);
10367
+ }, self);
10368
+ if (queued) return;
10309
10369
  self._Store.SDKConfig.appName = name;
10310
10370
  };
10311
10371
  /**
@@ -10354,6 +10414,11 @@ var mParticle = (function () {
10354
10414
 
10355
10415
 
10356
10416
  this.setPosition = function (lat, lng) {
10417
+ var queued = queueIfNotInitialized(function () {
10418
+ self.setPosition(lat, lng);
10419
+ }, self);
10420
+ if (queued) return;
10421
+
10357
10422
  self._SessionManager.resetSessionTimer();
10358
10423
 
10359
10424
  if (typeof lat === 'number' && typeof lng === 'number') {
@@ -10392,12 +10457,10 @@ var mParticle = (function () {
10392
10457
 
10393
10458
 
10394
10459
  this.logBaseEvent = function (event, eventOptions) {
10395
- if (!self._Store.isInitialized) {
10396
- self.ready(function () {
10397
- self.logBaseEvent(event, eventOptions);
10398
- });
10399
- return;
10400
- }
10460
+ var queued = queueIfNotInitialized(function () {
10461
+ self.logBaseEvent(event, eventOptions);
10462
+ }, self);
10463
+ if (queued) return;
10401
10464
 
10402
10465
  self._SessionManager.resetSessionTimer();
10403
10466
 
@@ -10429,12 +10492,10 @@ var mParticle = (function () {
10429
10492
 
10430
10493
 
10431
10494
  this.logEvent = function (eventName, eventType, eventInfo, customFlags, eventOptions) {
10432
- if (!self._Store.isInitialized) {
10433
- self.ready(function () {
10434
- self.logEvent(eventName, eventType, eventInfo, customFlags, eventOptions);
10435
- });
10436
- return;
10437
- }
10495
+ var queued = queueIfNotInitialized(function () {
10496
+ self.logEvent(eventName, eventType, eventInfo, customFlags, eventOptions);
10497
+ }, self);
10498
+ if (queued) return;
10438
10499
 
10439
10500
  self._SessionManager.resetSessionTimer();
10440
10501
 
@@ -10475,12 +10536,10 @@ var mParticle = (function () {
10475
10536
 
10476
10537
 
10477
10538
  this.logError = function (error, attrs) {
10478
- if (!self._Store.isInitialized) {
10479
- self.ready(function () {
10480
- self.logError(error, attrs);
10481
- });
10482
- return;
10483
- }
10539
+ var queued = queueIfNotInitialized(function () {
10540
+ self.logError(error, attrs);
10541
+ }, self);
10542
+ if (queued) return;
10484
10543
 
10485
10544
  self._SessionManager.resetSessionTimer();
10486
10545
 
@@ -10552,12 +10611,10 @@ var mParticle = (function () {
10552
10611
 
10553
10612
 
10554
10613
  this.logPageView = function (eventName, attrs, customFlags, eventOptions) {
10555
- if (!self._Store.isInitialized) {
10556
- self.ready(function () {
10557
- self.logPageView(eventName, attrs, customFlags, eventOptions);
10558
- });
10559
- return;
10560
- }
10614
+ var queued = queueIfNotInitialized(function () {
10615
+ self.logPageView(eventName, attrs, customFlags, eventOptions);
10616
+ }, self);
10617
+ if (queued) return;
10561
10618
 
10562
10619
  self._SessionManager.resetSessionTimer();
10563
10620
 
@@ -10725,12 +10782,10 @@ var mParticle = (function () {
10725
10782
  * @param {String} code The currency code
10726
10783
  */
10727
10784
  setCurrencyCode: function setCurrencyCode(code) {
10728
- if (!self._Store.isInitialized) {
10729
- self.ready(function () {
10730
- self.eCommerce.setCurrencyCode(code);
10731
- });
10732
- return;
10733
- }
10785
+ var queued = queueIfNotInitialized(function () {
10786
+ self.eCommerce.setCurrencyCode(code);
10787
+ }, self);
10788
+ if (queued) return;
10734
10789
 
10735
10790
  if (typeof code !== 'string') {
10736
10791
  self.Logger.error('Code must be a string');
@@ -10837,12 +10892,10 @@ var mParticle = (function () {
10837
10892
  * @param {Object} [eventOptions] For Event-level Configuration Options
10838
10893
  */
10839
10894
  logProductAction: function logProductAction(productActionType, product, attrs, customFlags, transactionAttributes, eventOptions) {
10840
- if (!self._Store.isInitialized) {
10841
- self.ready(function () {
10842
- self.eCommerce.logProductAction(productActionType, product, attrs, customFlags, transactionAttributes, eventOptions);
10843
- });
10844
- return;
10845
- }
10895
+ var queued = queueIfNotInitialized(function () {
10896
+ self.eCommerce.logProductAction(productActionType, product, attrs, customFlags, transactionAttributes, eventOptions);
10897
+ }, self);
10898
+ if (queued) return;
10846
10899
 
10847
10900
  self._SessionManager.resetSessionTimer();
10848
10901
 
@@ -10891,12 +10944,10 @@ var mParticle = (function () {
10891
10944
  * @param {Object} [eventOptions] For Event-level Configuration Options
10892
10945
  */
10893
10946
  logPromotion: function logPromotion(type, promotion, attrs, customFlags, eventOptions) {
10894
- if (!self._Store.isInitialized) {
10895
- self.ready(function () {
10896
- self.eCommerce.logPromotion(type, promotion, attrs, customFlags, eventOptions);
10897
- });
10898
- return;
10899
- }
10947
+ var queued = queueIfNotInitialized(function () {
10948
+ self.eCommerce.logPromotion(type, promotion, attrs, customFlags, eventOptions);
10949
+ }, self);
10950
+ if (queued) return;
10900
10951
 
10901
10952
  self._SessionManager.resetSessionTimer();
10902
10953
 
@@ -10913,12 +10964,10 @@ var mParticle = (function () {
10913
10964
  * @param {Object} [eventOptions] For Event-level Configuration Options
10914
10965
  */
10915
10966
  logImpression: function logImpression(impression, attrs, customFlags, eventOptions) {
10916
- if (!self._Store.isInitialized) {
10917
- self.ready(function () {
10918
- self.eCommerce.logImpression(impression, attrs, customFlags, eventOptions);
10919
- });
10920
- return;
10921
- }
10967
+ var queued = queueIfNotInitialized(function () {
10968
+ self.eCommerce.logImpression(impression, attrs, customFlags, eventOptions);
10969
+ }, self);
10970
+ if (queued) return;
10922
10971
 
10923
10972
  self._SessionManager.resetSessionTimer();
10924
10973
 
@@ -10962,16 +11011,13 @@ var mParticle = (function () {
10962
11011
  */
10963
11012
 
10964
11013
  this.setSessionAttribute = function (key, value) {
10965
- if (!self._Store.isInitialized) {
10966
- self.ready(function () {
10967
- self.setSessionAttribute(key, value);
10968
- });
10969
- return;
10970
- } // Logs to cookie
11014
+ var queued = queueIfNotInitialized(function () {
11015
+ self.setSessionAttribute(key, value);
11016
+ }, self);
11017
+ if (queued) return; // Logs to cookie
10971
11018
  // And logs to in-memory object
10972
11019
  // Example: mParticle.setSessionAttribute('location', '33431');
10973
11020
 
10974
-
10975
11021
  if (self._Helpers.canLog()) {
10976
11022
  if (!self._Helpers.Validators.isValidAttributeValue(value)) {
10977
11023
  self.Logger.error(Messages$9.ErrorMessages.BadAttribute);
@@ -11011,12 +11057,10 @@ var mParticle = (function () {
11011
11057
 
11012
11058
 
11013
11059
  this.setOptOut = function (isOptingOut) {
11014
- if (!self._Store.isInitialized) {
11015
- self.ready(function () {
11016
- self.setOptOut(isOptingOut);
11017
- });
11018
- return;
11019
- }
11060
+ var queued = queueIfNotInitialized(function () {
11061
+ self.setOptOut(isOptingOut);
11062
+ }, self);
11063
+ if (queued) return;
11020
11064
 
11021
11065
  self._SessionManager.resetSessionTimer();
11022
11066
 
@@ -11054,12 +11098,10 @@ var mParticle = (function () {
11054
11098
 
11055
11099
 
11056
11100
  this.setIntegrationAttribute = function (integrationId, attrs) {
11057
- if (!self._Store.isInitialized) {
11058
- self.ready(function () {
11059
- self.setIntegrationAttribute(integrationId, attrs);
11060
- });
11061
- return;
11062
- }
11101
+ var queued = queueIfNotInitialized(function () {
11102
+ self.setIntegrationAttribute(integrationId, attrs);
11103
+ }, self);
11104
+ if (queued) return;
11063
11105
 
11064
11106
  if (typeof integrationId !== 'number') {
11065
11107
  self.Logger.error('integrationId must be a number');
@@ -11223,7 +11265,11 @@ var mParticle = (function () {
11223
11265
  mpInstance._ForwardingStatsUploader.startForwardingStatsTimer();
11224
11266
  }
11225
11267
 
11226
- mpInstance._Forwarders.processForwarders(config, mpInstance._APIClient.prepareForwardingStats); // Call mParticle._Store.SDKConfig.identityCallback when identify was not called due to a reload or a sessionId already existing
11268
+ mpInstance._Forwarders.processForwarders(config, mpInstance._APIClient.prepareForwardingStats);
11269
+
11270
+ mpInstance._SessionManager.initialize();
11271
+
11272
+ mpInstance._Events.logAST(); // Call mParticle._Store.SDKConfig.identityCallback when identify was not called due to a reload or a sessionId already existing
11227
11273
 
11228
11274
 
11229
11275
  if (!mpInstance._Store.identifyCalled && mpInstance._Store.SDKConfig.identityCallback && currentUser && currentUser.getMPID()) {
@@ -11251,10 +11297,6 @@ var mParticle = (function () {
11251
11297
  }
11252
11298
  });
11253
11299
  }
11254
-
11255
- mpInstance._SessionManager.initialize();
11256
-
11257
- mpInstance._Events.logAST();
11258
11300
  }
11259
11301
 
11260
11302
  mpInstance._Store.isInitialized = true; // Call any functions that are waiting for the library to be initialized
@@ -11375,6 +11417,17 @@ var mParticle = (function () {
11375
11417
  }
11376
11418
  }
11377
11419
 
11420
+ function queueIfNotInitialized(func, self) {
11421
+ if (!self.isInitialized()) {
11422
+ self.ready(function () {
11423
+ func();
11424
+ });
11425
+ return true;
11426
+ }
11427
+
11428
+ return false;
11429
+ }
11430
+
11378
11431
  var _BatchValidator = /*#__PURE__*/ function () {
11379
11432
  function _BatchValidator() {
11380
11433
  classCallCheck(this, _BatchValidator);
@@ -11508,6 +11561,14 @@ var mParticle = (function () {
11508
11561
  return self.getInstance().getDeviceId();
11509
11562
  };
11510
11563
 
11564
+ this.setDeviceId = function (guid) {
11565
+ return self.getInstance().setDeviceId(guid);
11566
+ };
11567
+
11568
+ this.isInitialized = function () {
11569
+ return self.getInstance().isInitialized();
11570
+ };
11571
+
11511
11572
  this.startNewSession = function () {
11512
11573
  self.getInstance().startNewSession();
11513
11574
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mparticle/web-sdk",
3
- "version": "2.14.1",
3
+ "version": "2.15.1",
4
4
  "description": "mParticle core SDK for web applications",
5
5
  "license": "Apache-2.0",
6
6
  "keywords": [
@@ -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
@@ -319,6 +319,20 @@ export default function Events(mpInstance) {
319
319
  Messages.InformationMessages.StartingLogCommerceEvent
320
320
  );
321
321
 
322
+ // If a developer typos the ProductActionType, the event category will be
323
+ // null, resulting in kit forwarding errors on the server.
324
+ // The check for `ProductAction` is required to denote that these are
325
+ // ProductAction events, and not impression or promotions
326
+ if (
327
+ commerceEvent.ProductAction &&
328
+ commerceEvent.EventCategory === null
329
+ ) {
330
+ mpInstance.Logger.error(
331
+ 'Commerce event not sent. The mParticle.ProductActionType you passed was invalid. Re-check your code.'
332
+ );
333
+ return;
334
+ }
335
+
322
336
  attrs = mpInstance._Helpers.sanitizeAttributes(
323
337
  attrs,
324
338
  commerceEvent.EventName
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
  );