@mparticle/web-sdk 2.21.0 → 2.21.2

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
@@ -1,7 +1,7 @@
1
1
  var mParticle = (function () {
2
2
 
3
3
  // Base64 encoder/decoder - http://www.webtoolkit.info/javascript_base64.html
4
- var Base64$2 = {
4
+ var Base64$1 = {
5
5
  _keyStr: 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=',
6
6
  // Input must be a string
7
7
  encode: function encode(input) {
@@ -32,7 +32,7 @@ var mParticle = (function () {
32
32
  } else if (isNaN(chr3)) {
33
33
  enc4 = 64;
34
34
  }
35
- output = output + Base64$2._keyStr.charAt(enc1) + Base64$2._keyStr.charAt(enc2) + Base64$2._keyStr.charAt(enc3) + Base64$2._keyStr.charAt(enc4);
35
+ output = output + Base64$1._keyStr.charAt(enc1) + Base64$1._keyStr.charAt(enc2) + Base64$1._keyStr.charAt(enc3) + Base64$1._keyStr.charAt(enc4);
36
36
  }
37
37
  return output;
38
38
  },
@@ -44,7 +44,7 @@ var mParticle = (function () {
44
44
  } catch (e) {
45
45
  //log(e);
46
46
  }
47
- return Base64$2._decode(input);
47
+ return Base64$1._decode(input);
48
48
  },
49
49
  _decode: function _decode(input) {
50
50
  var output = '';
@@ -53,10 +53,10 @@ var mParticle = (function () {
53
53
  var i = 0;
54
54
  input = input.replace(/[^A-Za-z0-9\+\/\=]/g, '');
55
55
  while (i < input.length) {
56
- enc1 = Base64$2._keyStr.indexOf(input.charAt(i++));
57
- enc2 = Base64$2._keyStr.indexOf(input.charAt(i++));
58
- enc3 = Base64$2._keyStr.indexOf(input.charAt(i++));
59
- enc4 = Base64$2._keyStr.indexOf(input.charAt(i++));
56
+ enc1 = Base64$1._keyStr.indexOf(input.charAt(i++));
57
+ enc2 = Base64$1._keyStr.indexOf(input.charAt(i++));
58
+ enc3 = Base64$1._keyStr.indexOf(input.charAt(i++));
59
+ enc4 = Base64$1._keyStr.indexOf(input.charAt(i++));
60
60
  chr1 = enc1 << 2 | enc2 >> 4;
61
61
  chr2 = (enc2 & 15) << 4 | enc3 >> 2;
62
62
  chr3 = (enc3 & 3) << 6 | enc4;
@@ -200,7 +200,7 @@ var mParticle = (function () {
200
200
  isArray: function isArray(arg) {
201
201
  return Object.prototype.toString.call(arg) === '[object Array]';
202
202
  },
203
- Base64: Base64$2
203
+ Base64: Base64$1
204
204
  };
205
205
 
206
206
  function _defineProperty(obj, key, value) {
@@ -582,7 +582,7 @@ var mParticle = (function () {
582
582
  Environment: Environment
583
583
  };
584
584
 
585
- var version = "2.21.0";
585
+ var version = "2.21.2";
586
586
 
587
587
  var Constants = {
588
588
  sdkVersion: version,
@@ -730,7 +730,6 @@ var mParticle = (function () {
730
730
  },
731
731
  FeatureFlags: {
732
732
  ReportBatching: 'reportBatching',
733
- EventsV3: 'eventsV3',
734
733
  EventBatchingIntervalMillis: 'eventBatchingIntervalMillis',
735
734
  OfflineStorage: 'offlineStorage'
736
735
  },
@@ -1167,6 +1166,12 @@ var mParticle = (function () {
1167
1166
 
1168
1167
  var slugify = slugify$1.exports;
1169
1168
 
1169
+ var createCookieString = function createCookieString(value) {
1170
+ return replaceCommasWithPipes(replaceQuotesWithApostrophes(value));
1171
+ };
1172
+ var revertCookieString = function revertCookieString(value) {
1173
+ return replacePipesWithCommas(replaceApostrophesWithQuotes(value));
1174
+ };
1170
1175
  var inArray = function inArray(items, name) {
1171
1176
  var i = 0;
1172
1177
  if (Array.prototype.indexOf) {
@@ -1274,6 +1279,18 @@ var mParticle = (function () {
1274
1279
  return null;
1275
1280
  }
1276
1281
  };
1282
+ var replaceCommasWithPipes = function replaceCommasWithPipes(value) {
1283
+ return value.replace(/,/g, '|');
1284
+ };
1285
+ var replacePipesWithCommas = function replacePipesWithCommas(value) {
1286
+ return value.replace(/\|/g, ',');
1287
+ };
1288
+ var replaceApostrophesWithQuotes = function replaceApostrophesWithQuotes(value) {
1289
+ return value.replace(/\'/g, '"');
1290
+ };
1291
+ var replaceQuotesWithApostrophes = function replaceQuotesWithApostrophes(value) {
1292
+ return value.replace(/\"/g, "'");
1293
+ };
1277
1294
  // FIXME: REFACTOR for V3
1278
1295
  // only used in store.js to sanitize server-side formatting of
1279
1296
  // booleans when checking for `isDevelopmentMode`
@@ -2373,7 +2390,6 @@ var mParticle = (function () {
2373
2390
  return XHRUploader;
2374
2391
  }(AsyncUploader);
2375
2392
 
2376
- var Messages$9 = Constants.Messages;
2377
2393
  function APIClient(mpInstance, kitBlocker) {
2378
2394
  this.uploader = null;
2379
2395
  var self = this;
@@ -2385,16 +2401,6 @@ var mParticle = (function () {
2385
2401
  this.uploader.queueEvent(event);
2386
2402
  mpInstance._Persistence.update();
2387
2403
  };
2388
- this.shouldEnableBatching = function () {
2389
- // Returns a string of a number that must be parsed
2390
- // Invalid strings will be parsed to NaN which is falsey
2391
- var eventsV3Percentage = parseInt(mpInstance._Helpers.getFeatureFlag(Constants.FeatureFlags.EventsV3), 10);
2392
- if (!eventsV3Percentage) {
2393
- return false;
2394
- }
2395
- var rampNumber = getRampNumber(mpInstance._Store.deviceId);
2396
- return eventsV3Percentage >= rampNumber;
2397
- };
2398
2404
  this.processQueuedEvents = function () {
2399
2405
  var mpid,
2400
2406
  currentUser = mpInstance.Identity.getCurrentUser();
@@ -2440,14 +2446,13 @@ var mParticle = (function () {
2440
2446
  return;
2441
2447
  }
2442
2448
  this.processQueuedEvents();
2443
- if (event && options.shouldUploadEvent) {
2444
- if (this.shouldEnableBatching()) {
2445
- this.queueEventForBatchUpload(event);
2446
- } else {
2447
- this.sendSingleEventToServer(event);
2448
- }
2449
+ if (isEmpty(event)) {
2450
+ return;
2449
2451
  }
2450
- if (event && event.EventName !== Types.MessageType.AppStateTransition) {
2452
+ if (options.shouldUploadEvent) {
2453
+ this.queueEventForBatchUpload(event);
2454
+ }
2455
+ if (event.EventName !== Types.MessageType.AppStateTransition) {
2451
2456
  if (kitBlocker && kitBlocker.kitBlockingEnabled) {
2452
2457
  event = kitBlocker.createBlockedEvent(event);
2453
2458
  }
@@ -2458,32 +2463,6 @@ var mParticle = (function () {
2458
2463
  }
2459
2464
  }
2460
2465
  };
2461
- this.sendSingleEventToServer = function (event) {
2462
- if (event.EventDataType === Types.MessageType.Media) {
2463
- return;
2464
- }
2465
- var xhr,
2466
- xhrCallback = function xhrCallback() {
2467
- if (xhr.readyState === 4) {
2468
- mpInstance.Logger.verbose('Received ' + xhr.statusText + ' from server');
2469
- mpInstance._Persistence.update();
2470
- }
2471
- };
2472
- if (!event) {
2473
- mpInstance.Logger.error(Messages$9.ErrorMessages.EventEmpty);
2474
- return;
2475
- }
2476
- mpInstance.Logger.verbose(Messages$9.InformationMessages.SendHttp);
2477
- xhr = mpInstance._Helpers.createXHR(xhrCallback);
2478
- if (xhr) {
2479
- try {
2480
- xhr.open('post', mpInstance._Helpers.createServiceUrl(mpInstance._Store.SDKConfig.v2SecureServiceUrl, mpInstance._Store.devToken) + '/Events');
2481
- xhr.send(JSON.stringify(mpInstance._ServerModel.convertEventToV2DTO(event)));
2482
- } catch (e) {
2483
- mpInstance.Logger.error('Error sending event to mParticle servers. ' + e);
2484
- }
2485
- }
2486
- };
2487
2466
  this.sendBatchForwardingStatsToServer = function (forwardingStatsData, xhr) {
2488
2467
  var url;
2489
2468
  var data;
@@ -2640,7 +2619,7 @@ var mParticle = (function () {
2640
2619
  }
2641
2620
  };
2642
2621
 
2643
- var StorageNames$2 = Constants.StorageNames;
2622
+ var StorageNames$1 = Constants.StorageNames;
2644
2623
  function Helpers(mpInstance) {
2645
2624
  var self = this;
2646
2625
  this.canLog = function () {
@@ -2936,16 +2915,16 @@ var mParticle = (function () {
2936
2915
  };
2937
2916
  this.createMainStorageName = function (workspaceToken) {
2938
2917
  if (workspaceToken) {
2939
- return StorageNames$2.currentStorageName + '_' + workspaceToken;
2918
+ return StorageNames$1.currentStorageName + '_' + workspaceToken;
2940
2919
  } else {
2941
- return StorageNames$2.currentStorageName;
2920
+ return StorageNames$1.currentStorageName;
2942
2921
  }
2943
2922
  };
2944
2923
  this.createProductStorageName = function (workspaceToken) {
2945
2924
  if (workspaceToken) {
2946
- return StorageNames$2.currentStorageProductsName + '_' + workspaceToken;
2925
+ return StorageNames$1.currentStorageProductsName + '_' + workspaceToken;
2947
2926
  } else {
2948
- return StorageNames$2.currentStorageProductsName;
2927
+ return StorageNames$1.currentStorageProductsName;
2949
2928
  }
2950
2929
  };
2951
2930
 
@@ -3763,7 +3742,6 @@ var mParticle = (function () {
3763
3742
  clientId: null,
3764
3743
  deviceId: null,
3765
3744
  devToken: null,
3766
- migrationData: {},
3767
3745
  serverSettings: {},
3768
3746
  dateLastEventSent: null,
3769
3747
  sessionStartDate: null,
@@ -3778,7 +3756,6 @@ var mParticle = (function () {
3778
3756
  configurationLoaded: false,
3779
3757
  identityCallInFlight: false,
3780
3758
  SDKConfig: {},
3781
- migratingToIDSyncCookies: false,
3782
3759
  nonCurrentUserMPIDs: {},
3783
3760
  identifyCalled: false,
3784
3761
  isLoggedIn: false,
@@ -3947,9 +3924,6 @@ var mParticle = (function () {
3947
3924
  if (!config.hasOwnProperty('flags')) {
3948
3925
  this.SDKConfig.flags = {};
3949
3926
  }
3950
- if (!this.SDKConfig.flags.hasOwnProperty(Constants.FeatureFlags.EventsV3)) {
3951
- this.SDKConfig.flags[Constants.FeatureFlags.EventsV3] = 0;
3952
- }
3953
3927
  if (!this.SDKConfig.flags.hasOwnProperty(Constants.FeatureFlags.EventBatchingIntervalMillis)) {
3954
3928
  this.SDKConfig.flags[Constants.FeatureFlags.EventBatchingIntervalMillis] = Constants.DefaultConfig.uploadInterval;
3955
3929
  }
@@ -4013,11 +3987,11 @@ var mParticle = (function () {
4013
3987
  };
4014
3988
  }
4015
3989
 
4016
- var Base64$1 = Polyfill.Base64,
3990
+ var Base64 = Polyfill.Base64,
4017
3991
  Messages$4 = Constants.Messages,
4018
3992
  Base64CookieKeys = Constants.Base64CookieKeys,
4019
3993
  SDKv2NonMPIDCookieKeys = Constants.SDKv2NonMPIDCookieKeys,
4020
- StorageNames$1 = Constants.StorageNames;
3994
+ StorageNames = Constants.StorageNames;
4021
3995
  function _Persistence(mpInstance) {
4022
3996
  var self = this;
4023
3997
  this.useLocalStorage = function () {
@@ -4078,7 +4052,7 @@ var mParticle = (function () {
4078
4052
  if (mpInstance._Store.isLocalStorageAvailable) {
4079
4053
  var encodedProducts = localStorage.getItem(mpInstance._Store.prodStorageName);
4080
4054
  if (encodedProducts) {
4081
- var decodedProducts = JSON.parse(Base64$1.decode(encodedProducts));
4055
+ var decodedProducts = JSON.parse(Base64.decode(encodedProducts));
4082
4056
  }
4083
4057
  if (mpInstance._Store.mpid) {
4084
4058
  self.storeProductsInMemory(decodedProducts, mpInstance._Store.mpid);
@@ -4192,7 +4166,7 @@ var mParticle = (function () {
4192
4166
  parsedProducts,
4193
4167
  encodedProducts = localStorage.getItem(mpInstance._Store.prodStorageName);
4194
4168
  if (encodedProducts) {
4195
- decodedProducts = Base64$1.decode(encodedProducts);
4169
+ decodedProducts = Base64.decode(encodedProducts);
4196
4170
  }
4197
4171
  // if there is an MPID, we are retrieving the user's products, which is an array
4198
4172
  if (mpid) {
@@ -4218,7 +4192,7 @@ var mParticle = (function () {
4218
4192
  encodedProducts = localStorage.getItem(mpInstance._Store.prodStorageName),
4219
4193
  parsedDecodedProducts;
4220
4194
  if (encodedProducts) {
4221
- decodedProducts = Base64$1.decode(encodedProducts);
4195
+ decodedProducts = Base64.decode(encodedProducts);
4222
4196
  }
4223
4197
  // returns an object with keys of MPID and values of array of products
4224
4198
  try {
@@ -4244,7 +4218,7 @@ var mParticle = (function () {
4244
4218
  allLocalStorageProducts = allLocalStorageProducts || {};
4245
4219
  allLocalStorageProducts[mpid] = currentUserProducts;
4246
4220
  try {
4247
- window.localStorage.setItem(encodeURIComponent(mpInstance._Store.prodStorageName), Base64$1.encode(JSON.stringify(allLocalStorageProducts)));
4221
+ window.localStorage.setItem(encodeURIComponent(mpInstance._Store.prodStorageName), Base64.encode(JSON.stringify(allLocalStorageProducts)));
4248
4222
  } catch (e) {
4249
4223
  mpInstance.Logger.error('Error with setting products on localStorage.');
4250
4224
  }
@@ -4502,7 +4476,7 @@ var mParticle = (function () {
4502
4476
  if (persistence.gs[key]) {
4503
4477
  // base64 encode any value that is an object or Array in globalSettings
4504
4478
  if (Array.isArray(persistence.gs[key]) && persistence.gs[key].length || mpInstance._Helpers.isObject(persistence.gs[key]) && Object.keys(persistence.gs[key]).length) {
4505
- persistence.gs[key] = Base64$1.encode(JSON.stringify(persistence.gs[key]));
4479
+ persistence.gs[key] = Base64.encode(JSON.stringify(persistence.gs[key]));
4506
4480
  } else {
4507
4481
  delete persistence.gs[key];
4508
4482
  }
@@ -4523,7 +4497,7 @@ var mParticle = (function () {
4523
4497
  if (persistence[mpid].hasOwnProperty(key)) {
4524
4498
  if (Base64CookieKeys[key]) {
4525
4499
  if (mpInstance._Helpers.isObject(persistence[mpid][key]) && Object.keys(persistence[mpid][key]).length) {
4526
- persistence[mpid][key] = Base64$1.encode(JSON.stringify(persistence[mpid][key]));
4500
+ persistence[mpid][key] = Base64.encode(JSON.stringify(persistence[mpid][key]));
4527
4501
  } else {
4528
4502
  delete persistence[mpid][key];
4529
4503
  }
@@ -4533,17 +4507,20 @@ var mParticle = (function () {
4533
4507
  }
4534
4508
  }
4535
4509
  }
4536
- return self.createCookieString(JSON.stringify(persistence));
4510
+ return createCookieString(JSON.stringify(persistence));
4537
4511
  };
4512
+
4513
+ // TODO: This should actually be decodePersistenceString or
4514
+ // we should refactor this to take a string and return an object
4538
4515
  this.decodePersistence = function (persistence) {
4539
4516
  try {
4540
4517
  if (persistence) {
4541
- persistence = JSON.parse(self.revertCookieString(persistence));
4518
+ persistence = JSON.parse(revertCookieString(persistence));
4542
4519
  if (mpInstance._Helpers.isObject(persistence) && Object.keys(persistence).length) {
4543
4520
  for (var key in persistence.gs) {
4544
4521
  if (persistence.gs.hasOwnProperty(key)) {
4545
4522
  if (Base64CookieKeys[key]) {
4546
- persistence.gs[key] = JSON.parse(Base64$1.decode(persistence.gs[key]));
4523
+ persistence.gs[key] = JSON.parse(Base64.decode(persistence.gs[key]));
4547
4524
  } else if (key === 'ie') {
4548
4525
  persistence.gs[key] = Boolean(persistence.gs[key]);
4549
4526
  }
@@ -4556,7 +4533,7 @@ var mParticle = (function () {
4556
4533
  if (persistence[mpid].hasOwnProperty(key)) {
4557
4534
  if (Base64CookieKeys[key]) {
4558
4535
  if (persistence[mpid][key].length) {
4559
- persistence[mpid][key] = JSON.parse(Base64$1.decode(persistence[mpid][key]));
4536
+ persistence[mpid][key] = JSON.parse(Base64.decode(persistence[mpid][key]));
4560
4537
  }
4561
4538
  }
4562
4539
  }
@@ -4573,24 +4550,6 @@ var mParticle = (function () {
4573
4550
  mpInstance.Logger.error('Problem with decoding cookie', e);
4574
4551
  }
4575
4552
  };
4576
- this.replaceCommasWithPipes = function (string) {
4577
- return string.replace(/,/g, '|');
4578
- };
4579
- this.replacePipesWithCommas = function (string) {
4580
- return string.replace(/\|/g, ',');
4581
- };
4582
- this.replaceApostrophesWithQuotes = function (string) {
4583
- return string.replace(/\'/g, '"');
4584
- };
4585
- this.replaceQuotesWithApostrophes = function (string) {
4586
- return string.replace(/\"/g, "'");
4587
- };
4588
- this.createCookieString = function (string) {
4589
- return self.replaceCommasWithPipes(self.replaceQuotesWithApostrophes(string));
4590
- };
4591
- this.revertCookieString = function (string) {
4592
- return self.replacePipesWithCommas(self.replaceApostrophesWithQuotes(string));
4593
- };
4594
4553
  this.getCookieDomain = function () {
4595
4554
  if (mpInstance._Store.SDKConfig.cookieDomain) {
4596
4555
  return mpInstance._Store.SDKConfig.cookieDomain;
@@ -4644,7 +4603,7 @@ var mParticle = (function () {
4644
4603
  var allCartProducts,
4645
4604
  cartProductsString = localStorage.getItem(mpInstance._Store.prodStorageName);
4646
4605
  if (cartProductsString) {
4647
- allCartProducts = JSON.parse(Base64$1.decode(cartProductsString));
4606
+ allCartProducts = JSON.parse(Base64.decode(cartProductsString));
4648
4607
  if (allCartProducts && allCartProducts[mpid] && allCartProducts[mpid].cp) {
4649
4608
  return allCartProducts[mpid].cp;
4650
4609
  }
@@ -4656,7 +4615,7 @@ var mParticle = (function () {
4656
4615
  return;
4657
4616
  }
4658
4617
  try {
4659
- window.localStorage.setItem(encodeURIComponent(mpInstance._Store.prodStorageName), Base64$1.encode(JSON.stringify(allProducts)));
4618
+ window.localStorage.setItem(encodeURIComponent(mpInstance._Store.prodStorageName), Base64.encode(JSON.stringify(allProducts)));
4660
4619
  } catch (e) {
4661
4620
  mpInstance.Logger.error('Error with setting products on localStorage.');
4662
4621
  }
@@ -4835,16 +4794,16 @@ var mParticle = (function () {
4835
4794
  self.update();
4836
4795
  };
4837
4796
  this.resetPersistence = function () {
4838
- removeLocalStorage(StorageNames$1.localStorageName);
4839
- removeLocalStorage(StorageNames$1.localStorageNameV3);
4840
- removeLocalStorage(StorageNames$1.localStorageNameV4);
4797
+ removeLocalStorage(StorageNames.localStorageName);
4798
+ removeLocalStorage(StorageNames.localStorageNameV3);
4799
+ removeLocalStorage(StorageNames.localStorageNameV4);
4841
4800
  removeLocalStorage(mpInstance._Store.prodStorageName);
4842
4801
  removeLocalStorage(mpInstance._Store.storageName);
4843
- removeLocalStorage(StorageNames$1.localStorageProductsV4);
4844
- self.expireCookies(StorageNames$1.cookieName);
4845
- self.expireCookies(StorageNames$1.cookieNameV2);
4846
- self.expireCookies(StorageNames$1.cookieNameV3);
4847
- self.expireCookies(StorageNames$1.cookieNameV4);
4802
+ removeLocalStorage(StorageNames.localStorageProductsV4);
4803
+ self.expireCookies(StorageNames.cookieName);
4804
+ self.expireCookies(StorageNames.cookieNameV2);
4805
+ self.expireCookies(StorageNames.cookieNameV3);
4806
+ self.expireCookies(StorageNames.cookieNameV4);
4848
4807
  self.expireCookies(mpInstance._Store.prodStorageName);
4849
4808
  self.expireCookies(mpInstance._Store.storageName);
4850
4809
  if (mParticle._isTestEnv) {
@@ -5130,208 +5089,6 @@ var mParticle = (function () {
5130
5089
  };
5131
5090
  }
5132
5091
 
5133
- var StorageNames = Constants.StorageNames,
5134
- Base64 = Polyfill.Base64,
5135
- CookiesGlobalSettingsKeys = {
5136
- das: 1
5137
- },
5138
- MPIDKeys = {
5139
- ui: 1
5140
- };
5141
- function Migrations(mpInstance) {
5142
- var self = this;
5143
- // if there is a cookie or localStorage:
5144
- // 1. determine which version it is ('mprtcl-api', 'mprtcl-v2', 'mprtcl-v3', 'mprtcl-v4')
5145
- // 2. return if 'mprtcl-v4', otherwise migrate to mprtclv4 schema
5146
- // 3. if 'mprtcl-api', could be JSSDKv2 or JSSDKv1. JSSDKv2 cookie has a 'globalSettings' key on it
5147
- this.migrate = function () {
5148
- try {
5149
- migrateCookies();
5150
- } catch (e) {
5151
- mpInstance._Persistence.expireCookies(StorageNames.cookieNameV3);
5152
- mpInstance._Persistence.expireCookies(StorageNames.cookieNameV4);
5153
- mpInstance.Logger.error('Error migrating cookie: ' + e);
5154
- }
5155
- if (mpInstance._Store.isLocalStorageAvailable) {
5156
- try {
5157
- migrateLocalStorage();
5158
- } catch (e) {
5159
- localStorage.removeItem(StorageNames.localStorageNameV3);
5160
- localStorage.removeItem(StorageNames.localStorageNameV4);
5161
- mpInstance.Logger.error('Error migrating localStorage: ' + e);
5162
- }
5163
- }
5164
- };
5165
- function migrateCookies() {
5166
- var cookies = window.document.cookie.split('; '),
5167
- foundCookie,
5168
- i,
5169
- l,
5170
- parts,
5171
- name,
5172
- cookie;
5173
- mpInstance.Logger.verbose(Constants.Messages.InformationMessages.CookieSearch);
5174
- for (i = 0, l = cookies.length; i < l; i++) {
5175
- try {
5176
- parts = cookies[i].split('=');
5177
- name = mpInstance._Helpers.decoded(parts.shift());
5178
- cookie = mpInstance._Helpers.decoded(parts.join('='));
5179
- } catch (e) {
5180
- mpInstance.Logger.verbose('Unable to parse cookie: ' + name + '. Skipping.');
5181
- }
5182
-
5183
- //most recent version needs no migration
5184
- if (name === mpInstance._Store.storageName) {
5185
- return;
5186
- }
5187
- if (name === StorageNames.cookieNameV4) {
5188
- // adds cookies to new namespace, removes previous cookie
5189
- finishCookieMigration(cookie, StorageNames.cookieNameV4);
5190
- if (mpInstance._Store.isLocalStorageAvailable) {
5191
- migrateProductsToNameSpace();
5192
- }
5193
- return;
5194
- // migration path for SDKv1CookiesV3, doesn't need to be encoded
5195
- }
5196
-
5197
- if (name === StorageNames.cookieNameV3) {
5198
- foundCookie = self.convertSDKv1CookiesV3ToSDKv2CookiesV4(cookie);
5199
- finishCookieMigration(foundCookie, StorageNames.cookieNameV3);
5200
- break;
5201
- }
5202
- }
5203
- }
5204
- function finishCookieMigration(cookie, cookieName) {
5205
- var date = new Date(),
5206
- cookieDomain = mpInstance._Persistence.getCookieDomain(),
5207
- expires,
5208
- domain;
5209
- expires = new Date(date.getTime() + StorageNames.CookieExpiration * 24 * 60 * 60 * 1000).toGMTString();
5210
- if (cookieDomain === '') {
5211
- domain = '';
5212
- } else {
5213
- domain = ';domain=' + cookieDomain;
5214
- }
5215
- mpInstance.Logger.verbose(Constants.Messages.InformationMessages.CookieSet);
5216
- window.document.cookie = encodeURIComponent(mpInstance._Store.storageName) + '=' + cookie + ';expires=' + expires + ';path=/' + domain;
5217
- mpInstance._Persistence.expireCookies(cookieName);
5218
- mpInstance._Store.migratingToIDSyncCookies = true;
5219
- }
5220
- this.convertSDKv1CookiesV3ToSDKv2CookiesV4 = function (SDKv1CookiesV3) {
5221
- SDKv1CookiesV3 = mpInstance._Persistence.replacePipesWithCommas(mpInstance._Persistence.replaceApostrophesWithQuotes(SDKv1CookiesV3));
5222
- var parsedSDKv1CookiesV3 = JSON.parse(SDKv1CookiesV3);
5223
- var parsedCookiesV4 = JSON.parse(restructureToV4Cookie(SDKv1CookiesV3));
5224
- if (parsedSDKv1CookiesV3.mpid) {
5225
- parsedCookiesV4.gs.csm.push(parsedSDKv1CookiesV3.mpid);
5226
- // all other values are already encoded, so we have to encode any new values
5227
- parsedCookiesV4.gs.csm = Base64.encode(JSON.stringify(parsedCookiesV4.gs.csm));
5228
- migrateProductsFromSDKv1ToSDKv2CookiesV4(parsedSDKv1CookiesV3, parsedSDKv1CookiesV3.mpid);
5229
- }
5230
- return JSON.stringify(parsedCookiesV4);
5231
- };
5232
- function restructureToV4Cookie(cookies) {
5233
- try {
5234
- var cookiesV4Schema = {
5235
- gs: {
5236
- csm: []
5237
- }
5238
- };
5239
- cookies = JSON.parse(cookies);
5240
- for (var key in cookies) {
5241
- if (cookies.hasOwnProperty(key)) {
5242
- if (CookiesGlobalSettingsKeys[key]) {
5243
- cookiesV4Schema.gs[key] = cookies[key];
5244
- } else if (key === 'mpid') {
5245
- cookiesV4Schema.cu = cookies[key];
5246
- } else if (cookies.mpid) {
5247
- cookiesV4Schema[cookies.mpid] = cookiesV4Schema[cookies.mpid] || {};
5248
- if (MPIDKeys[key]) {
5249
- cookiesV4Schema[cookies.mpid][key] = cookies[key];
5250
- }
5251
- }
5252
- }
5253
- }
5254
- return JSON.stringify(cookiesV4Schema);
5255
- } catch (e) {
5256
- mpInstance.Logger.error('Failed to restructure previous cookie into most current cookie schema');
5257
- }
5258
- }
5259
- function migrateProductsToNameSpace() {
5260
- var lsProdV4Name = StorageNames.localStorageProductsV4;
5261
- var products = localStorage.getItem(StorageNames.localStorageProductsV4);
5262
- localStorage.setItem(mpInstance._Store.prodStorageName, products);
5263
- localStorage.removeItem(lsProdV4Name);
5264
- }
5265
- function migrateProductsFromSDKv1ToSDKv2CookiesV4(cookies, mpid) {
5266
- if (!mpInstance._Store.isLocalStorageAvailable) {
5267
- return;
5268
- }
5269
- var localStorageProducts = {};
5270
- localStorageProducts[mpid] = {};
5271
- if (cookies.cp) {
5272
- try {
5273
- localStorageProducts[mpid].cp = JSON.parse(Base64.decode(cookies.cp));
5274
- } catch (e) {
5275
- localStorageProducts[mpid].cp = cookies.cp;
5276
- }
5277
- if (!Array.isArray(localStorageProducts[mpid].cp)) {
5278
- localStorageProducts[mpid].cp = [];
5279
- }
5280
- }
5281
- localStorage.setItem(mpInstance._Store.prodStorageName, Base64.encode(JSON.stringify(localStorageProducts)));
5282
- }
5283
- function migrateLocalStorage() {
5284
- var cookies,
5285
- v3LSName = StorageNames.localStorageNameV3,
5286
- v4LSName = StorageNames.localStorageNameV4,
5287
- currentVersionLSData = window.localStorage.getItem(mpInstance._Store.storageName),
5288
- v4LSData,
5289
- v3LSData,
5290
- v3LSDataStringCopy;
5291
- if (currentVersionLSData) {
5292
- return;
5293
- }
5294
- v4LSData = window.localStorage.getItem(v4LSName);
5295
- if (v4LSData) {
5296
- finishLSMigration(v4LSData, v4LSName);
5297
- migrateProductsToNameSpace();
5298
- return;
5299
- }
5300
- v3LSData = window.localStorage.getItem(v3LSName);
5301
- if (v3LSData) {
5302
- mpInstance._Store.migratingToIDSyncCookies = true;
5303
- v3LSDataStringCopy = v3LSData.slice();
5304
- v3LSData = JSON.parse(mpInstance._Persistence.replacePipesWithCommas(mpInstance._Persistence.replaceApostrophesWithQuotes(v3LSData)));
5305
- // localStorage may contain only products, or the full persistence
5306
- // when there is an MPID on the cookie, it is the full persistence
5307
- if (v3LSData.mpid) {
5308
- v3LSData = JSON.parse(self.convertSDKv1CookiesV3ToSDKv2CookiesV4(v3LSDataStringCopy));
5309
- finishLSMigration(JSON.stringify(v3LSData), v3LSName);
5310
- return;
5311
- // if no MPID, it is only the products
5312
- } else if ((v3LSData.cp || v3LSData.pb) && !v3LSData.mpid) {
5313
- cookies = mpInstance._Persistence.getCookie();
5314
- if (cookies) {
5315
- migrateProductsFromSDKv1ToSDKv2CookiesV4(v3LSData, cookies.cu);
5316
- localStorage.removeItem(StorageNames.localStorageNameV3);
5317
- return;
5318
- } else {
5319
- localStorage.removeItem(StorageNames.localStorageNameV3);
5320
- return;
5321
- }
5322
- }
5323
- }
5324
- function finishLSMigration(data, lsName) {
5325
- try {
5326
- window.localStorage.setItem(encodeURIComponent(mpInstance._Store.storageName), data);
5327
- } catch (e) {
5328
- mpInstance.Logger.error('Error with setting localStorage item.');
5329
- }
5330
- window.localStorage.removeItem(encodeURIComponent(lsName));
5331
- }
5332
- }
5333
- }
5334
-
5335
5092
  function filteredMparticleUser(mpid, forwarder, mpInstance, kitBlocker) {
5336
5093
  var self = this;
5337
5094
  return {
@@ -6818,25 +6575,24 @@ var mParticle = (function () {
6818
6575
  cookies[mpid].ua = userAttributes;
6819
6576
  mpInstance._Persistence.savePersistence(cookies, mpid);
6820
6577
  }
6821
- if (mpInstance._APIClient.shouldEnableBatching()) {
6822
- // If the new attributeList length is different previous, then there is a change event.
6823
- // Loop through new attributes list, see if they are all in the same index as previous user attributes list
6824
- // If there are any changes, break, and immediately send a userAttributeChangeEvent with full array as a value
6825
- if (!previousUserAttributeValue || !Array.isArray(previousUserAttributeValue)) {
6826
- userAttributeChange = true;
6827
- } else if (newValue.length !== previousUserAttributeValue.length) {
6828
- userAttributeChange = true;
6829
- } else {
6830
- for (var i = 0; i < newValue.length; i++) {
6831
- if (previousUserAttributeValue[i] !== newValue[i]) {
6832
- userAttributeChange = true;
6833
- break;
6834
- }
6578
+
6579
+ // If the new attributeList length is different previous, then there is a change event.
6580
+ // Loop through new attributes list, see if they are all in the same index as previous user attributes list
6581
+ // If there are any changes, break, and immediately send a userAttributeChangeEvent with full array as a value
6582
+ if (!previousUserAttributeValue || !Array.isArray(previousUserAttributeValue)) {
6583
+ userAttributeChange = true;
6584
+ } else if (newValue.length !== previousUserAttributeValue.length) {
6585
+ userAttributeChange = true;
6586
+ } else {
6587
+ for (var i = 0; i < newValue.length; i++) {
6588
+ if (previousUserAttributeValue[i] !== newValue[i]) {
6589
+ userAttributeChange = true;
6590
+ break;
6835
6591
  }
6836
6592
  }
6837
- if (userAttributeChange) {
6838
- self.sendUserAttributeChangeEvent(key, newValue, previousUserAttributeValue, isNewAttribute, false, this);
6839
- }
6593
+ }
6594
+ if (userAttributeChange) {
6595
+ self.sendUserAttributeChangeEvent(key, newValue, previousUserAttributeValue, isNewAttribute, false, this);
6840
6596
  }
6841
6597
  mpInstance._Forwarders.initForwarders(self.IdentityAPI.getCurrentUser().getUserIdentities(), mpInstance._APIClient.prepareForwardingStats);
6842
6598
  mpInstance._Forwarders.handleForwarderUserAttributes('setUserAttribute', key, arrayCopy);
@@ -7111,16 +6867,8 @@ var mParticle = (function () {
7111
6867
  }
7112
6868
  mpInstance._CookieSyncManager.attemptCookieSync(previousMPID, identityApiResult.mpid, mpidIsNotInCookies);
7113
6869
  self.checkIdentitySwap(previousMPID, identityApiResult.mpid, mpInstance._Store.currentSessionMPIDs);
7114
-
7115
- //if there is any previous migration data
7116
- if (Object.keys(mpInstance._Store.migrationData).length) {
7117
- newIdentitiesByType = mpInstance._Store.migrationData.userIdentities || {};
7118
- var userAttributes = mpInstance._Store.migrationData.userAttributes || {};
7119
- mpInstance._Persistence.saveUserAttributesToPersistence(identityApiResult.mpid, userAttributes);
7120
- } else {
7121
- if (identityApiData && identityApiData.userIdentities && Object.keys(identityApiData.userIdentities).length) {
7122
- newIdentitiesByType = self.IdentityRequest.combineUserIdentities(incomingMpidUIByName, identityApiData.userIdentities);
7123
- }
6870
+ if (identityApiData && identityApiData.userIdentities && Object.keys(identityApiData.userIdentities).length) {
6871
+ newIdentitiesByType = self.IdentityRequest.combineUserIdentities(incomingMpidUIByName, identityApiData.userIdentities);
7124
6872
  }
7125
6873
  mpInstance._Persistence.saveUserIdentitiesToPersistence(identityApiResult.mpid, newIdentitiesByType);
7126
6874
  mpInstance._Persistence.update();
@@ -7178,9 +6926,6 @@ var mParticle = (function () {
7178
6926
 
7179
6927
  this.sendUserIdentityChangeEvent = function (newUserIdentities, method, mpid, prevUserIdentities) {
7180
6928
  var currentUserInMemory, userIdentityChangeEvent;
7181
- if (!mpInstance._APIClient.shouldEnableBatching()) {
7182
- return;
7183
- }
7184
6929
  if (!mpid) {
7185
6930
  if (method !== 'modify') {
7186
6931
  return;
@@ -7216,9 +6961,6 @@ var mParticle = (function () {
7216
6961
  return userIdentityChangeEvent;
7217
6962
  };
7218
6963
  this.sendUserAttributeChangeEvent = function (attributeKey, newUserAttributeValue, previousUserAttributeValue, isNewAttribute, deleted, user) {
7219
- if (!mpInstance._APIClient.shouldEnableBatching()) {
7220
- return;
7221
- }
7222
6964
  var userAttributeChangeEvent = self.createUserAttributeChange(attributeKey, newUserAttributeValue, previousUserAttributeValue, isNewAttribute, deleted, user);
7223
6965
  if (userAttributeChangeEvent) {
7224
6966
  mpInstance._APIClient.sendEventToServer(userAttributeChangeEvent);
@@ -8138,7 +7880,6 @@ var mParticle = (function () {
8138
7880
  // These classes are for internal use only. Not documented for public consumption
8139
7881
  this._instanceName = instanceName;
8140
7882
  this._NativeSdkHelpers = new NativeSdkHelpers(this);
8141
- this._Migrations = new Migrations(this);
8142
7883
  this._SessionManager = new SessionManager(this);
8143
7884
  this._Persistence = new _Persistence(this);
8144
7885
  this._Helpers = new Helpers(this);
@@ -9060,14 +8801,6 @@ var mParticle = (function () {
9060
8801
  mpInstance._APIClient = new APIClient(mpInstance, kitBlocker);
9061
8802
  mpInstance._Forwarders = new Forwarders(mpInstance, kitBlocker);
9062
8803
  if (config.flags) {
9063
- if (config.flags.hasOwnProperty(Constants.FeatureFlags.EventsV3)) {
9064
- // TODO: Remove this after 8/12/2022
9065
- if (config.flags[Constants.FeatureFlags.EventsV3] !== '100') {
9066
- var message = 'mParticle will be enabling Event Batching for all customers on July 12, 2022. ' + 'For more details, please see our docs: https://docs.mparticle.com/developers/sdk/web/getting-started/';
9067
- mpInstance.Logger.warning(message);
9068
- }
9069
- mpInstance._Store.SDKConfig.flags[Constants.FeatureFlags.EventsV3] = config.flags[Constants.FeatureFlags.EventsV3];
9070
- }
9071
8804
  if (config.flags.hasOwnProperty(Constants.FeatureFlags.EventBatchingIntervalMillis)) {
9072
8805
  mpInstance._Store.SDKConfig.flags[Constants.FeatureFlags.EventBatchingIntervalMillis] = config.flags[Constants.FeatureFlags.EventBatchingIntervalMillis];
9073
8806
  }
@@ -9087,9 +8820,6 @@ var mParticle = (function () {
9087
8820
  mpInstance._Store.webviewBridgeEnabled = mpInstance._NativeSdkHelpers.isWebviewEnabled(mpInstance._Store.SDKConfig.requiredWebviewBridgeName, mpInstance._Store.SDKConfig.minWebviewBridgeVersion);
9088
8821
  mpInstance._Store.configurationLoaded = true;
9089
8822
  if (!mpInstance._Store.webviewBridgeEnabled) {
9090
- // Migrate any cookies from previous versions to current cookie version
9091
- mpInstance._Migrations.migrate();
9092
-
9093
8823
  // Load any settings/identities/attributes from cookie or localStorage
9094
8824
  mpInstance._Persistence.initializeStorage();
9095
8825
  }
@@ -9123,12 +8853,6 @@ var mParticle = (function () {
9123
8853
  userIdentities: modifiedUIforIdentityRequest
9124
8854
  };
9125
8855
  }
9126
-
9127
- // If migrating from pre-IDSync to IDSync, a sessionID will exist and an identify request will not have been fired, so we need this check
9128
- if (mpInstance._Store.migratingToIDSyncCookies) {
9129
- mpInstance.Identity.identify(mpInstance._Store.SDKConfig.identifyRequest, mpInstance._Store.SDKConfig.identityCallback);
9130
- mpInstance._Store.migratingToIDSyncCookies = false;
9131
- }
9132
8856
  currentUser = mpInstance.Identity.getCurrentUser();
9133
8857
  if (mpInstance._Helpers.getFeatureFlag(Constants.FeatureFlags.ReportBatching)) {
9134
8858
  mpInstance._ForwardingStatsUploader.startForwardingStatsTimer();
@@ -9243,7 +8967,9 @@ var mParticle = (function () {
9243
8967
  mpInstance._Store.devToken = apiKey || null;
9244
8968
  mpInstance.Logger.verbose(Messages.InformationMessages.StartingInitialization);
9245
8969
 
9246
- //check to see if localStorage is available for migrating purposes
8970
+ // Check to see if localStorage is available before main configuration runs
8971
+ // since we will need this for the current implementation of user persistence
8972
+ // TODO: Refactor this when we refactor User Identity Persistence
9247
8973
  try {
9248
8974
  mpInstance._Store.isLocalStorageAvailable = mpInstance._Persistence.determineLocalStorageAvailability(window.localStorage);
9249
8975
  } catch (e) {
@@ -9327,7 +9053,6 @@ var mParticle = (function () {
9327
9053
  consentState: null,
9328
9054
  clientId: null,
9329
9055
  deviceId: null,
9330
- migrationData: {},
9331
9056
  serverSettings: {},
9332
9057
  dateLastEventSent: null,
9333
9058
  sessionStartDate: null,
@@ -9341,7 +9066,6 @@ var mParticle = (function () {
9341
9066
  context: null,
9342
9067
  configurationLoaded: false,
9343
9068
  identityCallInFlight: false,
9344
- migratingToIDSyncCookies: false,
9345
9069
  nonCurrentUserMPIDs: {},
9346
9070
  identifyCalled: false,
9347
9071
  isLoggedIn: false,