@mparticle/web-sdk 2.26.0 → 2.26.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
@@ -244,8 +244,574 @@ var mParticle = (function () {
244
244
  return obj;
245
245
  }
246
246
 
247
+ var EventTypeEnum;
248
+ (function (EventTypeEnum) {
249
+ EventTypeEnum[EventTypeEnum["Unknown"] = 0] = "Unknown";
250
+ EventTypeEnum[EventTypeEnum["Navigation"] = 1] = "Navigation";
251
+ EventTypeEnum[EventTypeEnum["Location"] = 2] = "Location";
252
+ EventTypeEnum[EventTypeEnum["Search"] = 3] = "Search";
253
+ EventTypeEnum[EventTypeEnum["Transaction"] = 4] = "Transaction";
254
+ EventTypeEnum[EventTypeEnum["UserContent"] = 5] = "UserContent";
255
+ EventTypeEnum[EventTypeEnum["UserPreference"] = 6] = "UserPreference";
256
+ EventTypeEnum[EventTypeEnum["Social"] = 7] = "Social";
257
+ EventTypeEnum[EventTypeEnum["Other"] = 8] = "Other";
258
+ EventTypeEnum[EventTypeEnum["Media"] = 9] = "Media";
259
+ })(EventTypeEnum || (EventTypeEnum = {}));
260
+ // TODO: https://mparticle-eng.atlassian.net/browse/SQDSDKS-5403
261
+ var MessageType$2;
262
+ (function (MessageType) {
263
+ MessageType[MessageType["SessionStart"] = 1] = "SessionStart";
264
+ MessageType[MessageType["SessionEnd"] = 2] = "SessionEnd";
265
+ MessageType[MessageType["PageView"] = 3] = "PageView";
266
+ MessageType[MessageType["PageEvent"] = 4] = "PageEvent";
267
+ MessageType[MessageType["CrashReport"] = 5] = "CrashReport";
268
+ MessageType[MessageType["OptOut"] = 6] = "OptOut";
269
+ MessageType[MessageType["AppStateTransition"] = 10] = "AppStateTransition";
270
+ MessageType[MessageType["Profile"] = 14] = "Profile";
271
+ MessageType[MessageType["Commerce"] = 16] = "Commerce";
272
+ MessageType[MessageType["UserAttributeChange"] = 17] = "UserAttributeChange";
273
+ MessageType[MessageType["UserIdentityChange"] = 18] = "UserIdentityChange";
274
+ MessageType[MessageType["Media"] = 20] = "Media";
275
+ })(MessageType$2 || (MessageType$2 = {}));
276
+ var IdentityType$1;
277
+ (function (IdentityType) {
278
+ IdentityType[IdentityType["Other"] = 0] = "Other";
279
+ IdentityType[IdentityType["CustomerId"] = 1] = "CustomerId";
280
+ IdentityType[IdentityType["Facebook"] = 2] = "Facebook";
281
+ IdentityType[IdentityType["Twitter"] = 3] = "Twitter";
282
+ IdentityType[IdentityType["Google"] = 4] = "Google";
283
+ IdentityType[IdentityType["Microsoft"] = 5] = "Microsoft";
284
+ IdentityType[IdentityType["Yahoo"] = 6] = "Yahoo";
285
+ IdentityType[IdentityType["Email"] = 7] = "Email";
286
+ IdentityType[IdentityType["FacebookCustomAudienceId"] = 9] = "FacebookCustomAudienceId";
287
+ IdentityType[IdentityType["Other2"] = 10] = "Other2";
288
+ IdentityType[IdentityType["Other3"] = 11] = "Other3";
289
+ IdentityType[IdentityType["Other4"] = 12] = "Other4";
290
+ IdentityType[IdentityType["Other5"] = 13] = "Other5";
291
+ IdentityType[IdentityType["Other6"] = 14] = "Other6";
292
+ IdentityType[IdentityType["Other7"] = 15] = "Other7";
293
+ IdentityType[IdentityType["Other8"] = 16] = "Other8";
294
+ IdentityType[IdentityType["Other9"] = 17] = "Other9";
295
+ IdentityType[IdentityType["Other10"] = 18] = "Other10";
296
+ IdentityType[IdentityType["MobileNumber"] = 19] = "MobileNumber";
297
+ IdentityType[IdentityType["PhoneNumber2"] = 20] = "PhoneNumber2";
298
+ IdentityType[IdentityType["PhoneNumber3"] = 21] = "PhoneNumber3";
299
+ })(IdentityType$1 || (IdentityType$1 = {}));
300
+
301
+ /******************************************************************************
302
+ Copyright (c) Microsoft Corporation.
303
+
304
+ Permission to use, copy, modify, and/or distribute this software for any
305
+ purpose with or without fee is hereby granted.
306
+
307
+ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
308
+ REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
309
+ AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
310
+ INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
311
+ LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
312
+ OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
313
+ PERFORMANCE OF THIS SOFTWARE.
314
+ ***************************************************************************** */
315
+ /* global Reflect, Promise, SuppressedError, Symbol */
316
+
317
+ var extendStatics = function(d, b) {
318
+ extendStatics = Object.setPrototypeOf ||
319
+ ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
320
+ function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
321
+ return extendStatics(d, b);
322
+ };
323
+
324
+ function __extends(d, b) {
325
+ if (typeof b !== "function" && b !== null)
326
+ throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
327
+ extendStatics(d, b);
328
+ function __() { this.constructor = d; }
329
+ d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
330
+ }
331
+
332
+ var __assign = function() {
333
+ __assign = Object.assign || function __assign(t) {
334
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
335
+ s = arguments[i];
336
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
337
+ }
338
+ return t;
339
+ };
340
+ return __assign.apply(this, arguments);
341
+ };
342
+
343
+ function __awaiter(thisArg, _arguments, P, generator) {
344
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
345
+ return new (P || (P = Promise))(function (resolve, reject) {
346
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
347
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
348
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
349
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
350
+ });
351
+ }
352
+
353
+ function __generator(thisArg, body) {
354
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
355
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
356
+ function verb(n) { return function (v) { return step([n, v]); }; }
357
+ function step(op) {
358
+ if (f) throw new TypeError("Generator is already executing.");
359
+ while (g && (g = 0, op[0] && (_ = 0)), _) try {
360
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
361
+ if (y = 0, t) op = [op[0] & 2, t.value];
362
+ switch (op[0]) {
363
+ case 0: case 1: t = op; break;
364
+ case 4: _.label++; return { value: op[1], done: false };
365
+ case 5: _.label++; y = op[1]; op = [0]; continue;
366
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
367
+ default:
368
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
369
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
370
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
371
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
372
+ if (t[2]) _.ops.pop();
373
+ _.trys.pop(); continue;
374
+ }
375
+ op = body.call(thisArg, _);
376
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
377
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
378
+ }
379
+ }
380
+
381
+ function __spreadArray(to, from, pack) {
382
+ if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
383
+ if (ar || !(i in from)) {
384
+ if (!ar) ar = Array.prototype.slice.call(from, 0, i);
385
+ ar[i] = from[i];
386
+ }
387
+ }
388
+ return to.concat(ar || Array.prototype.slice.call(from));
389
+ }
390
+
391
+ typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
392
+ var e = new Error(message);
393
+ return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
394
+ };
395
+
396
+ var version = "2.26.2";
397
+
398
+ var Constants = {
399
+ sdkVersion: version,
400
+ sdkVendor: 'mparticle',
401
+ platform: 'web',
402
+ Messages: {
403
+ DeprecationMessages: {
404
+ MethodIsDeprecatedPostfix: 'is a deprecated method and will be removed in future releases',
405
+ AlternativeMethodPrefix: 'Please use the alternate method:'
406
+ },
407
+ ErrorMessages: {
408
+ NoToken: 'A token must be specified.',
409
+ EventNameInvalidType: 'Event name must be a valid string value.',
410
+ EventDataInvalidType: 'Event data must be a valid object hash.',
411
+ LoggingDisabled: 'Event logging is currently disabled.',
412
+ CookieParseError: 'Could not parse cookie',
413
+ EventEmpty: 'Event object is null or undefined, cancelling send',
414
+ APIRequestEmpty: 'APIRequest is null or undefined, cancelling send',
415
+ NoEventType: 'Event type must be specified.',
416
+ TransactionIdRequired: 'Transaction ID is required',
417
+ TransactionRequired: 'A transaction attributes object is required',
418
+ PromotionIdRequired: 'Promotion ID is required',
419
+ BadAttribute: 'Attribute value cannot be object or array',
420
+ BadKey: 'Key value cannot be object or array',
421
+ BadLogPurchase: 'Transaction attributes and a product are both required to log a purchase, https://docs.mparticle.com/?javascript#measuring-transactions',
422
+ AudienceAPINotEnabled: 'Your workspace is not enabled to retrieve user audiences.'
423
+ },
424
+ InformationMessages: {
425
+ CookieSearch: 'Searching for cookie',
426
+ CookieFound: 'Cookie found, parsing values',
427
+ CookieNotFound: 'Cookies not found',
428
+ CookieSet: 'Setting cookie',
429
+ CookieSync: 'Performing cookie sync',
430
+ SendBegin: 'Starting to send event',
431
+ SendIdentityBegin: 'Starting to send event to identity server',
432
+ SendWindowsPhone: 'Sending event to Windows Phone container',
433
+ SendIOS: 'Calling iOS path: ',
434
+ SendAndroid: 'Calling Android JS interface method: ',
435
+ SendHttp: 'Sending event to mParticle HTTP service',
436
+ SendAliasHttp: 'Sending alias request to mParticle HTTP service',
437
+ SendIdentityHttp: 'Sending event to mParticle HTTP service',
438
+ StartingNewSession: 'Starting new Session',
439
+ StartingLogEvent: 'Starting to log event',
440
+ StartingLogOptOut: 'Starting to log user opt in/out',
441
+ StartingEndSession: 'Starting to end session',
442
+ StartingInitialization: 'Starting to initialize',
443
+ StartingLogCommerceEvent: 'Starting to log commerce event',
444
+ StartingAliasRequest: 'Starting to Alias MPIDs',
445
+ LoadingConfig: 'Loading configuration options',
446
+ AbandonLogEvent: 'Cannot log event, logging disabled or developer token not set',
447
+ AbandonAliasUsers: 'Cannot Alias Users, logging disabled or developer token not set',
448
+ AbandonStartSession: 'Cannot start session, logging disabled or developer token not set',
449
+ AbandonEndSession: 'Cannot end session, logging disabled or developer token not set',
450
+ NoSessionToEnd: 'Cannot end session, no active session found'
451
+ },
452
+ ValidationMessages: {
453
+ ModifyIdentityRequestUserIdentitiesPresent: 'identityRequests to modify require userIdentities to be present. Request not sent to server. Please fix and try again',
454
+ IdentityRequesetInvalidKey: 'There is an invalid key on your identityRequest object. It can only contain a `userIdentities` object and a `onUserAlias` function. Request not sent to server. Please fix and try again.',
455
+ OnUserAliasType: 'The onUserAlias value must be a function.',
456
+ UserIdentities: 'The userIdentities key must be an object with keys of identityTypes and values of strings. Request not sent to server. Please fix and try again.',
457
+ UserIdentitiesInvalidKey: 'There is an invalid identity key on your `userIdentities` object within the identityRequest. Request not sent to server. Please fix and try again.',
458
+ UserIdentitiesInvalidValues: 'All user identity values must be strings or null. Request not sent to server. Please fix and try again.',
459
+ AliasMissingMpid: 'Alias Request must contain both a destinationMpid and a sourceMpid',
460
+ AliasNonUniqueMpid: "Alias Request's destinationMpid and sourceMpid must be unique",
461
+ AliasMissingTime: 'Alias Request must have both a startTime and an endTime',
462
+ AliasStartBeforeEndTime: "Alias Request's endTime must be later than its startTime"
463
+ }
464
+ },
465
+ NativeSdkPaths: {
466
+ LogEvent: 'logEvent',
467
+ SetUserTag: 'setUserTag',
468
+ RemoveUserTag: 'removeUserTag',
469
+ SetUserAttribute: 'setUserAttribute',
470
+ RemoveUserAttribute: 'removeUserAttribute',
471
+ SetSessionAttribute: 'setSessionAttribute',
472
+ AddToCart: 'addToCart',
473
+ RemoveFromCart: 'removeFromCart',
474
+ ClearCart: 'clearCart',
475
+ LogOut: 'logOut',
476
+ SetUserAttributeList: 'setUserAttributeList',
477
+ RemoveAllUserAttributes: 'removeAllUserAttributes',
478
+ GetUserAttributesLists: 'getUserAttributesLists',
479
+ GetAllUserAttributes: 'getAllUserAttributes',
480
+ Identify: 'identify',
481
+ Logout: 'logout',
482
+ Login: 'login',
483
+ Modify: 'modify',
484
+ Alias: 'aliasUsers',
485
+ Upload: 'upload'
486
+ },
487
+ StorageNames: {
488
+ localStorageName: 'mprtcl-api',
489
+ localStorageNameV3: 'mprtcl-v3',
490
+ cookieName: 'mprtcl-api',
491
+ cookieNameV2: 'mprtcl-v2',
492
+ cookieNameV3: 'mprtcl-v3',
493
+ localStorageNameV4: 'mprtcl-v4',
494
+ localStorageProductsV4: 'mprtcl-prodv4',
495
+ cookieNameV4: 'mprtcl-v4',
496
+ currentStorageName: 'mprtcl-v4',
497
+ currentStorageProductsName: 'mprtcl-prodv4'
498
+ },
499
+ DefaultConfig: {
500
+ cookieDomain: null,
501
+ cookieExpiration: 365,
502
+ logLevel: null,
503
+ timeout: 300,
504
+ sessionTimeout: 30,
505
+ maxProducts: 20,
506
+ forwarderStatsTimeout: 5000,
507
+ integrationDelayTimeout: 5000,
508
+ maxCookieSize: 3000,
509
+ aliasMaxWindow: 90,
510
+ uploadInterval: 0 // Maximum milliseconds in between batch uploads, below 500 will mean immediate upload. The server returns this as a string, but we are using it as a number internally
511
+ },
512
+
513
+ DefaultBaseUrls: {
514
+ v1SecureServiceUrl: 'jssdks.mparticle.com/v1/JS/',
515
+ v2SecureServiceUrl: 'jssdks.mparticle.com/v2/JS/',
516
+ v3SecureServiceUrl: 'jssdks.mparticle.com/v3/JS/',
517
+ configUrl: 'jssdkcdns.mparticle.com/JS/v2/',
518
+ identityUrl: 'identity.mparticle.com/v1/',
519
+ aliasUrl: 'jssdks.mparticle.com/v1/identity/',
520
+ userAudienceUrl: 'nativesdks.mparticle.com/v1/'
521
+ },
522
+ Base64CookieKeys: {
523
+ csm: 1,
524
+ sa: 1,
525
+ ss: 1,
526
+ ua: 1,
527
+ ui: 1,
528
+ csd: 1,
529
+ ia: 1,
530
+ con: 1
531
+ },
532
+ // https://go.mparticle.com/work/SQDSDKS-6039
533
+ SDKv2NonMPIDCookieKeys: {
534
+ gs: 1,
535
+ cu: 1,
536
+ l: 1,
537
+ globalSettings: 1,
538
+ currentUserMPID: 1
539
+ },
540
+ HTTPCodes: {
541
+ noHttpCoverage: -1,
542
+ activeIdentityRequest: -2,
543
+ activeSession: -3,
544
+ validationIssue: -4,
545
+ nativeIdentityRequest: -5,
546
+ loggingDisabledOrMissingAPIKey: -6,
547
+ tooManyRequests: 429
548
+ },
549
+ FeatureFlags: {
550
+ ReportBatching: 'reportBatching',
551
+ EventBatchingIntervalMillis: 'eventBatchingIntervalMillis',
552
+ OfflineStorage: 'offlineStorage',
553
+ DirectUrlRouting: 'directURLRouting',
554
+ CacheIdentity: 'cacheIdentity',
555
+ AudienceAPI: 'audienceAPI'
556
+ },
557
+ DefaultInstance: 'default_instance',
558
+ CCPAPurpose: 'data_sale_opt_out',
559
+ IdentityMethods: {
560
+ Modify: 'modify',
561
+ Logout: 'logout',
562
+ Login: 'login',
563
+ Identify: 'identify'
564
+ }
565
+ };
566
+ // https://go.mparticle.com/work/SQDSDKS-6080
567
+ var ONE_DAY_IN_SECONDS = 60 * 60 * 24;
568
+ var MILLIS_IN_ONE_SEC = 1000;
569
+
570
+ var Messages$9 = Constants.Messages;
571
+ var createCookieString = function createCookieString(value) {
572
+ return replaceCommasWithPipes(replaceQuotesWithApostrophes(value));
573
+ };
574
+ var revertCookieString = function revertCookieString(value) {
575
+ return replacePipesWithCommas(replaceApostrophesWithQuotes(value));
576
+ };
577
+ var inArray = function inArray(items, name) {
578
+ var i = 0;
579
+ if (Array.prototype.indexOf) {
580
+ return items.indexOf(name, 0) >= 0;
581
+ } else {
582
+ for (var n = items.length; i < n; i++) {
583
+ if (i in items && items[i] === name) {
584
+ return true;
585
+ }
586
+ }
587
+ }
588
+ return false;
589
+ };
590
+ var findKeyInObject = function findKeyInObject(obj, key) {
591
+ if (key && obj) {
592
+ for (var prop in obj) {
593
+ if (obj.hasOwnProperty(prop) && prop.toLowerCase() === key.toLowerCase()) {
594
+ return prop;
595
+ }
596
+ }
597
+ }
598
+ return null;
599
+ };
600
+ var generateDeprecationMessage = function generateDeprecationMessage(methodName, alternateMethod) {
601
+ var messageArray = [methodName, Messages$9.DeprecationMessages.MethodIsDeprecatedPostfix];
602
+ if (alternateMethod) {
603
+ messageArray.push(alternateMethod);
604
+ messageArray.push(Messages$9.DeprecationMessages.MethodIsDeprecatedPostfix);
605
+ }
606
+ return messageArray.join(' ');
607
+ };
608
+ function generateHash(name) {
609
+ var hash = 0;
610
+ var character;
611
+ if (name === undefined || name === null) {
612
+ return 0;
613
+ }
614
+ name = name.toString().toLowerCase();
615
+ if (Array.prototype.reduce) {
616
+ return name.split('').reduce(function (a, b) {
617
+ a = (a << 5) - a + b.charCodeAt(0);
618
+ return a & a;
619
+ }, 0);
620
+ }
621
+ if (name.length === 0) {
622
+ return hash;
623
+ }
624
+ for (var i = 0; i < name.length; i++) {
625
+ character = name.charCodeAt(i);
626
+ hash = (hash << 5) - hash + character;
627
+ hash = hash & hash;
628
+ }
629
+ return hash;
630
+ }
631
+ var generateRandomValue = function generateRandomValue(value) {
632
+ var randomValue;
633
+ var a;
634
+ if (window.crypto && window.crypto.getRandomValues) {
635
+ // @ts-ignore
636
+ randomValue = window.crypto.getRandomValues(new Uint8Array(1)); // eslint-disable-line no-undef
637
+ }
638
+
639
+ if (randomValue) {
640
+ // @ts-ignore
641
+ return (a ^ randomValue[0] % 16 >> a / 4).toString(16);
642
+ }
643
+ return (a ^ Math.random() * 16 >> a / 4).toString(16);
644
+ };
645
+ var generateUniqueId = function generateUniqueId(a) {
646
+ // https://gist.github.com/jed/982883
647
+ // Added support for crypto for better random
648
+ if (a === void 0) {
649
+ a = '';
650
+ }
651
+ return a // if the placeholder was passed, return
652
+ ? generateRandomValue() // if the placeholder was passed, return
653
+ :
654
+ // [1e7] -> // 10000000 +
655
+ // -1e3 -> // -1000 +
656
+ // -4e3 -> // -4000 +
657
+ // -8e3 -> // -80000000 +
658
+ // -1e11 -> //-100000000000,
659
+ "".concat(1e7, "-").concat(1e3, "-").concat(4e3, "-").concat(8e3, "-").concat(1e11).replace(/[018]/g,
660
+ // zeroes, ones, and eights with
661
+ generateUniqueId // random hex digits
662
+ );
663
+ };
664
+ /**
665
+ * Returns a value between 1-100 inclusive.
666
+ */
667
+ var getRampNumber = function getRampNumber(value) {
668
+ if (!value) {
669
+ return 100;
670
+ }
671
+ var hash = generateHash(value);
672
+ return Math.abs(hash % 100) + 1;
673
+ };
674
+ var isObject = function isObject(value) {
675
+ var objType = Object.prototype.toString.call(value);
676
+ return objType === '[object Object]' || objType === '[object Error]';
677
+ };
678
+ var parseNumber = function parseNumber(value) {
679
+ if (isNaN(value) || !isFinite(value)) {
680
+ return 0;
681
+ }
682
+ var floatValue = parseFloat(value);
683
+ return isNaN(floatValue) ? 0 : floatValue;
684
+ };
685
+ var parseStringOrNumber = function parseStringOrNumber(value) {
686
+ if (isStringOrNumber(value)) {
687
+ return value;
688
+ } else {
689
+ return null;
690
+ }
691
+ };
692
+ var replaceCommasWithPipes = function replaceCommasWithPipes(value) {
693
+ return value.replace(/,/g, '|');
694
+ };
695
+ var replacePipesWithCommas = function replacePipesWithCommas(value) {
696
+ return value.replace(/\|/g, ',');
697
+ };
698
+ var replaceApostrophesWithQuotes = function replaceApostrophesWithQuotes(value) {
699
+ return value.replace(/\'/g, '"');
700
+ };
701
+ var replaceQuotesWithApostrophes = function replaceQuotesWithApostrophes(value) {
702
+ return value.replace(/\"/g, "'");
703
+ };
704
+ // FIXME: REFACTOR for V3
705
+ // only used in store.js to sanitize server-side formatting of
706
+ // booleans when checking for `isDevelopmentMode`
707
+ // Should be removed in v3
708
+ var returnConvertedBoolean = function returnConvertedBoolean(data) {
709
+ if (data === 'false' || data === '0') {
710
+ return false;
711
+ } else {
712
+ return Boolean(data);
713
+ }
714
+ };
715
+ var decoded = function decoded(s) {
716
+ return decodeURIComponent(s.replace(/\+/g, ' '));
717
+ };
718
+ var converted = function converted(s) {
719
+ if (s.indexOf('"') === 0) {
720
+ s = s.slice(1, -1).replace(/\\"/g, '"').replace(/\\\\/g, '\\');
721
+ }
722
+ return s;
723
+ };
724
+ var isString = function isString(value) {
725
+ return typeof value === 'string';
726
+ };
727
+ var isNumber = function isNumber(value) {
728
+ return typeof value === 'number';
729
+ };
730
+ var isBoolean = function isBoolean(value) {
731
+ return typeof value === 'boolean';
732
+ };
733
+ var isFunction = function isFunction(fn) {
734
+ return typeof fn === 'function';
735
+ };
736
+ var isValidCustomFlagProperty = function isValidCustomFlagProperty(value) {
737
+ return isNumber(value) || isString(value) || isBoolean(value);
738
+ };
739
+ var toDataPlanSlug = function toDataPlanSlug(value) {
740
+ // Make sure we are only acting on strings or numbers
741
+ return isStringOrNumber(value) ? value.toString().toLowerCase().replace(/[^0-9a-zA-Z]+/g, '_') : '';
742
+ };
743
+ var isDataPlanSlug = function isDataPlanSlug(str) {
744
+ return str === toDataPlanSlug(str);
745
+ };
746
+ var isStringOrNumber = function isStringOrNumber(value) {
747
+ return isString(value) || isNumber(value);
748
+ };
749
+ var isEmpty = function isEmpty(value) {
750
+ return value == null || !(Object.keys(value) || value).length;
751
+ };
752
+ var moveElementToEnd = function moveElementToEnd(array, index) {
753
+ return array.slice(0, index).concat(array.slice(index + 1), array[index]);
754
+ };
755
+
756
+ function getNewIdentitiesByName(newIdentitiesByType) {
757
+ var newIdentitiesByName = {};
758
+ for (var key in newIdentitiesByType) {
759
+ var identityNameKey = getIdentityName(parseNumber(key));
760
+ newIdentitiesByName[identityNameKey] = newIdentitiesByType[key];
761
+ }
762
+ return newIdentitiesByName;
763
+ }
764
+ function getIdentityName(identityType) {
765
+ switch (identityType) {
766
+ case IdentityType$1.Other:
767
+ return 'other';
768
+ case IdentityType$1.CustomerId:
769
+ return 'customerid';
770
+ case IdentityType$1.Facebook:
771
+ return 'facebook';
772
+ case IdentityType$1.Twitter:
773
+ return 'twitter';
774
+ case IdentityType$1.Google:
775
+ return 'google';
776
+ case IdentityType$1.Microsoft:
777
+ return 'microsoft';
778
+ case IdentityType$1.Yahoo:
779
+ return 'yahoo';
780
+ case IdentityType$1.Email:
781
+ return 'email';
782
+ case IdentityType$1.FacebookCustomAudienceId:
783
+ return 'facebookcustomaudienceid';
784
+ case IdentityType$1.Other2:
785
+ return 'other2';
786
+ case IdentityType$1.Other3:
787
+ return 'other3';
788
+ case IdentityType$1.Other4:
789
+ return 'other4';
790
+ case IdentityType$1.Other5:
791
+ return 'other5';
792
+ case IdentityType$1.Other6:
793
+ return 'other6';
794
+ case IdentityType$1.Other7:
795
+ return 'other7';
796
+ case IdentityType$1.Other8:
797
+ return 'other8';
798
+ case IdentityType$1.Other9:
799
+ return 'other9';
800
+ case IdentityType$1.Other10:
801
+ return 'other10';
802
+ case IdentityType$1.MobileNumber:
803
+ return 'mobile_number';
804
+ case IdentityType$1.PhoneNumber2:
805
+ return 'phone_number_2';
806
+ case IdentityType$1.PhoneNumber3:
807
+ return 'phone_number_3';
808
+ default:
809
+ return null;
810
+ }
811
+ }
812
+
247
813
  var _TriggerUploadType;
248
- var MessageType$2 = {
814
+ var MessageType$1 = {
249
815
  SessionStart: 1,
250
816
  SessionEnd: 2,
251
817
  PageView: 3,
@@ -262,7 +828,7 @@ var mParticle = (function () {
262
828
 
263
829
  // Dictionary that contains MessageTypes that will
264
830
  // trigger an immediate upload.
265
- var TriggerUploadType = (_TriggerUploadType = {}, _defineProperty(_TriggerUploadType, MessageType$2.Commerce, 1), _defineProperty(_TriggerUploadType, MessageType$2.UserIdentityChange, 1), _TriggerUploadType);
831
+ var TriggerUploadType = (_TriggerUploadType = {}, _defineProperty(_TriggerUploadType, MessageType$1.Commerce, 1), _defineProperty(_TriggerUploadType, MessageType$1.UserIdentityChange, 1), _TriggerUploadType);
266
832
  var EventType = {
267
833
  Unknown: 0,
268
834
  Navigation: 1,
@@ -301,580 +867,268 @@ var mParticle = (function () {
301
867
  case CommerceEventType.ProductCheckoutOption:
302
868
  return 'Product Checkout Options';
303
869
  case CommerceEventType.ProductClick:
304
- return 'Product Click';
305
- case CommerceEventType.ProductImpression:
306
- return 'Product Impression';
307
- case CommerceEventType.ProductPurchase:
308
- return 'Product Purchased';
309
- case CommerceEventType.ProductRefund:
310
- return 'Product Refunded';
311
- case CommerceEventType.ProductRemoveFromCart:
312
- return 'Product Removed From Cart';
313
- case CommerceEventType.ProductRemoveFromWishlist:
314
- return 'Product Removed from Wishlist';
315
- case CommerceEventType.ProductViewDetail:
316
- return 'Product View Details';
317
- case CommerceEventType.PromotionClick:
318
- return 'Promotion Click';
319
- case CommerceEventType.PromotionView:
320
- return 'Promotion View';
321
- default:
322
- return 'Other';
323
- }
324
- }
325
- };
326
-
327
- // Continuation of enum above, but in seperate object since we don't expose these to end user
328
- var CommerceEventType = {
329
- ProductAddToCart: 10,
330
- ProductRemoveFromCart: 11,
331
- ProductCheckout: 12,
332
- ProductCheckoutOption: 13,
333
- ProductClick: 14,
334
- ProductViewDetail: 15,
335
- ProductPurchase: 16,
336
- ProductRefund: 17,
337
- PromotionView: 18,
338
- PromotionClick: 19,
339
- ProductAddToWishlist: 20,
340
- ProductRemoveFromWishlist: 21,
341
- ProductImpression: 22
342
- };
343
- var IdentityType$1 = {
344
- Other: 0,
345
- CustomerId: 1,
346
- Facebook: 2,
347
- Twitter: 3,
348
- Google: 4,
349
- Microsoft: 5,
350
- Yahoo: 6,
351
- Email: 7,
352
- FacebookCustomAudienceId: 9,
353
- Other2: 10,
354
- Other3: 11,
355
- Other4: 12,
356
- Other5: 13,
357
- Other6: 14,
358
- Other7: 15,
359
- Other8: 16,
360
- Other9: 17,
361
- Other10: 18,
362
- MobileNumber: 19,
363
- PhoneNumber2: 20,
364
- PhoneNumber3: 21
365
- };
366
- IdentityType$1.isValid = function (identityType) {
367
- if (typeof identityType === 'number') {
368
- for (var prop in IdentityType$1) {
369
- if (IdentityType$1.hasOwnProperty(prop)) {
370
- if (IdentityType$1[prop] === identityType) {
371
- return true;
372
- }
373
- }
374
- }
375
- }
376
- return false;
377
- };
378
- IdentityType$1.getName = function (identityType) {
379
- switch (identityType) {
380
- case window.mParticle.IdentityType.CustomerId:
381
- return 'Customer ID';
382
- case window.mParticle.IdentityType.Facebook:
383
- return 'Facebook ID';
384
- case window.mParticle.IdentityType.Twitter:
385
- return 'Twitter ID';
386
- case window.mParticle.IdentityType.Google:
387
- return 'Google ID';
388
- case window.mParticle.IdentityType.Microsoft:
389
- return 'Microsoft ID';
390
- case window.mParticle.IdentityType.Yahoo:
391
- return 'Yahoo ID';
392
- case window.mParticle.IdentityType.Email:
393
- return 'Email';
394
- case window.mParticle.IdentityType.FacebookCustomAudienceId:
395
- return 'Facebook App User ID';
396
- default:
397
- return 'Other ID';
398
- }
399
- };
400
- IdentityType$1.getIdentityType = function (identityName) {
401
- switch (identityName) {
402
- case 'other':
403
- return IdentityType$1.Other;
404
- case 'customerid':
405
- return IdentityType$1.CustomerId;
406
- case 'facebook':
407
- return IdentityType$1.Facebook;
408
- case 'twitter':
409
- return IdentityType$1.Twitter;
410
- case 'google':
411
- return IdentityType$1.Google;
412
- case 'microsoft':
413
- return IdentityType$1.Microsoft;
414
- case 'yahoo':
415
- return IdentityType$1.Yahoo;
416
- case 'email':
417
- return IdentityType$1.Email;
418
- case 'facebookcustomaudienceid':
419
- return IdentityType$1.FacebookCustomAudienceId;
420
- case 'other2':
421
- return IdentityType$1.Other2;
422
- case 'other3':
423
- return IdentityType$1.Other3;
424
- case 'other4':
425
- return IdentityType$1.Other4;
426
- case 'other5':
427
- return IdentityType$1.Other5;
428
- case 'other6':
429
- return IdentityType$1.Other6;
430
- case 'other7':
431
- return IdentityType$1.Other7;
432
- case 'other8':
433
- return IdentityType$1.Other8;
434
- case 'other9':
435
- return IdentityType$1.Other9;
436
- case 'other10':
437
- return IdentityType$1.Other10;
438
- case 'mobile_number':
439
- return IdentityType$1.MobileNumber;
440
- case 'phone_number_2':
441
- return IdentityType$1.PhoneNumber2;
442
- case 'phone_number_3':
443
- return IdentityType$1.PhoneNumber3;
444
- default:
445
- return false;
446
- }
447
- };
448
- IdentityType$1.getIdentityName = function (identityType) {
449
- switch (identityType) {
450
- case IdentityType$1.Other:
451
- return 'other';
452
- case IdentityType$1.CustomerId:
453
- return 'customerid';
454
- case IdentityType$1.Facebook:
455
- return 'facebook';
456
- case IdentityType$1.Twitter:
457
- return 'twitter';
458
- case IdentityType$1.Google:
459
- return 'google';
460
- case IdentityType$1.Microsoft:
461
- return 'microsoft';
462
- case IdentityType$1.Yahoo:
463
- return 'yahoo';
464
- case IdentityType$1.Email:
465
- return 'email';
466
- case IdentityType$1.FacebookCustomAudienceId:
467
- return 'facebookcustomaudienceid';
468
- case IdentityType$1.Other2:
469
- return 'other2';
470
- case IdentityType$1.Other3:
471
- return 'other3';
472
- case IdentityType$1.Other4:
473
- return 'other4';
474
- case IdentityType$1.Other5:
475
- return 'other5';
476
- case IdentityType$1.Other6:
477
- return 'other6';
478
- case IdentityType$1.Other7:
479
- return 'other7';
480
- case IdentityType$1.Other8:
481
- return 'other8';
482
- case IdentityType$1.Other9:
483
- return 'other9';
484
- case IdentityType$1.Other10:
485
- return 'other10';
486
- case IdentityType$1.MobileNumber:
487
- return 'mobile_number';
488
- case IdentityType$1.PhoneNumber2:
489
- return 'phone_number_2';
490
- case IdentityType$1.PhoneNumber3:
491
- return 'phone_number_3';
492
- }
493
- };
494
- var ProductActionType = {
495
- Unknown: 0,
496
- AddToCart: 1,
497
- RemoveFromCart: 2,
498
- Checkout: 3,
499
- CheckoutOption: 4,
500
- Click: 5,
501
- ViewDetail: 6,
502
- Purchase: 7,
503
- Refund: 8,
504
- AddToWishlist: 9,
505
- RemoveFromWishlist: 10
506
- };
507
- ProductActionType.getName = function (id) {
508
- switch (id) {
509
- case ProductActionType.AddToCart:
510
- return 'Add to Cart';
511
- case ProductActionType.RemoveFromCart:
512
- return 'Remove from Cart';
513
- case ProductActionType.Checkout:
514
- return 'Checkout';
515
- case ProductActionType.CheckoutOption:
516
- return 'Checkout Option';
517
- case ProductActionType.Click:
518
- return 'Click';
519
- case ProductActionType.ViewDetail:
520
- return 'View Detail';
521
- case ProductActionType.Purchase:
522
- return 'Purchase';
523
- case ProductActionType.Refund:
524
- return 'Refund';
525
- case ProductActionType.AddToWishlist:
526
- return 'Add to Wishlist';
527
- case ProductActionType.RemoveFromWishlist:
528
- return 'Remove from Wishlist';
529
- default:
530
- return 'Unknown';
531
- }
532
- };
533
-
534
- // these are the action names used by server and mobile SDKs when expanding a CommerceEvent
535
- ProductActionType.getExpansionName = function (id) {
536
- switch (id) {
537
- case ProductActionType.AddToCart:
538
- return 'add_to_cart';
539
- case ProductActionType.RemoveFromCart:
540
- return 'remove_from_cart';
541
- case ProductActionType.Checkout:
542
- return 'checkout';
543
- case ProductActionType.CheckoutOption:
544
- return 'checkout_option';
545
- case ProductActionType.Click:
546
- return 'click';
547
- case ProductActionType.ViewDetail:
548
- return 'view_detail';
549
- case ProductActionType.Purchase:
550
- return 'purchase';
551
- case ProductActionType.Refund:
552
- return 'refund';
553
- case ProductActionType.AddToWishlist:
554
- return 'add_to_wishlist';
555
- case ProductActionType.RemoveFromWishlist:
556
- return 'remove_from_wishlist';
557
- default:
558
- return 'unknown';
870
+ return 'Product Click';
871
+ case CommerceEventType.ProductImpression:
872
+ return 'Product Impression';
873
+ case CommerceEventType.ProductPurchase:
874
+ return 'Product Purchased';
875
+ case CommerceEventType.ProductRefund:
876
+ return 'Product Refunded';
877
+ case CommerceEventType.ProductRemoveFromCart:
878
+ return 'Product Removed From Cart';
879
+ case CommerceEventType.ProductRemoveFromWishlist:
880
+ return 'Product Removed from Wishlist';
881
+ case CommerceEventType.ProductViewDetail:
882
+ return 'Product View Details';
883
+ case CommerceEventType.PromotionClick:
884
+ return 'Promotion Click';
885
+ case CommerceEventType.PromotionView:
886
+ return 'Promotion View';
887
+ default:
888
+ return 'Other';
889
+ }
559
890
  }
560
891
  };
561
- var PromotionActionType = {
562
- Unknown: 0,
563
- PromotionView: 1,
564
- PromotionClick: 2
892
+
893
+ // Continuation of enum above, but in seperate object since we don't expose these to end user
894
+ var CommerceEventType = {
895
+ ProductAddToCart: 10,
896
+ ProductRemoveFromCart: 11,
897
+ ProductCheckout: 12,
898
+ ProductCheckoutOption: 13,
899
+ ProductClick: 14,
900
+ ProductViewDetail: 15,
901
+ ProductPurchase: 16,
902
+ ProductRefund: 17,
903
+ PromotionView: 18,
904
+ PromotionClick: 19,
905
+ ProductAddToWishlist: 20,
906
+ ProductRemoveFromWishlist: 21,
907
+ ProductImpression: 22
565
908
  };
566
- PromotionActionType.getName = function (id) {
567
- switch (id) {
568
- case PromotionActionType.PromotionView:
569
- return 'view';
570
- case PromotionActionType.PromotionClick:
571
- return 'click';
572
- default:
573
- return 'unknown';
909
+ var IdentityType = {
910
+ Other: 0,
911
+ CustomerId: 1,
912
+ Facebook: 2,
913
+ Twitter: 3,
914
+ Google: 4,
915
+ Microsoft: 5,
916
+ Yahoo: 6,
917
+ Email: 7,
918
+ FacebookCustomAudienceId: 9,
919
+ Other2: 10,
920
+ Other3: 11,
921
+ Other4: 12,
922
+ Other5: 13,
923
+ Other6: 14,
924
+ Other7: 15,
925
+ Other8: 16,
926
+ Other9: 17,
927
+ Other10: 18,
928
+ MobileNumber: 19,
929
+ PhoneNumber2: 20,
930
+ PhoneNumber3: 21
931
+ };
932
+ IdentityType.isValid = function (identityType) {
933
+ if (typeof identityType === 'number') {
934
+ for (var prop in IdentityType) {
935
+ if (IdentityType.hasOwnProperty(prop)) {
936
+ if (IdentityType[prop] === identityType) {
937
+ return true;
938
+ }
939
+ }
940
+ }
574
941
  }
942
+ return false;
575
943
  };
576
-
577
- // these are the names that the server and mobile SDKs use while expanding CommerceEvent
578
- PromotionActionType.getExpansionName = function (id) {
579
- switch (id) {
580
- case PromotionActionType.PromotionView:
581
- return 'view';
582
- case PromotionActionType.PromotionClick:
583
- return 'click';
944
+ IdentityType.getName = function (identityType) {
945
+ switch (identityType) {
946
+ case window.mParticle.IdentityType.CustomerId:
947
+ return 'Customer ID';
948
+ case window.mParticle.IdentityType.Facebook:
949
+ return 'Facebook ID';
950
+ case window.mParticle.IdentityType.Twitter:
951
+ return 'Twitter ID';
952
+ case window.mParticle.IdentityType.Google:
953
+ return 'Google ID';
954
+ case window.mParticle.IdentityType.Microsoft:
955
+ return 'Microsoft ID';
956
+ case window.mParticle.IdentityType.Yahoo:
957
+ return 'Yahoo ID';
958
+ case window.mParticle.IdentityType.Email:
959
+ return 'Email';
960
+ case window.mParticle.IdentityType.FacebookCustomAudienceId:
961
+ return 'Facebook App User ID';
584
962
  default:
585
- return 'unknown';
963
+ return 'Other ID';
964
+ }
965
+ };
966
+ IdentityType.getIdentityType = function (identityName) {
967
+ switch (identityName) {
968
+ case 'other':
969
+ return IdentityType.Other;
970
+ case 'customerid':
971
+ return IdentityType.CustomerId;
972
+ case 'facebook':
973
+ return IdentityType.Facebook;
974
+ case 'twitter':
975
+ return IdentityType.Twitter;
976
+ case 'google':
977
+ return IdentityType.Google;
978
+ case 'microsoft':
979
+ return IdentityType.Microsoft;
980
+ case 'yahoo':
981
+ return IdentityType.Yahoo;
982
+ case 'email':
983
+ return IdentityType.Email;
984
+ case 'facebookcustomaudienceid':
985
+ return IdentityType.FacebookCustomAudienceId;
986
+ case 'other2':
987
+ return IdentityType.Other2;
988
+ case 'other3':
989
+ return IdentityType.Other3;
990
+ case 'other4':
991
+ return IdentityType.Other4;
992
+ case 'other5':
993
+ return IdentityType.Other5;
994
+ case 'other6':
995
+ return IdentityType.Other6;
996
+ case 'other7':
997
+ return IdentityType.Other7;
998
+ case 'other8':
999
+ return IdentityType.Other8;
1000
+ case 'other9':
1001
+ return IdentityType.Other9;
1002
+ case 'other10':
1003
+ return IdentityType.Other10;
1004
+ case 'mobile_number':
1005
+ return IdentityType.MobileNumber;
1006
+ case 'phone_number_2':
1007
+ return IdentityType.PhoneNumber2;
1008
+ case 'phone_number_3':
1009
+ return IdentityType.PhoneNumber3;
1010
+ default:
1011
+ return false;
1012
+ }
1013
+ };
1014
+ IdentityType.getIdentityName = function (identityType) {
1015
+ return getIdentityName(identityType);
1016
+ };
1017
+ var ProductActionType = {
1018
+ Unknown: 0,
1019
+ AddToCart: 1,
1020
+ RemoveFromCart: 2,
1021
+ Checkout: 3,
1022
+ CheckoutOption: 4,
1023
+ Click: 5,
1024
+ ViewDetail: 6,
1025
+ Purchase: 7,
1026
+ Refund: 8,
1027
+ AddToWishlist: 9,
1028
+ RemoveFromWishlist: 10
1029
+ };
1030
+ ProductActionType.getName = function (id) {
1031
+ switch (id) {
1032
+ case ProductActionType.AddToCart:
1033
+ return 'Add to Cart';
1034
+ case ProductActionType.RemoveFromCart:
1035
+ return 'Remove from Cart';
1036
+ case ProductActionType.Checkout:
1037
+ return 'Checkout';
1038
+ case ProductActionType.CheckoutOption:
1039
+ return 'Checkout Option';
1040
+ case ProductActionType.Click:
1041
+ return 'Click';
1042
+ case ProductActionType.ViewDetail:
1043
+ return 'View Detail';
1044
+ case ProductActionType.Purchase:
1045
+ return 'Purchase';
1046
+ case ProductActionType.Refund:
1047
+ return 'Refund';
1048
+ case ProductActionType.AddToWishlist:
1049
+ return 'Add to Wishlist';
1050
+ case ProductActionType.RemoveFromWishlist:
1051
+ return 'Remove from Wishlist';
1052
+ default:
1053
+ return 'Unknown';
586
1054
  }
587
1055
  };
588
- var ProfileMessageType = {
589
- Logout: 3
590
- };
591
- var ApplicationTransitionType$1 = {
592
- AppInit: 1
593
- };
594
- var Environment = {
595
- Production: 'production',
596
- Development: 'development'
597
- };
598
- var Types = {
599
- MessageType: MessageType$2,
600
- EventType: EventType,
601
- CommerceEventType: CommerceEventType,
602
- IdentityType: IdentityType$1,
603
- ProfileMessageType: ProfileMessageType,
604
- ApplicationTransitionType: ApplicationTransitionType$1,
605
- ProductActionType: ProductActionType,
606
- PromotionActionType: PromotionActionType,
607
- TriggerUploadType: TriggerUploadType,
608
- Environment: Environment
609
- };
610
-
611
- var version = "2.26.0";
612
-
613
- var Constants = {
614
- sdkVersion: version,
615
- sdkVendor: 'mparticle',
616
- platform: 'web',
617
- Messages: {
618
- DeprecationMessages: {
619
- MethodIsDeprecatedPostfix: 'is a deprecated method and will be removed in future releases',
620
- AlternativeMethodPrefix: 'Please use the alternate method:'
621
- },
622
- ErrorMessages: {
623
- NoToken: 'A token must be specified.',
624
- EventNameInvalidType: 'Event name must be a valid string value.',
625
- EventDataInvalidType: 'Event data must be a valid object hash.',
626
- LoggingDisabled: 'Event logging is currently disabled.',
627
- CookieParseError: 'Could not parse cookie',
628
- EventEmpty: 'Event object is null or undefined, cancelling send',
629
- APIRequestEmpty: 'APIRequest is null or undefined, cancelling send',
630
- NoEventType: 'Event type must be specified.',
631
- TransactionIdRequired: 'Transaction ID is required',
632
- TransactionRequired: 'A transaction attributes object is required',
633
- PromotionIdRequired: 'Promotion ID is required',
634
- BadAttribute: 'Attribute value cannot be object or array',
635
- BadKey: 'Key value cannot be object or array',
636
- BadLogPurchase: 'Transaction attributes and a product are both required to log a purchase, https://docs.mparticle.com/?javascript#measuring-transactions',
637
- AudienceAPINotEnabled: 'Your workspace is not enabled to retrieve user audiences.'
638
- },
639
- InformationMessages: {
640
- CookieSearch: 'Searching for cookie',
641
- CookieFound: 'Cookie found, parsing values',
642
- CookieNotFound: 'Cookies not found',
643
- CookieSet: 'Setting cookie',
644
- CookieSync: 'Performing cookie sync',
645
- SendBegin: 'Starting to send event',
646
- SendIdentityBegin: 'Starting to send event to identity server',
647
- SendWindowsPhone: 'Sending event to Windows Phone container',
648
- SendIOS: 'Calling iOS path: ',
649
- SendAndroid: 'Calling Android JS interface method: ',
650
- SendHttp: 'Sending event to mParticle HTTP service',
651
- SendAliasHttp: 'Sending alias request to mParticle HTTP service',
652
- SendIdentityHttp: 'Sending event to mParticle HTTP service',
653
- StartingNewSession: 'Starting new Session',
654
- StartingLogEvent: 'Starting to log event',
655
- StartingLogOptOut: 'Starting to log user opt in/out',
656
- StartingEndSession: 'Starting to end session',
657
- StartingInitialization: 'Starting to initialize',
658
- StartingLogCommerceEvent: 'Starting to log commerce event',
659
- StartingAliasRequest: 'Starting to Alias MPIDs',
660
- LoadingConfig: 'Loading configuration options',
661
- AbandonLogEvent: 'Cannot log event, logging disabled or developer token not set',
662
- AbandonAliasUsers: 'Cannot Alias Users, logging disabled or developer token not set',
663
- AbandonStartSession: 'Cannot start session, logging disabled or developer token not set',
664
- AbandonEndSession: 'Cannot end session, logging disabled or developer token not set',
665
- NoSessionToEnd: 'Cannot end session, no active session found'
666
- },
667
- ValidationMessages: {
668
- ModifyIdentityRequestUserIdentitiesPresent: 'identityRequests to modify require userIdentities to be present. Request not sent to server. Please fix and try again',
669
- IdentityRequesetInvalidKey: 'There is an invalid key on your identityRequest object. It can only contain a `userIdentities` object and a `onUserAlias` function. Request not sent to server. Please fix and try again.',
670
- OnUserAliasType: 'The onUserAlias value must be a function.',
671
- UserIdentities: 'The userIdentities key must be an object with keys of identityTypes and values of strings. Request not sent to server. Please fix and try again.',
672
- UserIdentitiesInvalidKey: 'There is an invalid identity key on your `userIdentities` object within the identityRequest. Request not sent to server. Please fix and try again.',
673
- UserIdentitiesInvalidValues: 'All user identity values must be strings or null. Request not sent to server. Please fix and try again.',
674
- AliasMissingMpid: 'Alias Request must contain both a destinationMpid and a sourceMpid',
675
- AliasNonUniqueMpid: "Alias Request's destinationMpid and sourceMpid must be unique",
676
- AliasMissingTime: 'Alias Request must have both a startTime and an endTime',
677
- AliasStartBeforeEndTime: "Alias Request's endTime must be later than its startTime"
678
- }
679
- },
680
- NativeSdkPaths: {
681
- LogEvent: 'logEvent',
682
- SetUserTag: 'setUserTag',
683
- RemoveUserTag: 'removeUserTag',
684
- SetUserAttribute: 'setUserAttribute',
685
- RemoveUserAttribute: 'removeUserAttribute',
686
- SetSessionAttribute: 'setSessionAttribute',
687
- AddToCart: 'addToCart',
688
- RemoveFromCart: 'removeFromCart',
689
- ClearCart: 'clearCart',
690
- LogOut: 'logOut',
691
- SetUserAttributeList: 'setUserAttributeList',
692
- RemoveAllUserAttributes: 'removeAllUserAttributes',
693
- GetUserAttributesLists: 'getUserAttributesLists',
694
- GetAllUserAttributes: 'getAllUserAttributes',
695
- Identify: 'identify',
696
- Logout: 'logout',
697
- Login: 'login',
698
- Modify: 'modify',
699
- Alias: 'aliasUsers',
700
- Upload: 'upload'
701
- },
702
- StorageNames: {
703
- localStorageName: 'mprtcl-api',
704
- localStorageNameV3: 'mprtcl-v3',
705
- cookieName: 'mprtcl-api',
706
- cookieNameV2: 'mprtcl-v2',
707
- cookieNameV3: 'mprtcl-v3',
708
- localStorageNameV4: 'mprtcl-v4',
709
- localStorageProductsV4: 'mprtcl-prodv4',
710
- cookieNameV4: 'mprtcl-v4',
711
- currentStorageName: 'mprtcl-v4',
712
- currentStorageProductsName: 'mprtcl-prodv4'
713
- },
714
- DefaultConfig: {
715
- cookieDomain: null,
716
- cookieExpiration: 365,
717
- logLevel: null,
718
- timeout: 300,
719
- sessionTimeout: 30,
720
- maxProducts: 20,
721
- forwarderStatsTimeout: 5000,
722
- integrationDelayTimeout: 5000,
723
- maxCookieSize: 3000,
724
- aliasMaxWindow: 90,
725
- uploadInterval: 0 // Maximum milliseconds in between batch uploads, below 500 will mean immediate upload. The server returns this as a string, but we are using it as a number internally
726
- },
727
1056
 
728
- DefaultBaseUrls: {
729
- v1SecureServiceUrl: 'jssdks.mparticle.com/v1/JS/',
730
- v2SecureServiceUrl: 'jssdks.mparticle.com/v2/JS/',
731
- v3SecureServiceUrl: 'jssdks.mparticle.com/v3/JS/',
732
- configUrl: 'jssdkcdns.mparticle.com/JS/v2/',
733
- identityUrl: 'identity.mparticle.com/v1/',
734
- aliasUrl: 'jssdks.mparticle.com/v1/identity/',
735
- userAudienceUrl: 'nativesdks.mparticle.com/v1/'
736
- },
737
- Base64CookieKeys: {
738
- csm: 1,
739
- sa: 1,
740
- ss: 1,
741
- ua: 1,
742
- ui: 1,
743
- csd: 1,
744
- ia: 1,
745
- con: 1
746
- },
747
- // https://go.mparticle.com/work/SQDSDKS-6039
748
- SDKv2NonMPIDCookieKeys: {
749
- gs: 1,
750
- cu: 1,
751
- l: 1,
752
- globalSettings: 1,
753
- currentUserMPID: 1
754
- },
755
- HTTPCodes: {
756
- noHttpCoverage: -1,
757
- activeIdentityRequest: -2,
758
- activeSession: -3,
759
- validationIssue: -4,
760
- nativeIdentityRequest: -5,
761
- loggingDisabledOrMissingAPIKey: -6,
762
- tooManyRequests: 429
763
- },
764
- FeatureFlags: {
765
- ReportBatching: 'reportBatching',
766
- EventBatchingIntervalMillis: 'eventBatchingIntervalMillis',
767
- OfflineStorage: 'offlineStorage',
768
- DirectUrlRouting: 'directURLRouting',
769
- CacheIdentity: 'cacheIdentity',
770
- AudienceAPI: 'audienceAPI'
771
- },
772
- DefaultInstance: 'default_instance',
773
- CCPAPurpose: 'data_sale_opt_out',
774
- IdentityMethods: {
775
- Modify: 'modify',
776
- Logout: 'logout',
777
- Login: 'login',
778
- Identify: 'identify'
1057
+ // these are the action names used by server and mobile SDKs when expanding a CommerceEvent
1058
+ ProductActionType.getExpansionName = function (id) {
1059
+ switch (id) {
1060
+ case ProductActionType.AddToCart:
1061
+ return 'add_to_cart';
1062
+ case ProductActionType.RemoveFromCart:
1063
+ return 'remove_from_cart';
1064
+ case ProductActionType.Checkout:
1065
+ return 'checkout';
1066
+ case ProductActionType.CheckoutOption:
1067
+ return 'checkout_option';
1068
+ case ProductActionType.Click:
1069
+ return 'click';
1070
+ case ProductActionType.ViewDetail:
1071
+ return 'view_detail';
1072
+ case ProductActionType.Purchase:
1073
+ return 'purchase';
1074
+ case ProductActionType.Refund:
1075
+ return 'refund';
1076
+ case ProductActionType.AddToWishlist:
1077
+ return 'add_to_wishlist';
1078
+ case ProductActionType.RemoveFromWishlist:
1079
+ return 'remove_from_wishlist';
1080
+ default:
1081
+ return 'unknown';
1082
+ }
1083
+ };
1084
+ var PromotionActionType = {
1085
+ Unknown: 0,
1086
+ PromotionView: 1,
1087
+ PromotionClick: 2
1088
+ };
1089
+ PromotionActionType.getName = function (id) {
1090
+ switch (id) {
1091
+ case PromotionActionType.PromotionView:
1092
+ return 'view';
1093
+ case PromotionActionType.PromotionClick:
1094
+ return 'click';
1095
+ default:
1096
+ return 'unknown';
779
1097
  }
780
1098
  };
781
- // https://go.mparticle.com/work/SQDSDKS-6080
782
- var ONE_DAY_IN_SECONDS = 60 * 60 * 24;
783
- var MILLIS_IN_ONE_SEC = 1000;
784
1099
 
785
- /******************************************************************************
786
- Copyright (c) Microsoft Corporation.
787
-
788
- Permission to use, copy, modify, and/or distribute this software for any
789
- purpose with or without fee is hereby granted.
790
-
791
- THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
792
- REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
793
- AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
794
- INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
795
- LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
796
- OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
797
- PERFORMANCE OF THIS SOFTWARE.
798
- ***************************************************************************** */
799
- /* global Reflect, Promise, SuppressedError, Symbol */
800
-
801
- var extendStatics = function(d, b) {
802
- extendStatics = Object.setPrototypeOf ||
803
- ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
804
- function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
805
- return extendStatics(d, b);
806
- };
807
-
808
- function __extends(d, b) {
809
- if (typeof b !== "function" && b !== null)
810
- throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
811
- extendStatics(d, b);
812
- function __() { this.constructor = d; }
813
- d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
814
- }
815
-
816
- var __assign = function() {
817
- __assign = Object.assign || function __assign(t) {
818
- for (var s, i = 1, n = arguments.length; i < n; i++) {
819
- s = arguments[i];
820
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
821
- }
822
- return t;
823
- };
824
- return __assign.apply(this, arguments);
825
- };
826
-
827
- function __awaiter(thisArg, _arguments, P, generator) {
828
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
829
- return new (P || (P = Promise))(function (resolve, reject) {
830
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
831
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
832
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
833
- step((generator = generator.apply(thisArg, _arguments || [])).next());
834
- });
835
- }
836
-
837
- function __generator(thisArg, body) {
838
- var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
839
- return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
840
- function verb(n) { return function (v) { return step([n, v]); }; }
841
- function step(op) {
842
- if (f) throw new TypeError("Generator is already executing.");
843
- while (g && (g = 0, op[0] && (_ = 0)), _) try {
844
- if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
845
- if (y = 0, t) op = [op[0] & 2, t.value];
846
- switch (op[0]) {
847
- case 0: case 1: t = op; break;
848
- case 4: _.label++; return { value: op[1], done: false };
849
- case 5: _.label++; y = op[1]; op = [0]; continue;
850
- case 7: op = _.ops.pop(); _.trys.pop(); continue;
851
- default:
852
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
853
- if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
854
- if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
855
- if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
856
- if (t[2]) _.ops.pop();
857
- _.trys.pop(); continue;
858
- }
859
- op = body.call(thisArg, _);
860
- } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
861
- if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
862
- }
863
- }
864
-
865
- function __spreadArray(to, from, pack) {
866
- if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
867
- if (ar || !(i in from)) {
868
- if (!ar) ar = Array.prototype.slice.call(from, 0, i);
869
- ar[i] = from[i];
870
- }
871
- }
872
- return to.concat(ar || Array.prototype.slice.call(from));
873
- }
874
-
875
- typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
876
- var e = new Error(message);
877
- return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
1100
+ // these are the names that the server and mobile SDKs use while expanding CommerceEvent
1101
+ PromotionActionType.getExpansionName = function (id) {
1102
+ switch (id) {
1103
+ case PromotionActionType.PromotionView:
1104
+ return 'view';
1105
+ case PromotionActionType.PromotionClick:
1106
+ return 'click';
1107
+ default:
1108
+ return 'unknown';
1109
+ }
1110
+ };
1111
+ var ProfileMessageType = {
1112
+ Logout: 3
1113
+ };
1114
+ var ApplicationTransitionType$1 = {
1115
+ AppInit: 1
1116
+ };
1117
+ var Environment = {
1118
+ Production: 'production',
1119
+ Development: 'development'
1120
+ };
1121
+ var Types = {
1122
+ MessageType: MessageType$1,
1123
+ EventType: EventType,
1124
+ CommerceEventType: CommerceEventType,
1125
+ IdentityType: IdentityType,
1126
+ ProfileMessageType: ProfileMessageType,
1127
+ ApplicationTransitionType: ApplicationTransitionType$1,
1128
+ ProductActionType: ProductActionType,
1129
+ PromotionActionType: PromotionActionType,
1130
+ TriggerUploadType: TriggerUploadType,
1131
+ Environment: Environment
878
1132
  };
879
1133
 
880
1134
  var SDKProductActionType;
@@ -1083,252 +1337,69 @@ var mParticle = (function () {
1083
1337
  ProductActionActionEnum["checkoutOption"] = "checkout_option";
1084
1338
  ProductActionActionEnum["click"] = "click";
1085
1339
  ProductActionActionEnum["viewDetail"] = "view_detail";
1086
- ProductActionActionEnum["purchase"] = "purchase";
1087
- ProductActionActionEnum["refund"] = "refund";
1088
- ProductActionActionEnum["addToWishlist"] = "add_to_wishlist";
1089
- ProductActionActionEnum["removeFromWishlist"] = "remove_from_wish_list";
1090
- })(exports.ProductActionActionEnum || (exports.ProductActionActionEnum = {}));
1091
- (function (ProfileEventEventTypeEnum) {
1092
- ProfileEventEventTypeEnum["profile"] = "profile";
1093
- })(exports.ProfileEventEventTypeEnum || (exports.ProfileEventEventTypeEnum = {}));
1094
- (function (ProfileEventDataProfileEventTypeEnum) {
1095
- ProfileEventDataProfileEventTypeEnum["signup"] = "signup";
1096
- ProfileEventDataProfileEventTypeEnum["login"] = "login";
1097
- ProfileEventDataProfileEventTypeEnum["logout"] = "logout";
1098
- ProfileEventDataProfileEventTypeEnum["update"] = "update";
1099
- ProfileEventDataProfileEventTypeEnum["delete"] = "delete";
1100
- })(exports.ProfileEventDataProfileEventTypeEnum || (exports.ProfileEventDataProfileEventTypeEnum = {}));
1101
- (function (PromotionActionActionEnum) {
1102
- PromotionActionActionEnum["view"] = "view";
1103
- PromotionActionActionEnum["click"] = "click";
1104
- })(exports.PromotionActionActionEnum || (exports.PromotionActionActionEnum = {}));
1105
- (function (PushMessageEventEventTypeEnum) {
1106
- PushMessageEventEventTypeEnum["pushMessage"] = "push_message";
1107
- })(exports.PushMessageEventEventTypeEnum || (exports.PushMessageEventEventTypeEnum = {}));
1108
- (function (PushMessageEventDataPushMessageTypeEnum) {
1109
- PushMessageEventDataPushMessageTypeEnum["sent"] = "sent";
1110
- PushMessageEventDataPushMessageTypeEnum["received"] = "received";
1111
- PushMessageEventDataPushMessageTypeEnum["action"] = "action";
1112
- })(exports.PushMessageEventDataPushMessageTypeEnum || (exports.PushMessageEventDataPushMessageTypeEnum = {}));
1113
- (function (PushMessageEventDataApplicationStateEnum) {
1114
- PushMessageEventDataApplicationStateEnum["notRunning"] = "not_running";
1115
- PushMessageEventDataApplicationStateEnum["background"] = "background";
1116
- PushMessageEventDataApplicationStateEnum["foreground"] = "foreground";
1117
- })(exports.PushMessageEventDataApplicationStateEnum || (exports.PushMessageEventDataApplicationStateEnum = {}));
1118
- (function (PushMessageEventDataPushMessageBehaviorEnum) {
1119
- PushMessageEventDataPushMessageBehaviorEnum["received"] = "Received";
1120
- PushMessageEventDataPushMessageBehaviorEnum["directOpen"] = "DirectOpen";
1121
- PushMessageEventDataPushMessageBehaviorEnum["read"] = "Read";
1122
- PushMessageEventDataPushMessageBehaviorEnum["influencedOpen"] = "InfluencedOpen";
1123
- PushMessageEventDataPushMessageBehaviorEnum["displayed"] = "Displayed";
1124
- })(exports.PushMessageEventDataPushMessageBehaviorEnum || (exports.PushMessageEventDataPushMessageBehaviorEnum = {}));
1125
- (function (PushRegistrationEventEventTypeEnum) {
1126
- PushRegistrationEventEventTypeEnum["pushRegistration"] = "push_registration";
1127
- })(exports.PushRegistrationEventEventTypeEnum || (exports.PushRegistrationEventEventTypeEnum = {}));
1128
- (function (SessionEndEventEventTypeEnum) {
1129
- SessionEndEventEventTypeEnum["sessionEnd"] = "session_end";
1130
- })(exports.SessionEndEventEventTypeEnum || (exports.SessionEndEventEventTypeEnum = {}));
1131
- (function (SessionStartEventEventTypeEnum) {
1132
- SessionStartEventEventTypeEnum["sessionStart"] = "session_start";
1133
- })(exports.SessionStartEventEventTypeEnum || (exports.SessionStartEventEventTypeEnum = {}));
1134
- (function (SourceInformationChannelEnum) {
1135
- SourceInformationChannelEnum["native"] = "native";
1136
- SourceInformationChannelEnum["javascript"] = "javascript";
1137
- SourceInformationChannelEnum["pixel"] = "pixel";
1138
- SourceInformationChannelEnum["desktop"] = "desktop";
1139
- SourceInformationChannelEnum["partner"] = "partner";
1140
- SourceInformationChannelEnum["serverToServer"] = "server_to_server";
1141
- })(exports.SourceInformationChannelEnum || (exports.SourceInformationChannelEnum = {}));
1142
- (function (UserAttributeChangeEventEventTypeEnum) {
1143
- UserAttributeChangeEventEventTypeEnum["userAttributeChange"] = "user_attribute_change";
1144
- })(exports.UserAttributeChangeEventEventTypeEnum || (exports.UserAttributeChangeEventEventTypeEnum = {}));
1145
- (function (UserIdentityChangeEventEventTypeEnum) {
1146
- UserIdentityChangeEventEventTypeEnum["userIdentityChange"] = "user_identity_change";
1147
- })(exports.UserIdentityChangeEventEventTypeEnum || (exports.UserIdentityChangeEventEventTypeEnum = {}));
1148
- } (dist));
1149
-
1150
- var Messages$9 = Constants.Messages;
1151
- var createCookieString = function createCookieString(value) {
1152
- return replaceCommasWithPipes(replaceQuotesWithApostrophes(value));
1153
- };
1154
- var revertCookieString = function revertCookieString(value) {
1155
- return replacePipesWithCommas(replaceApostrophesWithQuotes(value));
1156
- };
1157
- var inArray = function inArray(items, name) {
1158
- var i = 0;
1159
- if (Array.prototype.indexOf) {
1160
- return items.indexOf(name, 0) >= 0;
1161
- } else {
1162
- for (var n = items.length; i < n; i++) {
1163
- if (i in items && items[i] === name) {
1164
- return true;
1165
- }
1166
- }
1167
- }
1168
- return false;
1169
- };
1170
- var findKeyInObject = function findKeyInObject(obj, key) {
1171
- if (key && obj) {
1172
- for (var prop in obj) {
1173
- if (obj.hasOwnProperty(prop) && prop.toLowerCase() === key.toLowerCase()) {
1174
- return prop;
1175
- }
1176
- }
1177
- }
1178
- return null;
1179
- };
1180
- var generateDeprecationMessage = function generateDeprecationMessage(methodName, alternateMethod) {
1181
- var messageArray = [methodName, Messages$9.DeprecationMessages.MethodIsDeprecatedPostfix];
1182
- if (alternateMethod) {
1183
- messageArray.push(alternateMethod);
1184
- messageArray.push(Messages$9.DeprecationMessages.MethodIsDeprecatedPostfix);
1185
- }
1186
- return messageArray.join(' ');
1187
- };
1188
- function generateHash(name) {
1189
- var hash = 0;
1190
- var character;
1191
- if (name === undefined || name === null) {
1192
- return 0;
1193
- }
1194
- name = name.toString().toLowerCase();
1195
- if (Array.prototype.reduce) {
1196
- return name.split('').reduce(function (a, b) {
1197
- a = (a << 5) - a + b.charCodeAt(0);
1198
- return a & a;
1199
- }, 0);
1200
- }
1201
- if (name.length === 0) {
1202
- return hash;
1203
- }
1204
- for (var i = 0; i < name.length; i++) {
1205
- character = name.charCodeAt(i);
1206
- hash = (hash << 5) - hash + character;
1207
- hash = hash & hash;
1208
- }
1209
- return hash;
1210
- }
1211
- var generateRandomValue = function generateRandomValue(value) {
1212
- var randomValue;
1213
- var a;
1214
- if (window.crypto && window.crypto.getRandomValues) {
1215
- // @ts-ignore
1216
- randomValue = window.crypto.getRandomValues(new Uint8Array(1)); // eslint-disable-line no-undef
1217
- }
1218
-
1219
- if (randomValue) {
1220
- // @ts-ignore
1221
- return (a ^ randomValue[0] % 16 >> a / 4).toString(16);
1222
- }
1223
- return (a ^ Math.random() * 16 >> a / 4).toString(16);
1224
- };
1225
- var generateUniqueId = function generateUniqueId(a) {
1226
- // https://gist.github.com/jed/982883
1227
- // Added support for crypto for better random
1228
- if (a === void 0) {
1229
- a = '';
1230
- }
1231
- return a // if the placeholder was passed, return
1232
- ? generateRandomValue() // if the placeholder was passed, return
1233
- :
1234
- // [1e7] -> // 10000000 +
1235
- // -1e3 -> // -1000 +
1236
- // -4e3 -> // -4000 +
1237
- // -8e3 -> // -80000000 +
1238
- // -1e11 -> //-100000000000,
1239
- "".concat(1e7, "-").concat(1e3, "-").concat(4e3, "-").concat(8e3, "-").concat(1e11).replace(/[018]/g,
1240
- // zeroes, ones, and eights with
1241
- generateUniqueId // random hex digits
1242
- );
1243
- };
1244
- /**
1245
- * Returns a value between 1-100 inclusive.
1246
- */
1247
- var getRampNumber = function getRampNumber(value) {
1248
- if (!value) {
1249
- return 100;
1250
- }
1251
- var hash = generateHash(value);
1252
- return Math.abs(hash % 100) + 1;
1253
- };
1254
- var isObject = function isObject(value) {
1255
- var objType = Object.prototype.toString.call(value);
1256
- return objType === '[object Object]' || objType === '[object Error]';
1257
- };
1258
- var parseNumber = function parseNumber(value) {
1259
- if (isNaN(value) || !isFinite(value)) {
1260
- return 0;
1261
- }
1262
- var floatValue = parseFloat(value);
1263
- return isNaN(floatValue) ? 0 : floatValue;
1264
- };
1265
- var parseStringOrNumber = function parseStringOrNumber(value) {
1266
- if (isStringOrNumber(value)) {
1267
- return value;
1268
- } else {
1269
- return null;
1270
- }
1271
- };
1272
- var replaceCommasWithPipes = function replaceCommasWithPipes(value) {
1273
- return value.replace(/,/g, '|');
1274
- };
1275
- var replacePipesWithCommas = function replacePipesWithCommas(value) {
1276
- return value.replace(/\|/g, ',');
1277
- };
1278
- var replaceApostrophesWithQuotes = function replaceApostrophesWithQuotes(value) {
1279
- return value.replace(/\'/g, '"');
1280
- };
1281
- var replaceQuotesWithApostrophes = function replaceQuotesWithApostrophes(value) {
1282
- return value.replace(/\"/g, "'");
1283
- };
1284
- // FIXME: REFACTOR for V3
1285
- // only used in store.js to sanitize server-side formatting of
1286
- // booleans when checking for `isDevelopmentMode`
1287
- // Should be removed in v3
1288
- var returnConvertedBoolean = function returnConvertedBoolean(data) {
1289
- if (data === 'false' || data === '0') {
1290
- return false;
1291
- } else {
1292
- return Boolean(data);
1293
- }
1294
- };
1295
- var decoded = function decoded(s) {
1296
- return decodeURIComponent(s.replace(/\+/g, ' '));
1297
- };
1298
- var converted = function converted(s) {
1299
- if (s.indexOf('"') === 0) {
1300
- s = s.slice(1, -1).replace(/\\"/g, '"').replace(/\\\\/g, '\\');
1301
- }
1302
- return s;
1303
- };
1304
- var isString = function isString(value) {
1305
- return typeof value === 'string';
1306
- };
1307
- var isNumber = function isNumber(value) {
1308
- return typeof value === 'number';
1309
- };
1310
- var isBoolean = function isBoolean(value) {
1311
- return typeof value === 'boolean';
1312
- };
1313
- var isFunction = function isFunction(fn) {
1314
- return typeof fn === 'function';
1315
- };
1316
- var isValidCustomFlagProperty = function isValidCustomFlagProperty(value) {
1317
- return isNumber(value) || isString(value) || isBoolean(value);
1318
- };
1319
- var toDataPlanSlug = function toDataPlanSlug(value) {
1320
- // Make sure we are only acting on strings or numbers
1321
- return isStringOrNumber(value) ? value.toString().toLowerCase().replace(/[^0-9a-zA-Z]+/g, '_') : '';
1322
- };
1323
- var isDataPlanSlug = function isDataPlanSlug(str) {
1324
- return str === toDataPlanSlug(str);
1325
- };
1326
- var isStringOrNumber = function isStringOrNumber(value) {
1327
- return isString(value) || isNumber(value);
1328
- };
1329
- var isEmpty = function isEmpty(value) {
1330
- return value == null || !(Object.keys(value) || value).length;
1331
- };
1340
+ ProductActionActionEnum["purchase"] = "purchase";
1341
+ ProductActionActionEnum["refund"] = "refund";
1342
+ ProductActionActionEnum["addToWishlist"] = "add_to_wishlist";
1343
+ ProductActionActionEnum["removeFromWishlist"] = "remove_from_wish_list";
1344
+ })(exports.ProductActionActionEnum || (exports.ProductActionActionEnum = {}));
1345
+ (function (ProfileEventEventTypeEnum) {
1346
+ ProfileEventEventTypeEnum["profile"] = "profile";
1347
+ })(exports.ProfileEventEventTypeEnum || (exports.ProfileEventEventTypeEnum = {}));
1348
+ (function (ProfileEventDataProfileEventTypeEnum) {
1349
+ ProfileEventDataProfileEventTypeEnum["signup"] = "signup";
1350
+ ProfileEventDataProfileEventTypeEnum["login"] = "login";
1351
+ ProfileEventDataProfileEventTypeEnum["logout"] = "logout";
1352
+ ProfileEventDataProfileEventTypeEnum["update"] = "update";
1353
+ ProfileEventDataProfileEventTypeEnum["delete"] = "delete";
1354
+ })(exports.ProfileEventDataProfileEventTypeEnum || (exports.ProfileEventDataProfileEventTypeEnum = {}));
1355
+ (function (PromotionActionActionEnum) {
1356
+ PromotionActionActionEnum["view"] = "view";
1357
+ PromotionActionActionEnum["click"] = "click";
1358
+ })(exports.PromotionActionActionEnum || (exports.PromotionActionActionEnum = {}));
1359
+ (function (PushMessageEventEventTypeEnum) {
1360
+ PushMessageEventEventTypeEnum["pushMessage"] = "push_message";
1361
+ })(exports.PushMessageEventEventTypeEnum || (exports.PushMessageEventEventTypeEnum = {}));
1362
+ (function (PushMessageEventDataPushMessageTypeEnum) {
1363
+ PushMessageEventDataPushMessageTypeEnum["sent"] = "sent";
1364
+ PushMessageEventDataPushMessageTypeEnum["received"] = "received";
1365
+ PushMessageEventDataPushMessageTypeEnum["action"] = "action";
1366
+ })(exports.PushMessageEventDataPushMessageTypeEnum || (exports.PushMessageEventDataPushMessageTypeEnum = {}));
1367
+ (function (PushMessageEventDataApplicationStateEnum) {
1368
+ PushMessageEventDataApplicationStateEnum["notRunning"] = "not_running";
1369
+ PushMessageEventDataApplicationStateEnum["background"] = "background";
1370
+ PushMessageEventDataApplicationStateEnum["foreground"] = "foreground";
1371
+ })(exports.PushMessageEventDataApplicationStateEnum || (exports.PushMessageEventDataApplicationStateEnum = {}));
1372
+ (function (PushMessageEventDataPushMessageBehaviorEnum) {
1373
+ PushMessageEventDataPushMessageBehaviorEnum["received"] = "Received";
1374
+ PushMessageEventDataPushMessageBehaviorEnum["directOpen"] = "DirectOpen";
1375
+ PushMessageEventDataPushMessageBehaviorEnum["read"] = "Read";
1376
+ PushMessageEventDataPushMessageBehaviorEnum["influencedOpen"] = "InfluencedOpen";
1377
+ PushMessageEventDataPushMessageBehaviorEnum["displayed"] = "Displayed";
1378
+ })(exports.PushMessageEventDataPushMessageBehaviorEnum || (exports.PushMessageEventDataPushMessageBehaviorEnum = {}));
1379
+ (function (PushRegistrationEventEventTypeEnum) {
1380
+ PushRegistrationEventEventTypeEnum["pushRegistration"] = "push_registration";
1381
+ })(exports.PushRegistrationEventEventTypeEnum || (exports.PushRegistrationEventEventTypeEnum = {}));
1382
+ (function (SessionEndEventEventTypeEnum) {
1383
+ SessionEndEventEventTypeEnum["sessionEnd"] = "session_end";
1384
+ })(exports.SessionEndEventEventTypeEnum || (exports.SessionEndEventEventTypeEnum = {}));
1385
+ (function (SessionStartEventEventTypeEnum) {
1386
+ SessionStartEventEventTypeEnum["sessionStart"] = "session_start";
1387
+ })(exports.SessionStartEventEventTypeEnum || (exports.SessionStartEventEventTypeEnum = {}));
1388
+ (function (SourceInformationChannelEnum) {
1389
+ SourceInformationChannelEnum["native"] = "native";
1390
+ SourceInformationChannelEnum["javascript"] = "javascript";
1391
+ SourceInformationChannelEnum["pixel"] = "pixel";
1392
+ SourceInformationChannelEnum["desktop"] = "desktop";
1393
+ SourceInformationChannelEnum["partner"] = "partner";
1394
+ SourceInformationChannelEnum["serverToServer"] = "server_to_server";
1395
+ })(exports.SourceInformationChannelEnum || (exports.SourceInformationChannelEnum = {}));
1396
+ (function (UserAttributeChangeEventEventTypeEnum) {
1397
+ UserAttributeChangeEventEventTypeEnum["userAttributeChange"] = "user_attribute_change";
1398
+ })(exports.UserAttributeChangeEventEventTypeEnum || (exports.UserAttributeChangeEventEventTypeEnum = {}));
1399
+ (function (UserIdentityChangeEventEventTypeEnum) {
1400
+ UserIdentityChangeEventEventTypeEnum["userIdentityChange"] = "user_identity_change";
1401
+ })(exports.UserIdentityChangeEventEventTypeEnum || (exports.UserIdentityChangeEventEventTypeEnum = {}));
1402
+ } (dist));
1332
1403
 
1333
1404
  function convertEvents(mpid, sdkEvents, mpInstance) {
1334
1405
  if (!mpid) {
@@ -2977,7 +3048,6 @@ var mParticle = (function () {
2977
3048
  this.inArray = inArray;
2978
3049
  this.isObject = isObject;
2979
3050
  this.decoded = decoded;
2980
- this.returnConvertedBoolean = returnConvertedBoolean;
2981
3051
  this.parseStringOrNumber = parseStringOrNumber;
2982
3052
  this.generateHash = generateHash;
2983
3053
  this.generateUniqueId = generateUniqueId;
@@ -2991,6 +3061,21 @@ var mParticle = (function () {
2991
3061
  var iosBridgeNameBase = 'mParticle';
2992
3062
  function NativeSdkHelpers(mpInstance) {
2993
3063
  var self = this;
3064
+ this.initializeSessionAttributes = function (apiKey) {
3065
+ var SetSessionAttribute = Constants.NativeSdkPaths.SetSessionAttribute;
3066
+ var env = JSON.stringify({
3067
+ key: '$src_env',
3068
+ value: 'webview'
3069
+ });
3070
+ var key = JSON.stringify({
3071
+ key: '$src_key',
3072
+ value: apiKey
3073
+ });
3074
+ self.sendToNative(SetSessionAttribute, env);
3075
+ if (apiKey) {
3076
+ self.sendToNative(SetSessionAttribute, key);
3077
+ }
3078
+ };
2994
3079
  this.isBridgeV2Available = function (bridgeName) {
2995
3080
  if (!bridgeName) {
2996
3081
  return false;
@@ -3232,6 +3317,7 @@ var mParticle = (function () {
3232
3317
  // https://go.mparticle.com/work/SQDSDKS-6045
3233
3318
  var persistence = mpInstance._Persistence.getPersistence();
3234
3319
  if (persistence && !persistence.cu) {
3320
+ // https://go.mparticle.com/work/SQDSDKS-6323
3235
3321
  mpInstance.Identity.identify(mpInstance._Store.SDKConfig.identifyRequest, mpInstance._Store.SDKConfig.identityCallback);
3236
3322
  mpInstance._Store.identifyCalled = true;
3237
3323
  mpInstance._Store.SDKConfig.identityCallback = null;
@@ -3776,6 +3862,10 @@ var mParticle = (function () {
3776
3862
  // TODO: Merge this with SDKStoreApi in sdkRuntimeModels
3777
3863
  function Store(config, mpInstance, apiKey) {
3778
3864
  var _this = this;
3865
+ var _a = mpInstance._Helpers,
3866
+ createMainStorageName = _a.createMainStorageName,
3867
+ createProductStorageName = _a.createProductStorageName;
3868
+ var isWebviewEnabled = mpInstance._NativeSdkHelpers.isWebviewEnabled;
3779
3869
  var defaultStore = {
3780
3870
  isEnabled: true,
3781
3871
  sessionAttributes: {},
@@ -3851,12 +3941,16 @@ var mParticle = (function () {
3851
3941
  if (!config.hasOwnProperty('flags')) {
3852
3942
  this.SDKConfig.flags = {};
3853
3943
  }
3854
- this.SDKConfig.flags = processFlags(config, this.SDKConfig);
3944
+ // We process the initial config that is passed via the SDK init
3945
+ // and then we will reprocess the config within the processConfig
3946
+ // function when the config is updated from the server
3947
+ // https://go.mparticle.com/work/SQDSDKS-6317
3948
+ this.SDKConfig.flags = processFlags(config);
3855
3949
  if (config.deviceId) {
3856
3950
  this.deviceId = config.deviceId;
3857
3951
  }
3858
3952
  if (config.hasOwnProperty('isDevelopmentMode')) {
3859
- this.SDKConfig.isDevelopmentMode = mpInstance._Helpers.returnConvertedBoolean(config.isDevelopmentMode);
3953
+ this.SDKConfig.isDevelopmentMode = returnConvertedBoolean(config.isDevelopmentMode);
3860
3954
  } else {
3861
3955
  this.SDKConfig.isDevelopmentMode = false;
3862
3956
  }
@@ -3977,6 +4071,10 @@ var mParticle = (function () {
3977
4071
  }
3978
4072
  }
3979
4073
  }
4074
+ this.hasInvalidIdentifyRequest = function () {
4075
+ var identifyRequest = _this.SDKConfig.identifyRequest;
4076
+ return isObject(identifyRequest) && isObject(identifyRequest.userIdentities) && isEmpty(identifyRequest.userIdentities) || !identifyRequest;
4077
+ };
3980
4078
  this.getDeviceId = function () {
3981
4079
  return _this.deviceId;
3982
4080
  };
@@ -3985,11 +4083,15 @@ var mParticle = (function () {
3985
4083
  _this.persistenceData.gs.das = deviceId;
3986
4084
  mpInstance._Persistence.update();
3987
4085
  };
3988
- this.nullifySession = function () {
3989
- _this.sessionId = null;
3990
- _this.dateLastEventSent = null;
3991
- _this.sessionAttributes = {};
3992
- mpInstance._Persistence.update();
4086
+ this.addMpidToSessionHistory = function (mpid, previousMPID) {
4087
+ var indexOfMPID = _this.currentSessionMPIDs.indexOf(mpid);
4088
+ if (mpid && previousMPID !== mpid && indexOfMPID < 0) {
4089
+ _this.currentSessionMPIDs.push(mpid);
4090
+ return;
4091
+ }
4092
+ if (indexOfMPID >= 0) {
4093
+ _this.currentSessionMPIDs = moveElementToEnd(_this.currentSessionMPIDs, indexOfMPID);
4094
+ }
3993
4095
  };
3994
4096
  this.getFirstSeenTime = function (mpid) {
3995
4097
  if (!mpid) {
@@ -4046,8 +4148,34 @@ var mParticle = (function () {
4046
4148
  }
4047
4149
  }
4048
4150
  };
4151
+ this.nullifySession = function () {
4152
+ _this.sessionId = null;
4153
+ _this.dateLastEventSent = null;
4154
+ _this.sessionAttributes = {};
4155
+ mpInstance._Persistence.update();
4156
+ };
4157
+ this.processConfig = function (config) {
4158
+ var workspaceToken = config.workspaceToken,
4159
+ requiredWebviewBridgeName = config.requiredWebviewBridgeName;
4160
+ // We should reprocess the flags in case they have changed when we request an updated config
4161
+ // such as if the SDK is being self-hosted and the flags are different on the server config
4162
+ // https://go.mparticle.com/work/SQDSDKS-6317
4163
+ _this.SDKConfig.flags = processFlags(config);
4164
+ if (workspaceToken) {
4165
+ _this.SDKConfig.workspaceToken = workspaceToken;
4166
+ } else {
4167
+ mpInstance.Logger.warning('You should have a workspaceToken on your config object for security purposes.');
4168
+ }
4169
+ // add a new function to apply items to the store that require config to be returned
4170
+ _this.storageName = createMainStorageName(workspaceToken);
4171
+ _this.prodStorageName = createProductStorageName(workspaceToken);
4172
+ _this.SDKConfig.requiredWebviewBridgeName = requiredWebviewBridgeName || workspaceToken;
4173
+ _this.webviewBridgeEnabled = isWebviewEnabled(_this.SDKConfig.requiredWebviewBridgeName, _this.SDKConfig.minWebviewBridgeVersion);
4174
+ _this.configurationLoaded = true;
4175
+ };
4049
4176
  }
4050
- function processFlags(config, SDKConfig) {
4177
+ // https://go.mparticle.com/work/SQDSDKS-6317
4178
+ function processFlags(config) {
4051
4179
  var flags = {};
4052
4180
  var _a = Constants.FeatureFlags,
4053
4181
  ReportBatching = _a.ReportBatching,
@@ -4059,6 +4187,7 @@ var mParticle = (function () {
4059
4187
  if (!config.flags) {
4060
4188
  return {};
4061
4189
  }
4190
+ // https://go.mparticle.com/work/SQDSDKS-6317
4062
4191
  // Passed in config flags take priority over defaults
4063
4192
  flags[ReportBatching] = config.flags[ReportBatching] || false;
4064
4193
  // The server returns stringified numbers, sowe need to parse
@@ -4901,6 +5030,16 @@ var mParticle = (function () {
4901
5030
  }
4902
5031
  }
4903
5032
  };
5033
+ this.swapCurrentUser = function (previousMPID, currentMPID, currentSessionMPIDs) {
5034
+ if (previousMPID && currentMPID && previousMPID !== currentMPID) {
5035
+ var persistence = self.getPersistence();
5036
+ if (persistence) {
5037
+ persistence.cu = currentMPID;
5038
+ persistence.gs.csm = currentSessionMPIDs;
5039
+ self.savePersistence(persistence);
5040
+ }
5041
+ }
5042
+ };
4904
5043
 
4905
5044
  // https://go.mparticle.com/work/SQDSDKS-6021
4906
5045
  this.savePersistence = function (persistence) {
@@ -4956,6 +5095,7 @@ var mParticle = (function () {
4956
5095
  if (!mpid) {
4957
5096
  return;
4958
5097
  }
5098
+ // https://go.mparticle.com/work/SQDSDKS-6329
4959
5099
  if (!time) {
4960
5100
  time = new Date().getTime();
4961
5101
  }
@@ -4995,6 +5135,7 @@ var mParticle = (function () {
4995
5135
  if (!mpid) {
4996
5136
  return;
4997
5137
  }
5138
+ // https://go.mparticle.com/work/SQDSDKS-6329
4998
5139
  if (!time) {
4999
5140
  time = new Date().getTime();
5000
5141
  }
@@ -5368,11 +5509,11 @@ var mParticle = (function () {
5368
5509
  };
5369
5510
  }
5370
5511
 
5371
- var _Constants$IdentityMe$1 = Constants.IdentityMethods,
5372
- Modify$3 = _Constants$IdentityMe$1.Modify,
5373
- Identify$2 = _Constants$IdentityMe$1.Identify,
5374
- Login$2 = _Constants$IdentityMe$1.Login,
5375
- Logout$2 = _Constants$IdentityMe$1.Logout;
5512
+ var _Constants$IdentityMe = Constants.IdentityMethods,
5513
+ Modify$3 = _Constants$IdentityMe.Modify,
5514
+ Identify$2 = _Constants$IdentityMe.Identify,
5515
+ Login$2 = _Constants$IdentityMe.Login,
5516
+ Logout$2 = _Constants$IdentityMe.Logout;
5376
5517
  function Forwarders(mpInstance, kitBlocker) {
5377
5518
  var self = this;
5378
5519
  var UserAttributeActionTypes = {
@@ -5846,7 +5987,7 @@ var mParticle = (function () {
5846
5987
  }
5847
5988
 
5848
5989
  // TODO: This file is no longer the server model because the web SDK payload
5849
- var MessageType$1 = Types.MessageType;
5990
+ var MessageType = Types.MessageType;
5850
5991
  var ApplicationTransitionType = Types.ApplicationTransitionType;
5851
5992
  // TODO: Make this a pure function that returns a new object
5852
5993
  function convertCustomFlags(event, dto) {
@@ -6029,7 +6170,7 @@ var mParticle = (function () {
6029
6170
  CurrencyCode: mpInstance._Store.currencyCode,
6030
6171
  DataPlan: mpInstance._Store.SDKConfig.dataPlan ? mpInstance._Store.SDKConfig.dataPlan : {}
6031
6172
  };
6032
- if (eventObject.EventDataType === MessageType$1.AppStateTransition) {
6173
+ if (eventObject.EventDataType === MessageType.AppStateTransition) {
6033
6174
  eventObject.IsFirstRun = mpInstance._Store.isFirstRun;
6034
6175
  eventObject.LaunchReferral = window.location.href || null;
6035
6176
  }
@@ -6089,7 +6230,7 @@ var mParticle = (function () {
6089
6230
  if (consent) {
6090
6231
  dto.con = consent;
6091
6232
  }
6092
- if (event.EventDataType === MessageType$1.AppStateTransition) {
6233
+ if (event.EventDataType === MessageType.AppStateTransition) {
6093
6234
  dto.fr = event.IsFirstRun;
6094
6235
  dto.iu = false;
6095
6236
  dto.at = ApplicationTransitionType.AppInit;
@@ -6101,7 +6242,7 @@ var mParticle = (function () {
6101
6242
  if (event.CustomFlags) {
6102
6243
  convertCustomFlags(event, dto);
6103
6244
  }
6104
- if (event.EventDataType === MessageType$1.Commerce) {
6245
+ if (event.EventDataType === MessageType.Commerce) {
6105
6246
  dto.cu = event.CurrencyCode;
6106
6247
  // TODO: If Cart is deprecated, we should deprecate this too
6107
6248
  if (event.ShoppingCart) {
@@ -6142,7 +6283,7 @@ var mParticle = (function () {
6142
6283
  };
6143
6284
  });
6144
6285
  }
6145
- } else if (event.EventDataType === MessageType$1.Profile) {
6286
+ } else if (event.EventDataType === MessageType.Profile) {
6146
6287
  dto.pet = event.ProfileMessageType;
6147
6288
  }
6148
6289
  return dto;
@@ -6401,29 +6542,29 @@ var mParticle = (function () {
6401
6542
  return AudienceManager;
6402
6543
  }();
6403
6544
 
6545
+ function didUserChange(previousUser, newUser) {
6546
+ return !previousUser || newUser.getMPID() !== previousUser.getMPID() || previousUser.isLoggedIn() !== newUser.isLoggedIn();
6547
+ }
6548
+
6404
6549
  var Messages$2 = Constants.Messages,
6405
6550
  HTTPCodes$2 = Constants.HTTPCodes,
6406
- FeatureFlags = Constants.FeatureFlags;
6551
+ FeatureFlags$1 = Constants.FeatureFlags,
6552
+ IdentityMethods = Constants.IdentityMethods;
6407
6553
  var ErrorMessages = Messages$2.ErrorMessages;
6408
- var _Constants$IdentityMe = Constants.IdentityMethods,
6409
- Identify = _Constants$IdentityMe.Identify,
6410
- Modify$1 = _Constants$IdentityMe.Modify,
6411
- Login = _Constants$IdentityMe.Login,
6412
- Logout = _Constants$IdentityMe.Logout;
6554
+ var CacheIdentity = FeatureFlags$1.CacheIdentity;
6555
+ var Identify = IdentityMethods.Identify,
6556
+ Modify$1 = IdentityMethods.Modify,
6557
+ Login = IdentityMethods.Login,
6558
+ Logout = IdentityMethods.Logout;
6413
6559
  function Identity(mpInstance) {
6560
+ var _mpInstance$_Helpers = mpInstance._Helpers,
6561
+ getFeatureFlag = _mpInstance$_Helpers.getFeatureFlag,
6562
+ extend = _mpInstance$_Helpers.extend;
6414
6563
  var self = this;
6415
6564
  this.idCache = null;
6416
6565
  this.audienceManager = null;
6417
- this.checkIdentitySwap = function (previousMPID, currentMPID, currentSessionMPIDs) {
6418
- if (previousMPID && currentMPID && previousMPID !== currentMPID) {
6419
- var persistence = mpInstance._Persistence.getPersistence();
6420
- if (persistence) {
6421
- persistence.cu = currentMPID;
6422
- persistence.gs.csm = currentSessionMPIDs;
6423
- mpInstance._Persistence.savePersistence(persistence);
6424
- }
6425
- }
6426
- };
6566
+
6567
+ // https://go.mparticle.com/work/SQDSDKS-6353
6427
6568
  this.IdentityRequest = {
6428
6569
  preProcessIdentityRequest: function preProcessIdentityRequest(identityApiData, callback, method) {
6429
6570
  mpInstance.Logger.verbose(Messages$2.InformationMessages.StartingLogEvent + ': ' + method);
@@ -6480,7 +6621,7 @@ var mParticle = (function () {
6480
6621
  createIdentityChanges: function createIdentityChanges(previousIdentities, newIdentities) {
6481
6622
  var identityChanges = [];
6482
6623
  var key;
6483
- if (newIdentities && mpInstance._Helpers.isObject(newIdentities) && previousIdentities && mpInstance._Helpers.isObject(previousIdentities)) {
6624
+ if (newIdentities && isObject(newIdentities) && previousIdentities && isObject(previousIdentities)) {
6484
6625
  for (key in newIdentities) {
6485
6626
  identityChanges.push({
6486
6627
  old_value: previousIdentities[key] || null,
@@ -6494,7 +6635,7 @@ var mParticle = (function () {
6494
6635
  // takes 2 UI objects keyed by name, combines them, returns them keyed by type
6495
6636
  combineUserIdentities: function combineUserIdentities(previousUIByName, newUIByName) {
6496
6637
  var combinedUIByType = {};
6497
- var combinedUIByName = mpInstance._Helpers.extend(previousUIByName, newUIByName);
6638
+ var combinedUIByName = extend({}, previousUIByName, newUIByName);
6498
6639
  for (var key in combinedUIByName) {
6499
6640
  var type = Types.IdentityType.getIdentityType(key);
6500
6641
  // this check removes anything that is not whitelisted as an identity type
@@ -6559,6 +6700,7 @@ var mParticle = (function () {
6559
6700
  * @param {Function} [callback] A callback function that is called when the identify request completes
6560
6701
  */
6561
6702
  identify: function identify(identityApiData, callback) {
6703
+ // https://go.mparticle.com/work/SQDSDKS-6337
6562
6704
  var mpid,
6563
6705
  currentUser = mpInstance.Identity.getCurrentUser(),
6564
6706
  preProcessResult = mpInstance._Identity.IdentityRequest.preProcessIdentityRequest(identityApiData, callback, Identify);
@@ -6596,6 +6738,7 @@ var mParticle = (function () {
6596
6738
  * @param {Function} [callback] A callback function that is called when the logout request completes
6597
6739
  */
6598
6740
  logout: function logout(identityApiData, callback) {
6741
+ // https://go.mparticle.com/work/SQDSDKS-6337
6599
6742
  var mpid,
6600
6743
  currentUser = mpInstance.Identity.getCurrentUser(),
6601
6744
  preProcessResult = mpInstance._Identity.IdentityRequest.preProcessIdentityRequest(identityApiData, callback, Logout);
@@ -6639,6 +6782,7 @@ var mParticle = (function () {
6639
6782
  * @param {Function} [callback] A callback function that is called when the login request completes
6640
6783
  */
6641
6784
  login: function login(identityApiData, callback) {
6785
+ // https://go.mparticle.com/work/SQDSDKS-6337
6642
6786
  var mpid,
6643
6787
  currentUser = mpInstance.Identity.getCurrentUser(),
6644
6788
  preProcessResult = mpInstance._Identity.IdentityRequest.preProcessIdentityRequest(identityApiData, callback, Login);
@@ -6676,6 +6820,7 @@ var mParticle = (function () {
6676
6820
  * @param {Function} [callback] A callback function that is called when the modify request completes
6677
6821
  */
6678
6822
  modify: function modify(identityApiData, callback) {
6823
+ // https://go.mparticle.com/work/SQDSDKS-6337
6679
6824
  var mpid,
6680
6825
  currentUser = mpInstance.Identity.getCurrentUser(),
6681
6826
  preProcessResult = mpInstance._Identity.IdentityRequest.preProcessIdentityRequest(identityApiData, callback, Modify$1);
@@ -6857,6 +7002,7 @@ var mParticle = (function () {
6857
7002
  }
6858
7003
  };
6859
7004
 
7005
+ // https://go.mparticle.com/work/SQDSDKS-6354
6860
7006
  /**
6861
7007
  * Invoke these methods on the mParticle.Identity.getCurrentUser() object.
6862
7008
  * Example: mParticle.Identity.getCurrentUser().getAllUserAttributes()
@@ -6966,7 +7112,7 @@ var mParticle = (function () {
6966
7112
  */
6967
7113
  setUserAttributes: function setUserAttributes(userAttributes) {
6968
7114
  mpInstance._SessionManager.resetSessionTimer();
6969
- if (mpInstance._Helpers.isObject(userAttributes)) {
7115
+ if (isObject(userAttributes)) {
6970
7116
  if (mpInstance._Helpers.canLog()) {
6971
7117
  for (var key in userAttributes) {
6972
7118
  if (userAttributes.hasOwnProperty(key)) {
@@ -7177,7 +7323,7 @@ var mParticle = (function () {
7177
7323
  */
7178
7324
  getUserAudiences: function getUserAudiences(callback) {
7179
7325
  // user audience API is feature flagged
7180
- if (!mpInstance._Helpers.getFeatureFlag(FeatureFlags.AudienceAPI)) {
7326
+ if (!mpInstance._Helpers.getFeatureFlag(FeatureFlags$1.AudienceAPI)) {
7181
7327
  mpInstance.Logger.error(ErrorMessages.AudienceAPINotEnabled);
7182
7328
  return;
7183
7329
  }
@@ -7306,64 +7452,51 @@ var mParticle = (function () {
7306
7452
  }
7307
7453
  };
7308
7454
  };
7455
+
7456
+ // https://go.mparticle.com/work/SQDSDKS-6355
7309
7457
  this.parseIdentityResponse = function (xhr, previousMPID, callback, identityApiData, method, knownIdentities, parsingCachedResponse) {
7310
- var prevUser = mpInstance.Identity.getUser(previousMPID),
7311
- newUser,
7312
- mpidIsNotInCookies,
7313
- identityApiResult,
7314
- indexOfMPID,
7315
- newIdentitiesByType = {},
7316
- previousUIByName = prevUser ? prevUser.getUserIdentities().userIdentities : {},
7317
- previousUIByNameCopy = mpInstance._Helpers.extend({}, previousUIByName);
7458
+ var prevUser = mpInstance.Identity.getUser(previousMPID);
7459
+ var prevUserMPID = prevUser ? prevUser.getMPID() : null;
7460
+ var previousUIByName = prevUser ? prevUser.getUserIdentities().userIdentities : {};
7461
+ var identityApiResult;
7462
+ var newUser;
7463
+ var newIdentitiesByType = {};
7318
7464
  mpInstance._Store.identityCallInFlight = false;
7319
7465
  try {
7466
+ var _identityApiResult;
7320
7467
  mpInstance.Logger.verbose('Parsing "' + method + '" identity response from server');
7321
- if (xhr.responseText) {
7322
- identityApiResult = JSON.parse(xhr.responseText);
7323
- if (identityApiResult.hasOwnProperty('is_logged_in')) {
7324
- mpInstance._Store.isLoggedIn = identityApiResult.is_logged_in;
7325
- }
7468
+ identityApiResult = xhr.responseText ? JSON.parse(xhr.responseText) : null;
7469
+ mpInstance._Store.isLoggedIn = ((_identityApiResult = identityApiResult) === null || _identityApiResult === void 0 ? void 0 : _identityApiResult.is_logged_in) || false;
7470
+ mpInstance._Store.mpid = identityApiResult.mpid;
7471
+ if (prevUser) {
7472
+ // https://go.mparticle.com/work/SQDSDKS-6329
7473
+ mpInstance._Persistence.setLastSeenTime(previousMPID);
7326
7474
  }
7475
+ var mpidIsNotInCookies = !mpInstance._Persistence.getFirstSeenTime(identityApiResult.mpid);
7327
7476
 
7328
- // set currentUser
7329
- if (!prevUser || prevUser.getMPID() && identityApiResult.mpid && identityApiResult.mpid !== prevUser.getMPID()) {
7330
- mpInstance._Store.mpid = identityApiResult.mpid;
7331
- if (prevUser) {
7332
- mpInstance._Persistence.setLastSeenTime(previousMPID);
7333
- }
7334
- if (!mpInstance._Persistence.getFirstSeenTime(identityApiResult.mpid)) mpidIsNotInCookies = true;
7335
- mpInstance._Persistence.setFirstSeenTime(identityApiResult.mpid);
7336
- }
7477
+ // https://go.mparticle.com/work/SQDSDKS-6329
7478
+ mpInstance._Persistence.setFirstSeenTime(identityApiResult.mpid);
7337
7479
  if (xhr.status === 200) {
7338
- if (mpInstance._Helpers.getFeatureFlag(Constants.FeatureFlags.CacheIdentity)) {
7480
+ if (getFeatureFlag(CacheIdentity)) {
7339
7481
  cacheOrClearIdCache(method, knownIdentities, self.idCache, xhr, parsingCachedResponse);
7340
7482
  }
7483
+ var incomingUser = self.IdentityAPI.getUser(identityApiResult.mpid);
7484
+ var incomingMpidUIByName = incomingUser ? incomingUser.getUserIdentities().userIdentities : {};
7341
7485
  if (method === Modify$1) {
7342
7486
  newIdentitiesByType = mpInstance._Identity.IdentityRequest.combineUserIdentities(previousUIByName, identityApiData.userIdentities);
7343
7487
  mpInstance._Persistence.saveUserIdentitiesToPersistence(previousMPID, newIdentitiesByType);
7344
7488
  } else {
7345
- var incomingUser = self.IdentityAPI.getUser(identityApiResult.mpid);
7346
- var incomingMpidUIByName = incomingUser ? incomingUser.getUserIdentities().userIdentities : {};
7347
- var incomingMpidUIByNameCopy = mpInstance._Helpers.extend({}, incomingMpidUIByName);
7348
- mpInstance.Logger.verbose('Successfully parsed Identity Response');
7349
-
7489
+ // https://go.mparticle.com/work/SQDSDKS-6356
7350
7490
  //this covers an edge case where, users stored before "firstSeenTime" was introduced
7351
7491
  //will not have a value for "fst" until the current MPID changes, and in some cases,
7352
7492
  //the current MPID will never change
7353
- if (method === Identify && prevUser && identityApiResult.mpid === prevUser.getMPID()) {
7493
+ if (method === Identify && prevUser && identityApiResult.mpid === prevUserMPID) {
7354
7494
  mpInstance._Persistence.setFirstSeenTime(identityApiResult.mpid);
7355
7495
  }
7356
- indexOfMPID = mpInstance._Store.currentSessionMPIDs.indexOf(identityApiResult.mpid);
7357
- if (mpInstance._Store.sessionId && identityApiResult.mpid && previousMPID !== identityApiResult.mpid && indexOfMPID < 0) {
7358
- mpInstance._Store.currentSessionMPIDs.push(identityApiResult.mpid);
7359
- }
7360
- if (indexOfMPID > -1) {
7361
- mpInstance._Store.currentSessionMPIDs = mpInstance._Store.currentSessionMPIDs.slice(0, indexOfMPID).concat(mpInstance._Store.currentSessionMPIDs.slice(indexOfMPID + 1, mpInstance._Store.currentSessionMPIDs.length));
7362
- mpInstance._Store.currentSessionMPIDs.push(identityApiResult.mpid);
7363
- }
7496
+ mpInstance._Store.addMpidToSessionHistory(identityApiResult.mpid, previousMPID);
7364
7497
  mpInstance._CookieSyncManager.attemptCookieSync(previousMPID, identityApiResult.mpid, mpidIsNotInCookies);
7365
- self.checkIdentitySwap(previousMPID, identityApiResult.mpid, mpInstance._Store.currentSessionMPIDs);
7366
- if (identityApiData && identityApiData.userIdentities && Object.keys(identityApiData.userIdentities).length) {
7498
+ mpInstance._Persistence.swapCurrentUser(previousMPID, identityApiResult.mpid, mpInstance._Store.currentSessionMPIDs);
7499
+ if (identityApiData && !isEmpty(identityApiData.userIdentities)) {
7367
7500
  newIdentitiesByType = self.IdentityRequest.combineUserIdentities(incomingMpidUIByName, identityApiData.userIdentities);
7368
7501
  }
7369
7502
 
@@ -7371,46 +7504,31 @@ var mParticle = (function () {
7371
7504
  mpInstance._Persistence.saveUserIdentitiesToPersistence(identityApiResult.mpid, newIdentitiesByType);
7372
7505
  mpInstance._Persistence.update();
7373
7506
  mpInstance._Persistence.findPrevCookiesBasedOnUI(identityApiData);
7507
+
7508
+ // https://go.mparticle.com/work/SQDSDKS-6357
7374
7509
  mpInstance._Store.context = identityApiResult.context || mpInstance._Store.context;
7375
7510
  }
7376
7511
  newUser = mpInstance.Identity.getCurrentUser();
7377
- if (identityApiData && identityApiData.onUserAlias && mpInstance._Helpers.Validators.isFunction(identityApiData.onUserAlias)) {
7378
- try {
7379
- mpInstance.Logger.warning('Deprecated function onUserAlias will be removed in future releases');
7380
- identityApiData.onUserAlias(prevUser, newUser);
7381
- } catch (e) {
7382
- mpInstance.Logger.error('There was an error with your onUserAlias function - ' + e);
7383
- }
7384
- }
7512
+
7513
+ // https://go.mparticle.com/work/SQDSDKS-6359
7514
+ tryOnUserAlias(prevUser, newUser, identityApiData, mpInstance.Logger);
7385
7515
  var persistence = mpInstance._Persistence.getPersistence();
7386
7516
  if (newUser) {
7387
7517
  mpInstance._Persistence.storeDataInMemory(persistence, newUser.getMPID());
7388
- if (!prevUser || newUser.getMPID() !== prevUser.getMPID() || prevUser.isLoggedIn() !== newUser.isLoggedIn()) {
7389
- mpInstance._Forwarders.initForwarders(newUser.getUserIdentities().userIdentities, mpInstance._APIClient.prepareForwardingStats);
7390
- }
7391
-
7392
- // TODO: https://go.mparticle.com/work/SQDSDKS-6036
7393
- mpInstance._Forwarders.setForwarderUserIdentities(newUser.getUserIdentities().userIdentities);
7394
- mpInstance._Forwarders.setForwarderOnIdentityComplete(newUser, method);
7395
- mpInstance._Forwarders.setForwarderOnUserIdentified(newUser);
7518
+ self.reinitForwardersOnUserChange(prevUser, newUser);
7519
+ self.setForwarderCallbacks(newUser, method);
7396
7520
  }
7397
- var newIdentitiesByName = {};
7398
- for (var key in newIdentitiesByType) {
7399
- newIdentitiesByName[Types.IdentityType.getIdentityName(mpInstance._Helpers.parseNumber(key))] = newIdentitiesByType[key];
7400
- }
7401
- self.sendUserIdentityChangeEvent(newIdentitiesByName, method, identityApiResult.mpid, method === Modify$1 ? previousUIByNameCopy : incomingMpidUIByNameCopy);
7521
+ var newIdentitiesByName = getNewIdentitiesByName(newIdentitiesByType);
7522
+ var uiByName = method === Modify$1 ? previousUIByName : incomingMpidUIByName;
7523
+ self.sendUserIdentityChangeEvent(newIdentitiesByName, identityApiResult.mpid, uiByName);
7402
7524
  }
7403
7525
  if (callback) {
7404
- if (xhr.status === 0) {
7405
- mpInstance._Helpers.invokeCallback(callback, HTTPCodes$2.noHttpCoverage, identityApiResult || null, newUser);
7406
- } else {
7407
- mpInstance._Helpers.invokeCallback(callback, xhr.status, identityApiResult || null, newUser);
7408
- }
7409
- } else {
7410
- if (identityApiResult && identityApiResult.errors && identityApiResult.errors.length) {
7411
- mpInstance.Logger.error('Received HTTP response code of ' + xhr.status + ' - ' + identityApiResult.errors[0].message);
7412
- }
7526
+ var callbackCode = xhr.status === 0 ? HTTPCodes$2.noHttpCoverage : xhr.status;
7527
+ mpInstance._Helpers.invokeCallback(callback, callbackCode, identityApiResult || null, newUser);
7528
+ } else if (identityApiResult && !isEmpty(identityApiResult.errors)) {
7529
+ mpInstance.Logger.error('Received HTTP response code of ' + xhr.status + ' - ' + identityApiResult.errors[0].message);
7413
7530
  }
7531
+ mpInstance.Logger.verbose('Successfully parsed Identity Response');
7414
7532
  mpInstance._APIClient.processQueuedEvents();
7415
7533
  } catch (e) {
7416
7534
  if (callback) {
@@ -7424,23 +7542,22 @@ var mParticle = (function () {
7424
7542
  // compare what identities exist vs what is previously was for the specific user if they were in memory before.
7425
7543
  // if it's the first time the user is logging in, send a user identity change request with
7426
7544
 
7427
- this.sendUserIdentityChangeEvent = function (newUserIdentities, method, mpid, prevUserIdentities) {
7428
- var currentUserInMemory, userIdentityChangeEvent;
7429
- if (!mpid) {
7430
- if (method !== Modify$1) {
7431
- return;
7432
- }
7433
- }
7434
- currentUserInMemory = this.IdentityAPI.getUser(mpid);
7545
+ this.sendUserIdentityChangeEvent = function (newUserIdentities, mpid, currentUserIdentities) {
7546
+ // https://go.mparticle.com/work/SQDSDKS-6354
7547
+ var currentUserInMemory = this.IdentityAPI.getUser(mpid);
7435
7548
  for (var identityType in newUserIdentities) {
7436
- if (prevUserIdentities[identityType] !== newUserIdentities[identityType]) {
7437
- var isNewUserIdentityType = !prevUserIdentities[identityType];
7438
- userIdentityChangeEvent = self.createUserIdentityChange(identityType, newUserIdentities[identityType], prevUserIdentities[identityType], isNewUserIdentityType, currentUserInMemory);
7549
+ // Verifies a change actually happened
7550
+ if (currentUserIdentities[identityType] !== newUserIdentities[identityType]) {
7551
+ // If a new identity type was introduced when the identity changes
7552
+ // we need to notify the server so that it will associate the new
7553
+ // identity type with subsequent events
7554
+ var isNewUserIdentityType = !currentUserIdentities[identityType];
7555
+ var userIdentityChangeEvent = self.createUserIdentityChange(identityType, newUserIdentities[identityType], currentUserIdentities[identityType], isNewUserIdentityType, currentUserInMemory);
7439
7556
  mpInstance._APIClient.sendEventToServer(userIdentityChangeEvent);
7440
7557
  }
7441
7558
  }
7442
7559
  };
7443
- this.createUserIdentityChange = function (identityType, newIdentity, oldIdentity, newCreatedThisBatch, userInMemory) {
7560
+ this.createUserIdentityChange = function (identityType, newIdentity, oldIdentity, isIdentityTypeNewToBatch, userInMemory) {
7444
7561
  var userIdentityChangeEvent;
7445
7562
  userIdentityChangeEvent = mpInstance._ServerModel.createEventObject({
7446
7563
  messageType: Types.MessageType.UserIdentityChange,
@@ -7448,7 +7565,7 @@ var mParticle = (function () {
7448
7565
  New: {
7449
7566
  IdentityType: identityType,
7450
7567
  Identity: newIdentity,
7451
- CreatedThisBatch: newCreatedThisBatch
7568
+ CreatedThisBatch: isIdentityTypeNewToBatch
7452
7569
  },
7453
7570
  Old: {
7454
7571
  IdentityType: identityType,
@@ -7485,6 +7602,29 @@ var mParticle = (function () {
7485
7602
  }
7486
7603
  return userAttributeChangeEvent;
7487
7604
  };
7605
+ this.reinitForwardersOnUserChange = function (prevUser, newUser) {
7606
+ if (didUserChange(prevUser, newUser)) {
7607
+ mpInstance._Forwarders.initForwarders(newUser.getUserIdentities().userIdentities, mpInstance._APIClient.prepareForwardingStats);
7608
+ }
7609
+ };
7610
+ this.setForwarderCallbacks = function (user, method) {
7611
+ // https://go.mparticle.com/work/SQDSDKS-6036
7612
+ mpInstance._Forwarders.setForwarderUserIdentities(user.getUserIdentities().userIdentities);
7613
+ mpInstance._Forwarders.setForwarderOnIdentityComplete(user, method);
7614
+ mpInstance._Forwarders.setForwarderOnUserIdentified(user);
7615
+ };
7616
+ }
7617
+
7618
+ // https://go.mparticle.com/work/SQDSDKS-6359
7619
+ function tryOnUserAlias(previousUser, newUser, identityApiData, logger) {
7620
+ if (identityApiData && identityApiData.onUserAlias && isFunction(identityApiData.onUserAlias)) {
7621
+ try {
7622
+ logger.warning(generateDeprecationMessage('onUserAlias'));
7623
+ identityApiData.onUserAlias(previousUser, newUser);
7624
+ } catch (e) {
7625
+ logger.error('There was an error with your onUserAlias function - ' + e);
7626
+ }
7627
+ }
7488
7628
  }
7489
7629
 
7490
7630
  var CCPAPurpose = Constants.CCPAPurpose;
@@ -8291,6 +8431,7 @@ var mParticle = (function () {
8291
8431
  var xhr,
8292
8432
  xhrCallback = function xhrCallback() {
8293
8433
  if (xhr.readyState === 4) {
8434
+ // https://go.mparticle.com/work/SQDSDKS-6368
8294
8435
  mpInstance.Logger.verbose('Received ' + xhr.statusText + ' from server');
8295
8436
  //only parse error messages from failing requests
8296
8437
  if (xhr.status !== 200 && xhr.status !== 202) {
@@ -8323,6 +8464,7 @@ var mParticle = (function () {
8323
8464
  previousMPID,
8324
8465
  xhrCallback = function xhrCallback() {
8325
8466
  if (xhr.readyState === 4) {
8467
+ // https://go.mparticle.com/work/SQDSDKS-6368
8326
8468
  mpInstance.Logger.verbose('Received ' + xhr.statusText + ' from server');
8327
8469
  parseIdentityResponse(xhr, previousMPID, callback, originalIdentityApiData, method, knownIdentities, false);
8328
8470
  }
@@ -8360,7 +8502,10 @@ var mParticle = (function () {
8360
8502
  }
8361
8503
 
8362
8504
  var Messages = Constants.Messages,
8363
- HTTPCodes = Constants.HTTPCodes;
8505
+ HTTPCodes = Constants.HTTPCodes,
8506
+ FeatureFlags = Constants.FeatureFlags;
8507
+ var ReportBatching = FeatureFlags.ReportBatching;
8508
+ var StartingInitialization = Messages.InformationMessages.StartingInitialization;
8364
8509
 
8365
8510
  /**
8366
8511
  * <p>All of the following methods can be called on the primary mParticle class. In version 2.10.0, we introduced <a href="https://docs.mparticle.com/developers/sdk/web/multiple-instances/">multiple instances</a>. If you are using multiple instances (self hosted environments only), you should call these methods on each instance.</p>
@@ -8585,7 +8730,7 @@ var mParticle = (function () {
8585
8730
  * @param {Function} [callback] A callback function that is called when the location is either allowed or rejected by the user. A position object of schema {coords: {latitude: number, longitude: number}} is passed to the callback
8586
8731
  */
8587
8732
  this.startTrackingLocation = function (callback) {
8588
- if (!self._Helpers.Validators.isFunction(callback)) {
8733
+ if (!isFunction(callback)) {
8589
8734
  self.Logger.warning('Warning: Location tracking is triggered, but not including a callback into the `startTrackingLocation` may result in events logged too quickly and not being associated with a location.');
8590
8735
  }
8591
8736
  self._SessionManager.resetSessionTimer();
@@ -9303,118 +9448,48 @@ var mParticle = (function () {
9303
9448
  var kitBlocker = createKitBlocker(config, mpInstance);
9304
9449
  mpInstance._APIClient = new APIClient(mpInstance, kitBlocker);
9305
9450
  mpInstance._Forwarders = new Forwarders(mpInstance, kitBlocker);
9306
- if (config.flags) {
9307
- if (config.flags.hasOwnProperty(Constants.FeatureFlags.EventBatchingIntervalMillis)) {
9308
- mpInstance._Store.SDKConfig.flags[Constants.FeatureFlags.EventBatchingIntervalMillis] = config.flags[Constants.FeatureFlags.EventBatchingIntervalMillis];
9309
- }
9310
- }
9311
-
9312
- // add a new function to apply items to the store that require config to be returned
9313
- mpInstance._Store.storageName = mpInstance._Helpers.createMainStorageName(config.workspaceToken);
9314
- mpInstance._Store.prodStorageName = mpInstance._Helpers.createProductStorageName(config.workspaceToken);
9315
-
9316
- // idCache is instantiated here as opposed to when _Identity is instantiated
9317
- // because it depends on _Store.storageName, which is not sent until above
9318
- // because it is a setting on config which returns asyncronously
9319
- // in self hosted mode
9320
- mpInstance._Identity.idCache = new LocalStorageVault("".concat(mpInstance._Store.storageName, "-id-cache"), {
9321
- logger: mpInstance.Logger
9322
- });
9451
+ mpInstance._Store.processConfig(config);
9452
+ mpInstance._Identity.idCache = createIdentityCache(mpInstance);
9323
9453
  removeExpiredIdentityCacheDates(mpInstance._Identity.idCache);
9324
- if (config.hasOwnProperty('workspaceToken')) {
9325
- mpInstance._Store.SDKConfig.workspaceToken = config.workspaceToken;
9454
+
9455
+ // Web View Bridge is used for cases where the Web SDK is loaded within an iOS or Android device's
9456
+ // Web View. The Web SDK simply acts as a passthrough to the mParticle Native SDK. It is not
9457
+ // responsible for sending events directly to mParticle's servers. The Web SDK will not initialize
9458
+ // persistence or Identity directly.
9459
+ if (mpInstance._Store.webviewBridgeEnabled) {
9460
+ mpInstance._NativeSdkHelpers.initializeSessionAttributes(apiKey);
9326
9461
  } else {
9327
- mpInstance.Logger.warning('You should have a workspaceToken on your config object for security purposes.');
9328
- }
9329
- if (config.hasOwnProperty('requiredWebviewBridgeName')) {
9330
- mpInstance._Store.SDKConfig.requiredWebviewBridgeName = config.requiredWebviewBridgeName;
9331
- } else if (config.hasOwnProperty('workspaceToken')) {
9332
- mpInstance._Store.SDKConfig.requiredWebviewBridgeName = config.workspaceToken;
9333
- }
9334
- mpInstance._Store.webviewBridgeEnabled = mpInstance._NativeSdkHelpers.isWebviewEnabled(mpInstance._Store.SDKConfig.requiredWebviewBridgeName, mpInstance._Store.SDKConfig.minWebviewBridgeVersion);
9335
- mpInstance._Store.configurationLoaded = true;
9462
+ // Main SDK initialization flow
9336
9463
 
9337
- // https://go.mparticle.com/work/SQDSDKS-6044
9338
- if (!mpInstance._Store.webviewBridgeEnabled) {
9339
9464
  // Load any settings/identities/attributes from cookie or localStorage
9340
9465
  mpInstance._Persistence.initializeStorage();
9341
- }
9342
- if (mpInstance._Store.webviewBridgeEnabled) {
9343
- mpInstance._NativeSdkHelpers.sendToNative(Constants.NativeSdkPaths.SetSessionAttribute, JSON.stringify({
9344
- key: '$src_env',
9345
- value: 'webview'
9346
- }));
9347
- if (apiKey) {
9348
- mpInstance._NativeSdkHelpers.sendToNative(Constants.NativeSdkPaths.SetSessionAttribute, JSON.stringify({
9349
- key: '$src_key',
9350
- value: apiKey
9351
- }));
9352
- }
9353
- } else {
9354
- var currentUser;
9355
9466
 
9356
- // If no initialIdentityRequest is passed in, we set the user identities to what is currently in cookies for the identify request
9357
- if (mpInstance._Helpers.isObject(mpInstance._Store.SDKConfig.identifyRequest) && mpInstance._Helpers.isObject(mpInstance._Store.SDKConfig.identifyRequest.userIdentities) && Object.keys(mpInstance._Store.SDKConfig.identifyRequest.userIdentities).length === 0 || !mpInstance._Store.SDKConfig.identifyRequest) {
9358
- var modifiedUIforIdentityRequest = {};
9359
- currentUser = mpInstance.Identity.getCurrentUser();
9360
- if (currentUser) {
9361
- var identities = currentUser.getUserIdentities().userIdentities || {};
9362
- for (var identityKey in identities) {
9363
- if (identities.hasOwnProperty(identityKey)) {
9364
- modifiedUIforIdentityRequest[identityKey] = identities[identityKey];
9365
- }
9366
- }
9367
- }
9368
- mpInstance._Store.SDKConfig.identifyRequest = {
9369
- userIdentities: modifiedUIforIdentityRequest
9370
- };
9371
- }
9372
- currentUser = mpInstance.Identity.getCurrentUser();
9373
- if (mpInstance._Helpers.getFeatureFlag(Constants.FeatureFlags.ReportBatching)) {
9467
+ // Set up user identitiy variables for later use
9468
+ var currentUser = mpInstance.Identity.getCurrentUser();
9469
+ var currentUserMPID = currentUser ? currentUser.getMPID() : null;
9470
+ var currentUserIdentities = currentUser ? currentUser.getUserIdentities().userIdentities : {};
9471
+ mpInstance._Store.SDKConfig.identifyRequest = mpInstance._Store.hasInvalidIdentifyRequest() ? {
9472
+ userIdentities: currentUserIdentities
9473
+ } : mpInstance._Store.SDKConfig.identifyRequest;
9474
+ if (mpInstance._Helpers.getFeatureFlag(ReportBatching)) {
9374
9475
  mpInstance._ForwardingStatsUploader.startForwardingStatsTimer();
9375
9476
  }
9376
9477
  mpInstance._Forwarders.processForwarders(config, mpInstance._APIClient.prepareForwardingStats);
9377
9478
  mpInstance._Forwarders.processPixelConfigs(config);
9479
+
9480
+ // Checks if session is created, resumed, or needs to be ended
9481
+ // Logs a session start or session end event accordingly
9378
9482
  mpInstance._SessionManager.initialize();
9379
9483
  mpInstance._Events.logAST();
9380
-
9381
- // Call mParticle._Store.SDKConfig.identityCallback when identify was not called due to a reload or a sessionId already existing
9382
- // Any identity callback should always be ran regardless if an identity call is made
9383
- if (!mpInstance._Store.identifyCalled && mpInstance._Store.SDKConfig.identityCallback && currentUser && currentUser.getMPID()) {
9384
- mpInstance._Store.SDKConfig.identityCallback({
9385
- httpCode: HTTPCodes.activeSession,
9386
- getUser: function getUser() {
9387
- return mpInstance._Identity.mParticleUser(currentUser.getMPID());
9388
- },
9389
- getPreviousUser: function getPreviousUser() {
9390
- var users = mpInstance.Identity.getUsers();
9391
- var mostRecentUser = users.shift();
9392
- if (mostRecentUser && currentUser && mostRecentUser.getMPID() === currentUser.getMPID()) {
9393
- mostRecentUser = users.shift();
9394
- }
9395
- return mostRecentUser || null;
9396
- },
9397
- body: {
9398
- mpid: currentUser.getMPID(),
9399
- is_logged_in: mpInstance._Store.isLoggedIn,
9400
- matched_identities: currentUser.getUserIdentities().userIdentities,
9401
- context: null,
9402
- is_ephemeral: false
9403
- }
9404
- });
9405
- }
9484
+ processIdentityCallback(mpInstance, currentUser, currentUserMPID, currentUserIdentities);
9406
9485
  }
9407
9486
  mpInstance._Store.isInitialized = true;
9487
+
9408
9488
  // Call any functions that are waiting for the library to be initialized
9409
- if (mpInstance._preInit.readyQueue && mpInstance._preInit.readyQueue.length) {
9410
- mpInstance._preInit.readyQueue.forEach(function (readyQueueItem) {
9411
- if (mpInstance._Helpers.Validators.isFunction(readyQueueItem)) {
9412
- readyQueueItem();
9413
- } else if (Array.isArray(readyQueueItem)) {
9414
- processPreloadedItem(readyQueueItem, mpInstance);
9415
- }
9416
- });
9417
- mpInstance._preInit.readyQueue = [];
9489
+ try {
9490
+ mpInstance._preInit.readyQueue = processReadyQueue(mpInstance._preInit.readyQueue);
9491
+ } catch (error) {
9492
+ mpInstance.Logger.error(error);
9418
9493
  }
9419
9494
 
9420
9495
  // https://go.mparticle.com/work/SQDSDKS-6040
@@ -9479,11 +9554,16 @@ var mParticle = (function () {
9479
9554
  }
9480
9555
  return kitBlocker;
9481
9556
  }
9557
+ function createIdentityCache(mpInstance) {
9558
+ return new LocalStorageVault("".concat(mpInstance._Store.storageName, "-id-cache"), {
9559
+ logger: mpInstance.Logger
9560
+ });
9561
+ }
9482
9562
  function runPreConfigFetchInitialization(mpInstance, apiKey, config) {
9483
9563
  mpInstance.Logger = new Logger(config);
9484
9564
  mpInstance._Store = new Store(config, mpInstance, apiKey);
9485
9565
  window.mParticle.Store = mpInstance._Store;
9486
- mpInstance.Logger.verbose(Messages.InformationMessages.StartingInitialization);
9566
+ mpInstance.Logger.verbose(StartingInitialization);
9487
9567
 
9488
9568
  // Check to see if localStorage is available before main configuration runs
9489
9569
  // since we will need this for the current implementation of user persistence
@@ -9495,9 +9575,40 @@ var mParticle = (function () {
9495
9575
  mpInstance._Store.isLocalStorageAvailable = false;
9496
9576
  }
9497
9577
  }
9498
- function processPreloadedItem(readyQueueItem, mpInstance) {
9499
- var args = readyQueueItem,
9500
- method = args.splice(0, 1)[0];
9578
+ function processIdentityCallback(mpInstance, currentUser, currentUserMPID, currentUserIdentities) {
9579
+ // https://go.mparticle.com/work/SQDSDKS-6323
9580
+ // Call mParticle._Store.SDKConfig.identityCallback when identify was not called
9581
+ // due to a reload or a sessionId already existing
9582
+ // Any identity callback should always be ran regardless if an identity call
9583
+ // is made
9584
+ if (!mpInstance._Store.identifyCalled && mpInstance._Store.SDKConfig.identityCallback && currentUser && currentUserMPID) {
9585
+ mpInstance._Store.SDKConfig.identityCallback({
9586
+ httpCode: HTTPCodes.activeSession,
9587
+ getUser: function getUser() {
9588
+ return mpInstance._Identity.mParticleUser(currentUserMPID);
9589
+ },
9590
+ getPreviousUser: function getPreviousUser() {
9591
+ var users = mpInstance.Identity.getUsers();
9592
+ var mostRecentUser = users.shift();
9593
+ var mostRecentUserMPID = mostRecentUser.getMPID();
9594
+ if (mostRecentUser && mostRecentUserMPID === currentUserMPID) {
9595
+ mostRecentUser = users.shift();
9596
+ }
9597
+ return mostRecentUser || null;
9598
+ },
9599
+ body: {
9600
+ mpid: currentUserMPID,
9601
+ is_logged_in: mpInstance._Store.isLoggedIn,
9602
+ matched_identities: currentUserIdentities,
9603
+ context: null,
9604
+ is_ephemeral: false
9605
+ }
9606
+ });
9607
+ }
9608
+ }
9609
+ function processPreloadedItem(readyQueueItem) {
9610
+ var args = readyQueueItem;
9611
+ var method = args.splice(0, 1)[0];
9501
9612
  // if the first argument is a method on the base mParticle object, run it
9502
9613
  if (mParticle[args[0]]) {
9503
9614
  mParticle[method].apply(this, args);
@@ -9512,10 +9623,22 @@ var mParticle = (function () {
9512
9623
  }
9513
9624
  computedMPFunction.apply(this, args);
9514
9625
  } catch (e) {
9515
- mpInstance.Logger.verbose('Unable to compute proper mParticle function ' + e);
9626
+ throw new Error('Unable to compute proper mParticle function ' + e);
9516
9627
  }
9517
9628
  }
9518
9629
  }
9630
+ function processReadyQueue(readyQueue) {
9631
+ if (!isEmpty(readyQueue)) {
9632
+ readyQueue.forEach(function (readyQueueItem) {
9633
+ if (isFunction(readyQueueItem)) {
9634
+ readyQueueItem();
9635
+ } else if (Array.isArray(readyQueueItem)) {
9636
+ processPreloadedItem(readyQueueItem);
9637
+ }
9638
+ });
9639
+ return [];
9640
+ }
9641
+ }
9519
9642
  function queueIfNotInitialized(func, self) {
9520
9643
  if (!self.isInitialized()) {
9521
9644
  self.ready(function () {
@@ -9547,7 +9670,6 @@ var mParticle = (function () {
9547
9670
  createServiceUrl: mockFunction,
9548
9671
  parseNumber: mockFunction,
9549
9672
  isObject: mockFunction,
9550
- returnConvertedBoolean: mockFunction,
9551
9673
  Validators: null
9552
9674
  },
9553
9675
  _resetForTests: mockFunction,
@@ -9656,60 +9778,6 @@ var mParticle = (function () {
9656
9778
  return _BatchValidator;
9657
9779
  }();
9658
9780
 
9659
- var EventTypeEnum;
9660
- (function (EventTypeEnum) {
9661
- EventTypeEnum[EventTypeEnum["Unknown"] = 0] = "Unknown";
9662
- EventTypeEnum[EventTypeEnum["Navigation"] = 1] = "Navigation";
9663
- EventTypeEnum[EventTypeEnum["Location"] = 2] = "Location";
9664
- EventTypeEnum[EventTypeEnum["Search"] = 3] = "Search";
9665
- EventTypeEnum[EventTypeEnum["Transaction"] = 4] = "Transaction";
9666
- EventTypeEnum[EventTypeEnum["UserContent"] = 5] = "UserContent";
9667
- EventTypeEnum[EventTypeEnum["UserPreference"] = 6] = "UserPreference";
9668
- EventTypeEnum[EventTypeEnum["Social"] = 7] = "Social";
9669
- EventTypeEnum[EventTypeEnum["Other"] = 8] = "Other";
9670
- EventTypeEnum[EventTypeEnum["Media"] = 9] = "Media";
9671
- })(EventTypeEnum || (EventTypeEnum = {}));
9672
- // TODO: https://mparticle-eng.atlassian.net/browse/SQDSDKS-5403
9673
- var MessageType;
9674
- (function (MessageType) {
9675
- MessageType[MessageType["SessionStart"] = 1] = "SessionStart";
9676
- MessageType[MessageType["SessionEnd"] = 2] = "SessionEnd";
9677
- MessageType[MessageType["PageView"] = 3] = "PageView";
9678
- MessageType[MessageType["PageEvent"] = 4] = "PageEvent";
9679
- MessageType[MessageType["CrashReport"] = 5] = "CrashReport";
9680
- MessageType[MessageType["OptOut"] = 6] = "OptOut";
9681
- MessageType[MessageType["AppStateTransition"] = 10] = "AppStateTransition";
9682
- MessageType[MessageType["Profile"] = 14] = "Profile";
9683
- MessageType[MessageType["Commerce"] = 16] = "Commerce";
9684
- MessageType[MessageType["UserAttributeChange"] = 17] = "UserAttributeChange";
9685
- MessageType[MessageType["UserIdentityChange"] = 18] = "UserIdentityChange";
9686
- MessageType[MessageType["Media"] = 20] = "Media";
9687
- })(MessageType || (MessageType = {}));
9688
- var IdentityType;
9689
- (function (IdentityType) {
9690
- IdentityType[IdentityType["Other"] = 0] = "Other";
9691
- IdentityType[IdentityType["CustomerId"] = 1] = "CustomerId";
9692
- IdentityType[IdentityType["Facebook"] = 2] = "Facebook";
9693
- IdentityType[IdentityType["Twitter"] = 3] = "Twitter";
9694
- IdentityType[IdentityType["Google"] = 4] = "Google";
9695
- IdentityType[IdentityType["Microsoft"] = 5] = "Microsoft";
9696
- IdentityType[IdentityType["Yahoo"] = 6] = "Yahoo";
9697
- IdentityType[IdentityType["Email"] = 7] = "Email";
9698
- IdentityType[IdentityType["FacebookCustomAudienceId"] = 9] = "FacebookCustomAudienceId";
9699
- IdentityType[IdentityType["Other2"] = 10] = "Other2";
9700
- IdentityType[IdentityType["Other3"] = 11] = "Other3";
9701
- IdentityType[IdentityType["Other4"] = 12] = "Other4";
9702
- IdentityType[IdentityType["Other5"] = 13] = "Other5";
9703
- IdentityType[IdentityType["Other6"] = 14] = "Other6";
9704
- IdentityType[IdentityType["Other7"] = 15] = "Other7";
9705
- IdentityType[IdentityType["Other8"] = 16] = "Other8";
9706
- IdentityType[IdentityType["Other9"] = 17] = "Other9";
9707
- IdentityType[IdentityType["Other10"] = 18] = "Other10";
9708
- IdentityType[IdentityType["MobileNumber"] = 19] = "MobileNumber";
9709
- IdentityType[IdentityType["PhoneNumber2"] = 20] = "PhoneNumber2";
9710
- IdentityType[IdentityType["PhoneNumber3"] = 21] = "PhoneNumber3";
9711
- })(IdentityType || (IdentityType = {}));
9712
-
9713
9781
  var MPSideloadedKit = /** @class */function () {
9714
9782
  function MPSideloadedKit(unregisteredKitInstance) {
9715
9783
  this.filterDictionary = {