@mparticle/web-sdk 2.19.2 → 2.20.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
@@ -725,7 +725,7 @@ var mParticle = (function () {
725
725
  Environment: Environment
726
726
  };
727
727
 
728
- var version = "2.19.2";
728
+ var version = "2.20.0";
729
729
 
730
730
  var Constants = {
731
731
  sdkVersion: version,
@@ -2111,12 +2111,27 @@ var mParticle = (function () {
2111
2111
  }
2112
2112
  }
2113
2113
 
2114
+ /**
2115
+ * BatchUploader contains all the logic to upload batches to mParticle.
2116
+ * It queues events as they come in and at set intervals turns them into batches.
2117
+ * It then attempts to upload them to mParticle.
2118
+ *
2119
+ * These uploads happen on an interval basis using window.fetch or XHR
2120
+ * requests, depending on what is available in the browser.
2121
+ *
2122
+ * Uploads can also be triggered on browser visibility/focus changes via an
2123
+ * event listener, which then uploads to mPartice via the browser's Beacon API.
2124
+ */
2125
+
2114
2126
  var BatchUploader =
2115
2127
  /** @class */
2116
2128
  function () {
2129
+ /**
2130
+ * Creates an instance of a BatchUploader
2131
+ * @param {MParticleWebSDK} mpInstance - the mParticle SDK instance
2132
+ * @param {number} uploadInterval - the desired upload interval in milliseconds
2133
+ */
2117
2134
  function BatchUploader(mpInstance, uploadInterval) {
2118
- var _this_1 = this;
2119
-
2120
2135
  this.mpInstance = mpInstance;
2121
2136
  this.uploadIntervalMillis = uploadInterval;
2122
2137
  this.batchingEnabled = uploadInterval >= BatchUploader.MINIMUM_INTERVAL_MILLIS;
@@ -2125,8 +2140,8 @@ var mParticle = (function () {
2125
2140
  this.uploadIntervalMillis = BatchUploader.MINIMUM_INTERVAL_MILLIS;
2126
2141
  }
2127
2142
 
2128
- this.pendingEvents = [];
2129
- this.pendingUploads = [];
2143
+ this.eventsQueuedForProcessing = [];
2144
+ this.batchesQueuedForProcessing = [];
2130
2145
  var _a = this.mpInstance._Store,
2131
2146
  SDKConfig = _a.SDKConfig,
2132
2147
  devToken = _a.devToken;
@@ -2134,14 +2149,16 @@ var mParticle = (function () {
2134
2149
  var baseUrl = this.mpInstance._Helpers.createServiceUrl(SDKConfig.v3SecureServiceUrl, devToken);
2135
2150
 
2136
2151
  this.uploadUrl = "".concat(baseUrl, "/events");
2137
- setTimeout(function () {
2138
- _this_1.prepareAndUpload(true, false);
2139
- }, this.uploadIntervalMillis);
2152
+ this.uploader = window.fetch ? new FetchUploader(this.uploadUrl) : new XHRUploader(this.uploadUrl);
2153
+ this.triggerUploadInterval(true, false);
2140
2154
  this.addEventListeners();
2141
- }
2155
+ } // Adds listeners to be used trigger Navigator.sendBeacon if the browser
2156
+ // loses focus for any reason, such as closing browser tab or minimizing window
2157
+
2142
2158
 
2143
2159
  BatchUploader.prototype.addEventListeners = function () {
2144
- var _this = this;
2160
+ var _this = this; // visibility change is a document property, not window
2161
+
2145
2162
 
2146
2163
  document.addEventListener('visibilitychange', function () {
2147
2164
  _this.prepareAndUpload(false, _this.isBeaconAvailable());
@@ -2160,13 +2177,36 @@ var mParticle = (function () {
2160
2177
  }
2161
2178
 
2162
2179
  return false;
2180
+ }; // Triggers a setTimeout for prepareAndUpload
2181
+
2182
+
2183
+ BatchUploader.prototype.triggerUploadInterval = function (triggerFuture, useBeacon) {
2184
+ var _this_1 = this;
2185
+
2186
+ if (triggerFuture === void 0) {
2187
+ triggerFuture = false;
2188
+ }
2189
+
2190
+ if (useBeacon === void 0) {
2191
+ useBeacon = false;
2192
+ }
2193
+
2194
+ setTimeout(function () {
2195
+ _this_1.prepareAndUpload(triggerFuture, useBeacon);
2196
+ }, this.uploadIntervalMillis);
2163
2197
  };
2198
+ /**
2199
+ * This method will queue a single Event which will eventually be processed into a Batch
2200
+ * @param event event that should be queued
2201
+ */
2202
+
2164
2203
 
2165
2204
  BatchUploader.prototype.queueEvent = function (event) {
2166
2205
  if (!isEmpty(event)) {
2167
- this.pendingEvents.push(event);
2206
+ this.eventsQueuedForProcessing.push(event);
2168
2207
  this.mpInstance.Logger.verbose("Queuing event: ".concat(JSON.stringify(event)));
2169
- this.mpInstance.Logger.verbose("Queued event count: ".concat(this.pendingEvents.length));
2208
+ this.mpInstance.Logger.verbose("Queued event count: ".concat(this.eventsQueuedForProcessing.length)); // TODO: Remove this check once the v2 code path is removed
2209
+ // https://go.mparticle.com/work/SQDSDKS-3720
2170
2210
 
2171
2211
  if (!this.batchingEnabled || Types.TriggerUploadType[event.EventDataType]) {
2172
2212
  this.prepareAndUpload(false, false);
@@ -2184,7 +2224,7 @@ var mParticle = (function () {
2184
2224
  */
2185
2225
 
2186
2226
 
2187
- BatchUploader.createNewUploads = function (sdkEvents, defaultUser, mpInstance) {
2227
+ BatchUploader.createNewBatches = function (sdkEvents, defaultUser, mpInstance) {
2188
2228
  if (!defaultUser || !sdkEvents || !sdkEvents.length) {
2189
2229
  return null;
2190
2230
  } //bucket by MPID, and then by session, ordered by timestamp
@@ -2264,41 +2304,40 @@ var mParticle = (function () {
2264
2304
 
2265
2305
  BatchUploader.prototype.prepareAndUpload = function (triggerFuture, useBeacon) {
2266
2306
  return __awaiter(this, void 0, void 0, function () {
2267
- var currentUser, currentEvents, newUploads, currentUploads, remainingUploads;
2307
+ var currentUser, currentEvents, newBatches, batchesToUpload, batchesThatDidNotUpload;
2268
2308
 
2269
2309
  var _a, _b;
2270
2310
 
2271
- var _this_1 = this;
2272
-
2273
2311
  return __generator(this, function (_c) {
2274
2312
  switch (_c.label) {
2275
2313
  case 0:
2276
2314
  currentUser = this.mpInstance.Identity.getCurrentUser();
2277
- currentEvents = this.pendingEvents;
2278
- this.pendingEvents = [];
2279
- newUploads = BatchUploader.createNewUploads(currentEvents, currentUser, this.mpInstance);
2315
+ currentEvents = this.eventsQueuedForProcessing;
2316
+ this.eventsQueuedForProcessing = [];
2317
+ newBatches = BatchUploader.createNewBatches(currentEvents, currentUser, this.mpInstance);
2280
2318
 
2281
- if (newUploads && newUploads.length) {
2282
- (_a = this.pendingUploads).push.apply(_a, newUploads);
2319
+ if (!isEmpty(newBatches)) {
2320
+ (_a = this.batchesQueuedForProcessing).push.apply(_a, newBatches);
2283
2321
  }
2284
2322
 
2285
- currentUploads = this.pendingUploads;
2286
- this.pendingUploads = [];
2323
+ batchesToUpload = this.batchesQueuedForProcessing;
2324
+ this.batchesQueuedForProcessing = [];
2287
2325
  return [4
2288
2326
  /*yield*/
2289
- , this.upload(this.mpInstance.Logger, currentUploads, useBeacon)];
2327
+ , this.uploadBatches(this.mpInstance.Logger, batchesToUpload, useBeacon)];
2290
2328
 
2291
2329
  case 1:
2292
- remainingUploads = _c.sent();
2330
+ batchesThatDidNotUpload = _c.sent(); // Batches that do not successfully upload are added back to the process queue
2331
+ // in the order they were created so that we can attempt re-transmission in
2332
+ // the same sequence. This is to prevent any potential data corruption.
2293
2333
 
2294
- if (remainingUploads && remainingUploads.length) {
2295
- (_b = this.pendingUploads).unshift.apply(_b, remainingUploads);
2334
+ if (!isEmpty(batchesThatDidNotUpload)) {
2335
+ // TODO: https://go.mparticle.com/work/SQDSDKS-5165
2336
+ (_b = this.batchesQueuedForProcessing).unshift.apply(_b, batchesThatDidNotUpload);
2296
2337
  }
2297
2338
 
2298
2339
  if (triggerFuture) {
2299
- setTimeout(function () {
2300
- _this_1.prepareAndUpload(true, false);
2301
- }, this.uploadIntervalMillis);
2340
+ this.triggerUploadInterval(triggerFuture, false);
2302
2341
  }
2303
2342
 
2304
2343
  return [2
@@ -2307,16 +2346,18 @@ var mParticle = (function () {
2307
2346
  }
2308
2347
  });
2309
2348
  });
2310
- };
2349
+ }; // TODO: Refactor to use logger as a class method
2350
+ // https://go.mparticle.com/work/SQDSDKS-5167
2311
2351
 
2312
- BatchUploader.prototype.upload = function (logger, _uploads, useBeacon) {
2352
+
2353
+ BatchUploader.prototype.uploadBatches = function (logger, batches, useBeacon) {
2313
2354
  return __awaiter(this, void 0, void 0, function () {
2314
- var uploader, uploads, i, fetchPayload, blob, response, e_1;
2355
+ var uploads, i, fetchPayload, blob, response, e_1;
2315
2356
  return __generator(this, function (_a) {
2316
2357
  switch (_a.label) {
2317
2358
  case 0:
2318
- uploads = _uploads.filter(function (upload) {
2319
- return !isEmpty(upload.events);
2359
+ uploads = batches.filter(function (batch) {
2360
+ return !isEmpty(batch.events);
2320
2361
  });
2321
2362
 
2322
2363
  if (isEmpty(uploads)) {
@@ -2333,7 +2374,7 @@ var mParticle = (function () {
2333
2374
  case 1:
2334
2375
  if (!(i < uploads.length)) return [3
2335
2376
  /*break*/
2336
- , 7];
2377
+ , 6];
2337
2378
  fetchPayload = {
2338
2379
  method: 'POST',
2339
2380
  headers: {
@@ -2351,33 +2392,22 @@ var mParticle = (function () {
2351
2392
  navigator.sendBeacon(this.uploadUrl, blob);
2352
2393
  return [3
2353
2394
  /*break*/
2354
- , 6];
2395
+ , 5];
2355
2396
 
2356
2397
  case 2:
2357
- if (!uploader) {
2358
- if (window.fetch) {
2359
- uploader = new FetchUploader(this.uploadUrl, logger);
2360
- } else {
2361
- uploader = new XHRUploader(this.uploadUrl, logger);
2362
- }
2363
- }
2364
-
2365
- _a.label = 3;
2366
-
2367
- case 3:
2368
- _a.trys.push([3, 5,, 6]);
2398
+ _a.trys.push([2, 4,, 5]);
2369
2399
 
2370
2400
  return [4
2371
2401
  /*yield*/
2372
- , uploader.upload(fetchPayload, uploads, i)];
2402
+ , this.uploader.upload(fetchPayload)];
2373
2403
 
2374
- case 4:
2404
+ case 3:
2375
2405
  response = _a.sent();
2376
2406
 
2377
2407
  if (response.status >= 200 && response.status < 300) {
2378
2408
  logger.verbose("Upload success for request ID: ".concat(uploads[i].source_request_id));
2379
2409
  } else if (response.status >= 500 || response.status === 429) {
2380
- logger.error("HTTP error status ".concat(response.status, " received")); //server error, add back current events and try again later
2410
+ logger.error("HTTP error status ".concat(response.status, " received")); // Server error, add back current batches and try again later
2381
2411
 
2382
2412
  return [2
2383
2413
  /*return*/
@@ -2388,33 +2418,37 @@ var mParticle = (function () {
2388
2418
  return [2
2389
2419
  /*return*/
2390
2420
  , null];
2421
+ } else {
2422
+ // In case there is an HTTP error we did not anticipate.
2423
+ console.error("HTTP error status ".concat(response.status, " while uploading events."), response);
2424
+ throw new Error("Uncaught HTTP Error ".concat(response.status, ". Batch upload will be re-attempted."));
2391
2425
  }
2392
2426
 
2393
2427
  return [3
2394
2428
  /*break*/
2395
- , 6];
2429
+ , 5];
2396
2430
 
2397
- case 5:
2431
+ case 4:
2398
2432
  e_1 = _a.sent();
2399
2433
  logger.error("Error sending event to mParticle servers. ".concat(e_1));
2400
2434
  return [2
2401
2435
  /*return*/
2402
2436
  , uploads.slice(i, uploads.length)];
2403
2437
 
2404
- case 6:
2438
+ case 5:
2405
2439
  i++;
2406
2440
  return [3
2407
2441
  /*break*/
2408
2442
  , 1];
2409
2443
 
2410
- case 7:
2444
+ case 6:
2411
2445
  return [2
2412
2446
  /*return*/
2413
2447
  , null];
2414
2448
  }
2415
2449
  });
2416
2450
  });
2417
- }; //we upload JSON, but this content type is required to avoid a CORS preflight request
2451
+ }; // We upload JSON, but this content type is required to avoid a CORS preflight request
2418
2452
 
2419
2453
 
2420
2454
  BatchUploader.CONTENT_TYPE = 'text/plain;charset=UTF-8';
@@ -2425,9 +2459,8 @@ var mParticle = (function () {
2425
2459
  var AsyncUploader =
2426
2460
  /** @class */
2427
2461
  function () {
2428
- function AsyncUploader(url, logger) {
2462
+ function AsyncUploader(url) {
2429
2463
  this.url = url;
2430
- this.logger = logger;
2431
2464
  }
2432
2465
 
2433
2466
  return AsyncUploader;
@@ -2442,7 +2475,7 @@ var mParticle = (function () {
2442
2475
  return _super !== null && _super.apply(this, arguments) || this;
2443
2476
  }
2444
2477
 
2445
- FetchUploader.prototype.upload = function (fetchPayload, uploads, i) {
2478
+ FetchUploader.prototype.upload = function (fetchPayload) {
2446
2479
  return __awaiter(this, void 0, void 0, function () {
2447
2480
  var response;
2448
2481
  return __generator(this, function (_a) {
@@ -2474,7 +2507,7 @@ var mParticle = (function () {
2474
2507
  return _super !== null && _super.apply(this, arguments) || this;
2475
2508
  }
2476
2509
 
2477
- XHRUploader.prototype.upload = function (fetchPayload, uploads, i) {
2510
+ XHRUploader.prototype.upload = function (fetchPayload) {
2478
2511
  return __awaiter(this, void 0, void 0, function () {
2479
2512
  var response;
2480
2513
  return __generator(this, function (_a) {
@@ -2482,7 +2515,7 @@ var mParticle = (function () {
2482
2515
  case 0:
2483
2516
  return [4
2484
2517
  /*yield*/
2485
- , this.makeRequest(this.url, this.logger, fetchPayload.body)];
2518
+ , this.makeRequest(this.url, fetchPayload.body)];
2486
2519
 
2487
2520
  case 1:
2488
2521
  response = _a.sent();
@@ -2494,7 +2527,7 @@ var mParticle = (function () {
2494
2527
  });
2495
2528
  };
2496
2529
 
2497
- XHRUploader.prototype.makeRequest = function (url, logger, data) {
2530
+ XHRUploader.prototype.makeRequest = function (url, data) {
2498
2531
  return __awaiter(this, void 0, void 0, function () {
2499
2532
  var xhr;
2500
2533
  return __generator(this, function (_a) {
@@ -3172,6 +3205,11 @@ var mParticle = (function () {
3172
3205
  return filteredUserAttributes;
3173
3206
  };
3174
3207
 
3208
+ this.isFilteredUserAttribute = function (userAttributeKey, filterList) {
3209
+ var hashedUserAttribute = self.generateHash(userAttributeKey);
3210
+ return filterList && self.inArray(filterList, hashedUserAttribute);
3211
+ };
3212
+
3175
3213
  this.isEventType = function (type) {
3176
3214
  for (var prop in Types.EventType) {
3177
3215
  if (Types.EventType.hasOwnProperty(prop)) {
@@ -4269,6 +4307,7 @@ var mParticle = (function () {
4269
4307
  prodStorageName: null,
4270
4308
  activeForwarders: [],
4271
4309
  kits: {},
4310
+ sideloadedKits: [],
4272
4311
  configuredForwarders: [],
4273
4312
  pixelConfigurations: [],
4274
4313
  wrapperSDKInfo: {
@@ -4326,6 +4365,7 @@ var mParticle = (function () {
4326
4365
 
4327
4366
  this.SDKConfig.useNativeSdk = !!config.useNativeSdk;
4328
4367
  this.SDKConfig.kits = config.kits || {};
4368
+ this.SDKConfig.sideloadedKits = config.sideloadedKits || [];
4329
4369
 
4330
4370
  if (config.hasOwnProperty('isIOS')) {
4331
4371
  this.SDKConfig.isIOS = config.isIOS;
@@ -5321,6 +5361,9 @@ var mParticle = (function () {
5321
5361
  if (userAttributes) {
5322
5362
  if (persistence) {
5323
5363
  if (persistence[mpid]) {
5364
+ // TODO: Investigate why setting this to UI still shows up as UA
5365
+ // when running `mParticle.getInstance()._Persistence.getLocalStorage()`
5366
+ // https://go.mparticle.com/work/SQDSDKS-5195
5324
5367
  persistence[mpid].ui = userAttributes;
5325
5368
  } else {
5326
5369
  persistence[mpid] = {
@@ -6150,6 +6193,10 @@ var mParticle = (function () {
6150
6193
 
6151
6194
  function Forwarders(mpInstance, kitBlocker) {
6152
6195
  var self = this;
6196
+ var UserAttributeActionTypes = {
6197
+ setUserAttribute: 'setUserAttribute',
6198
+ removeUserAttribute: 'removeUserAttribute'
6199
+ };
6153
6200
 
6154
6201
  this.initForwarders = function (userIdentities, forwardingStatsCallback) {
6155
6202
  var user = mpInstance.Identity.getCurrentUser();
@@ -6384,26 +6431,34 @@ var mParticle = (function () {
6384
6431
  }
6385
6432
  };
6386
6433
 
6387
- this.callSetUserAttributeOnForwarders = function (key, value) {
6388
- if (kitBlocker && kitBlocker.isAttributeKeyBlocked(key)) {
6434
+ this.handleForwarderUserAttributes = function (functionNameKey, key, value) {
6435
+ if (kitBlocker && kitBlocker.isAttributeKeyBlocked(key) || !mpInstance._Store.activeForwarders.length) {
6389
6436
  return;
6390
6437
  }
6391
6438
 
6392
- if (mpInstance._Store.activeForwarders.length) {
6393
- mpInstance._Store.activeForwarders.forEach(function (forwarder) {
6394
- if (forwarder.setUserAttribute && forwarder.userAttributeFilters && !mpInstance._Helpers.inArray(forwarder.userAttributeFilters, mpInstance._Helpers.generateHash(key))) {
6395
- try {
6396
- var result = forwarder.setUserAttribute(key, value);
6439
+ mpInstance._Store.activeForwarders.forEach(function (forwarder) {
6440
+ var forwarderFunction = forwarder[functionNameKey];
6397
6441
 
6398
- if (result) {
6399
- mpInstance.Logger.verbose(result);
6400
- }
6401
- } catch (e) {
6402
- mpInstance.Logger.error(e);
6403
- }
6442
+ if (!forwarderFunction || mpInstance._Helpers.isFilteredUserAttribute(key, forwarder.userAttributeFilters)) {
6443
+ return;
6444
+ }
6445
+
6446
+ try {
6447
+ var result;
6448
+
6449
+ if (functionNameKey === UserAttributeActionTypes.setUserAttribute) {
6450
+ result = forwarder.setUserAttribute(key, value);
6451
+ } else if (functionNameKey === UserAttributeActionTypes.removeUserAttribute) {
6452
+ result = forwarder.removeUserAttribute(key);
6404
6453
  }
6405
- });
6406
- }
6454
+
6455
+ if (result) {
6456
+ mpInstance.Logger.verbose(result);
6457
+ }
6458
+ } catch (e) {
6459
+ mpInstance.Logger.error(e);
6460
+ }
6461
+ });
6407
6462
  };
6408
6463
 
6409
6464
  this.setForwarderUserIdentities = function (userIdentities) {
@@ -6484,16 +6539,50 @@ var mParticle = (function () {
6484
6539
 
6485
6540
  this.setForwarderStatsQueue = function (queue) {
6486
6541
  mpInstance._Persistence.forwardingStatsBatches.forwardingStatsEventQueue = queue;
6542
+ }; // Processing forwarders is a 2 step process:
6543
+ // 1. Configure the kit
6544
+ // 2. Initialize the kit
6545
+ // There are 2 types of kits:
6546
+ // 1. UI-enabled kits
6547
+ // 2. Sideloaded kits.
6548
+
6549
+
6550
+ this.processForwarders = function (config, forwardingStatsCallback) {
6551
+ if (!config) {
6552
+ mpInstance.Logger.warning('No config was passed. Cannot process forwarders');
6553
+ } else {
6554
+ this.processUIEnabledKits(config);
6555
+ this.processSideloadedKits(config);
6556
+ self.initForwarders(mpInstance._Store.SDKConfig.identifyRequest.userIdentities, forwardingStatsCallback);
6557
+ }
6558
+ }; // These are kits that are enabled via the mParticle UI.
6559
+ // A kit that is UI-enabled will have a kit configuration that returns from
6560
+ // the server, or in rare cases, is passed in by the developer.
6561
+ // The kit configuration will be compared with the kit constructors to determine
6562
+ // if there is a match before being initialized.
6563
+ // Only kits that are configured properly can be active and used for kit forwarding.
6564
+
6565
+
6566
+ this.processUIEnabledKits = function (config) {
6567
+ try {
6568
+ if (Array.isArray(config.kitConfigs) && config.kitConfigs.length) {
6569
+ config.kitConfigs.forEach(function (kitConfig) {
6570
+ self.configureUIEnabledKit(kitConfig);
6571
+ });
6572
+ }
6573
+ } catch (e) {
6574
+ mpInstance.Logger.error('MP Kits not configured propertly. Kits may not be initialized. ' + e);
6575
+ }
6487
6576
  };
6488
6577
 
6489
- this.configureForwarder = function (configuration) {
6578
+ this.configureUIEnabledKit = function (configuration) {
6490
6579
  var newForwarder = null,
6491
6580
  config = configuration,
6492
- forwarders = {}; // if there are kits inside of mpInstance._Store.SDKConfig.kits, then mParticle is self hosted
6581
+ forwarders = {}; // If there are kits inside of mpInstance._Store.SDKConfig.kits, then mParticle is self hosted
6493
6582
 
6494
- if (mpInstance._Helpers.isObject(mpInstance._Store.SDKConfig.kits) && Object.keys(mpInstance._Store.SDKConfig.kits).length > 0) {
6583
+ if (!isEmpty(mpInstance._Store.SDKConfig.kits)) {
6495
6584
  forwarders = mpInstance._Store.SDKConfig.kits; // otherwise mParticle is loaded via script tag
6496
- } else if (mpInstance._preInit.forwarderConstructors.length > 0) {
6585
+ } else if (!isEmpty(mpInstance._preInit.forwarderConstructors)) {
6497
6586
  mpInstance._preInit.forwarderConstructors.forEach(function (forwarder) {
6498
6587
  forwarders[forwarder.name] = forwarder;
6499
6588
  });
@@ -6502,25 +6591,7 @@ var mParticle = (function () {
6502
6591
  for (var name in forwarders) {
6503
6592
  if (name === config.name) {
6504
6593
  if (config.isDebug === mpInstance._Store.SDKConfig.isDevelopmentMode || config.isSandbox === mpInstance._Store.SDKConfig.isDevelopmentMode) {
6505
- newForwarder = new forwarders[name].constructor();
6506
- newForwarder.id = config.moduleId;
6507
- newForwarder.isSandbox = config.isDebug || config.isSandbox;
6508
- newForwarder.hasSandbox = config.hasDebugString === 'true';
6509
- newForwarder.isVisible = config.isVisible;
6510
- newForwarder.settings = config.settings;
6511
- newForwarder.eventNameFilters = config.eventNameFilters;
6512
- newForwarder.eventTypeFilters = config.eventTypeFilters;
6513
- newForwarder.attributeFilters = config.attributeFilters;
6514
- newForwarder.screenNameFilters = config.screenNameFilters;
6515
- newForwarder.screenNameFilters = config.screenNameFilters;
6516
- newForwarder.screenAttributeFilters = config.screenAttributeFilters;
6517
- newForwarder.userIdentityFilters = config.userIdentityFilters;
6518
- newForwarder.userAttributeFilters = config.userAttributeFilters;
6519
- newForwarder.filteringEventAttributeValue = config.filteringEventAttributeValue;
6520
- newForwarder.filteringUserAttributeValue = config.filteringUserAttributeValue;
6521
- newForwarder.eventSubscriptionId = config.eventSubscriptionId;
6522
- newForwarder.filteringConsentRuleValues = config.filteringConsentRuleValues;
6523
- newForwarder.excludeAnonymousUser = config.excludeAnonymousUser;
6594
+ newForwarder = this.returnConfiguredKit(forwarders[name], config);
6524
6595
 
6525
6596
  mpInstance._Store.configuredForwarders.push(newForwarder);
6526
6597
 
@@ -6528,6 +6599,68 @@ var mParticle = (function () {
6528
6599
  }
6529
6600
  }
6530
6601
  }
6602
+ }; // Sideloaded kits are not configured in the UI and do not have kit configurations
6603
+ // They are automatically added to active forwarders.
6604
+ // TODO: Sideloading kits currently requires the use of a register method
6605
+ // which requires an object on which to be registered.
6606
+ // In the future, when all kits are moved to the config rather than
6607
+ // there being a separate process for MP configured kits and
6608
+ // sideloaded kits, this will need to be refactored.
6609
+
6610
+
6611
+ this.processSideloadedKits = function (config) {
6612
+ try {
6613
+ if (Array.isArray(config.sideloadedKits)) {
6614
+ var sideloadedKits = {
6615
+ kits: {}
6616
+ }; // First register each kit's constructor onto sideloadedKits,
6617
+ // which is typed { kits: Dictionary<constructor> }.
6618
+ // The constructors are keyed by the name of the kit.
6619
+
6620
+ config.sideloadedKits.forEach(function (sideloadedKit) {
6621
+ sideloadedKit.register(sideloadedKits);
6622
+ }); // Then configure each kit
6623
+
6624
+ for (var registeredKitKey in sideloadedKits.kits) {
6625
+ var kitConstructor = sideloadedKits.kits[registeredKitKey];
6626
+ self.configureSideloadedKit(kitConstructor);
6627
+ }
6628
+ }
6629
+ } catch (e) {
6630
+ mpInstance.Logger.error('Sideloaded Kits not configured propertly. Kits may not be initialized. ' + e);
6631
+ }
6632
+ }; // kits can be included via mParticle UI, or via sideloaded kit config API
6633
+
6634
+
6635
+ this.configureSideloadedKit = function (kitConstructor) {
6636
+ mpInstance._Store.configuredForwarders.push(this.returnConfiguredKit(kitConstructor));
6637
+ };
6638
+
6639
+ this.returnConfiguredKit = function (forwarder) {
6640
+ var config = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
6641
+ var newForwarder = new forwarder.constructor();
6642
+ newForwarder.id = config.moduleId; // TODO: isSandbox, hasSandbox is never used in any kit or in core SDK.
6643
+ // isVisibleInvestigate is only used in 1 place. It is always true if
6644
+ // it is sent to JS. Investigate further to determine if these can be removed.
6645
+ // https://go.mparticle.com/work/SQDSDKS-5156
6646
+
6647
+ newForwarder.isSandbox = config.isDebug || config.isSandbox;
6648
+ newForwarder.hasSandbox = config.hasDebugString === 'true';
6649
+ newForwarder.isVisible = config.isVisible || true;
6650
+ newForwarder.settings = config.settings || {};
6651
+ newForwarder.eventNameFilters = config.eventNameFilters || [];
6652
+ newForwarder.eventTypeFilters = config.eventTypeFilters || [];
6653
+ newForwarder.attributeFilters = config.attributeFilters || [];
6654
+ newForwarder.screenNameFilters = config.screenNameFilters || [];
6655
+ newForwarder.screenAttributeFilters = config.screenAttributeFilters || [];
6656
+ newForwarder.userIdentityFilters = config.userIdentityFilters || [];
6657
+ newForwarder.userAttributeFilters = config.userAttributeFilters || [];
6658
+ newForwarder.filteringEventAttributeValue = config.filteringEventAttributeValue || {};
6659
+ newForwarder.filteringUserAttributeValue = config.filteringUserAttributeValue || {};
6660
+ newForwarder.eventSubscriptionId = config.eventSubscriptionId || null;
6661
+ newForwarder.filteringConsentRuleValues = config.filteringConsentRuleValues || {};
6662
+ newForwarder.excludeAnonymousUser = config.excludeAnonymousUser || false;
6663
+ return newForwarder;
6531
6664
  };
6532
6665
 
6533
6666
  this.configurePixel = function (settings) {
@@ -6536,27 +6669,15 @@ var mParticle = (function () {
6536
6669
  }
6537
6670
  };
6538
6671
 
6539
- this.processForwarders = function (config, forwardingStatsCallback) {
6540
- if (!config) {
6541
- mpInstance.Logger.warning('No config was passed. Cannot process forwarders');
6542
- } else {
6543
- try {
6544
- if (Array.isArray(config.kitConfigs) && config.kitConfigs.length) {
6545
- config.kitConfigs.forEach(function (kitConfig) {
6546
- self.configureForwarder(kitConfig);
6547
- });
6548
- }
6549
-
6550
- if (Array.isArray(config.pixelConfigs) && config.pixelConfigs.length) {
6551
- config.pixelConfigs.forEach(function (pixelConfig) {
6552
- self.configurePixel(pixelConfig);
6553
- });
6554
- }
6555
-
6556
- self.initForwarders(mpInstance._Store.SDKConfig.identifyRequest.userIdentities, forwardingStatsCallback);
6557
- } catch (e) {
6558
- mpInstance.Logger.error('Config was not parsed propertly. Forwarders may not be initialized.');
6672
+ this.processPixelConfigs = function (config) {
6673
+ try {
6674
+ if (!isEmpty(config.pixelConfigs)) {
6675
+ config.pixelConfigs.forEach(function (pixelConfig) {
6676
+ self.configurePixel(pixelConfig);
6677
+ });
6559
6678
  }
6679
+ } catch (e) {
6680
+ mpInstance.Logger.error('Cookie Sync configs not configured propertly. Cookie Sync may not be initialized. ' + e);
6560
6681
  }
6561
6682
  };
6562
6683
  }
@@ -7608,7 +7729,7 @@ var mParticle = (function () {
7608
7729
 
7609
7730
  mpInstance._Forwarders.initForwarders(self.IdentityAPI.getCurrentUser().getUserIdentities(), mpInstance._APIClient.prepareForwardingStats);
7610
7731
 
7611
- mpInstance._Forwarders.callSetUserAttributeOnForwarders(key, newValue);
7732
+ mpInstance._Forwarders.handleForwarderUserAttributes('setUserAttribute', key, newValue);
7612
7733
  }
7613
7734
  }
7614
7735
  },
@@ -7677,7 +7798,7 @@ var mParticle = (function () {
7677
7798
 
7678
7799
  mpInstance._Forwarders.initForwarders(self.IdentityAPI.getCurrentUser().getUserIdentities(), mpInstance._APIClient.prepareForwardingStats);
7679
7800
 
7680
- mpInstance._Forwarders.applyToForwarders('removeUserAttribute', key);
7801
+ mpInstance._Forwarders.handleForwarderUserAttributes('removeUserAttribute', key, null);
7681
7802
  }
7682
7803
  },
7683
7804
 
@@ -7755,7 +7876,7 @@ var mParticle = (function () {
7755
7876
 
7756
7877
  mpInstance._Forwarders.initForwarders(self.IdentityAPI.getCurrentUser().getUserIdentities(), mpInstance._APIClient.prepareForwardingStats);
7757
7878
 
7758
- mpInstance._Forwarders.callSetUserAttributeOnForwarders(key, arrayCopy);
7879
+ mpInstance._Forwarders.handleForwarderUserAttributes('setUserAttribute', key, arrayCopy);
7759
7880
  }
7760
7881
  },
7761
7882
 
@@ -7778,7 +7899,7 @@ var mParticle = (function () {
7778
7899
  if (userAttributes) {
7779
7900
  for (var prop in userAttributes) {
7780
7901
  if (userAttributes.hasOwnProperty(prop)) {
7781
- mpInstance._Forwarders.applyToForwarders('removeUserAttribute', prop);
7902
+ mpInstance._Forwarders.handleForwarderUserAttributes('removeUserAttribute', prop, null);
7782
7903
  }
7783
7904
 
7784
7905
  this.removeUserAttribute(prop);
@@ -10505,6 +10626,8 @@ var mParticle = (function () {
10505
10626
 
10506
10627
  mpInstance._Forwarders.processForwarders(config, mpInstance._APIClient.prepareForwardingStats);
10507
10628
 
10629
+ mpInstance._Forwarders.processPixelConfigs(config);
10630
+
10508
10631
  mpInstance._SessionManager.initialize();
10509
10632
 
10510
10633
  mpInstance._Events.logAST(); // Call mParticle._Store.SDKConfig.identityCallback when identify was not called due to a reload or a sessionId already existing
@@ -10707,6 +10830,7 @@ var mParticle = (function () {
10707
10830
  _SessionManager: null,
10708
10831
  _Store: {
10709
10832
  sessionId: 'mockSessionId',
10833
+ sideloadedKits: [],
10710
10834
  devToken: 'test_dev_token',
10711
10835
  isFirstRun: true,
10712
10836
  isEnabled: true,