@mparticle/web-sdk 2.19.3 → 2.20.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/mparticle.common.js +77 -37
- package/dist/mparticle.esm.js +77 -37
- package/dist/mparticle.js +747 -2389
- package/package.json +5 -5
- package/src/apiClient.ts +2 -4
- package/src/configAPIClient.ts +19 -2
- package/src/forwarders.interfaces.ts +61 -0
- package/src/forwarders.js +141 -72
- package/src/helpers.js +4 -75
- package/src/mockBatchCreator.ts +1 -0
- package/src/mp-instance.js +2 -0
- package/src/persistence.interfaces.ts +138 -0
- package/src/persistence.js +3 -0
- package/src/sdkRuntimeModels.ts +3 -2
- package/src/store.ts +9 -3
- package/src/utils.ts +79 -4
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mparticle/web-sdk",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.20.1",
|
|
4
4
|
"description": "mParticle core SDK for web applications",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"keywords": [
|
|
@@ -78,7 +78,7 @@
|
|
|
78
78
|
"@mparticle/event-models": "^1.1.6",
|
|
79
79
|
"@rollup/plugin-json": "^4.1.0",
|
|
80
80
|
"@rollup/plugin-typescript": "^8.3.3",
|
|
81
|
-
"@rollup/plugin-babel": "
|
|
81
|
+
"@rollup/plugin-babel": "6.0.3",
|
|
82
82
|
"@rollup/plugin-commonjs": "22.0.2",
|
|
83
83
|
"@rollup/plugin-node-resolve": "13.3.0",
|
|
84
84
|
"@semantic-release/changelog": "^5.0.1",
|
|
@@ -93,8 +93,8 @@
|
|
|
93
93
|
"browserify": "^17.0.0",
|
|
94
94
|
"chai": "^4.2.0",
|
|
95
95
|
"cross-env": "^7.0.3",
|
|
96
|
-
"eslint": "^
|
|
97
|
-
"eslint-config-prettier": "8.
|
|
96
|
+
"eslint": "^8.36.0",
|
|
97
|
+
"eslint-config-prettier": "8.8.0",
|
|
98
98
|
"eslint-plugin-prettier": "3.4.1",
|
|
99
99
|
"fetch-mock": "^7.5.1",
|
|
100
100
|
"gts": "^3.1.0",
|
|
@@ -116,7 +116,7 @@
|
|
|
116
116
|
"should": "^7.1.0",
|
|
117
117
|
"sinon": "^11.0.0",
|
|
118
118
|
"tslib": "^2.1.0",
|
|
119
|
-
"typescript": "^
|
|
119
|
+
"typescript": "^5.0.2",
|
|
120
120
|
"uglify-js": "^3.4.9",
|
|
121
121
|
"webpack": "^5.36.2",
|
|
122
122
|
"webpack-cli": "^4.6.0"
|
package/src/apiClient.ts
CHANGED
|
@@ -8,7 +8,7 @@ import {
|
|
|
8
8
|
SDKEvent,
|
|
9
9
|
} from './sdkRuntimeModels';
|
|
10
10
|
import KitBlocker from './kitBlocking';
|
|
11
|
-
import { Dictionary } from './utils';
|
|
11
|
+
import { Dictionary, getRampNumber } from './utils';
|
|
12
12
|
import { IUploadObject } from './serverModel';
|
|
13
13
|
|
|
14
14
|
const Messages = Constants.Messages;
|
|
@@ -67,9 +67,7 @@ export default function APIClient(
|
|
|
67
67
|
return false;
|
|
68
68
|
}
|
|
69
69
|
|
|
70
|
-
const rampNumber = mpInstance.
|
|
71
|
-
mpInstance._Store.deviceId
|
|
72
|
-
);
|
|
70
|
+
const rampNumber = getRampNumber(mpInstance._Store.deviceId);
|
|
73
71
|
return eventsV3Percentage >= rampNumber;
|
|
74
72
|
};
|
|
75
73
|
|
package/src/configAPIClient.ts
CHANGED
|
@@ -29,8 +29,9 @@ export interface IKitConfigs {
|
|
|
29
29
|
eventNameFilters: number[];
|
|
30
30
|
eventTypeFilters: number[];
|
|
31
31
|
attributeFilters: number[];
|
|
32
|
-
filteringEventAttributeValue:
|
|
33
|
-
|
|
32
|
+
filteringEventAttributeValue: IFilteringAttributeValue;
|
|
33
|
+
filteringUserAttributeValue: IFilteringAttributeValue;
|
|
34
|
+
filteringConsentRuleValues: IFilteringConsentRulesValue;
|
|
34
35
|
consentRegulationFilters: number[];
|
|
35
36
|
consentRegulationPurposeFilters: number[];
|
|
36
37
|
messageTypeFilters: number[];
|
|
@@ -39,6 +40,22 @@ export interface IKitConfigs {
|
|
|
39
40
|
excludeAnonymousUser: boolean;
|
|
40
41
|
}
|
|
41
42
|
|
|
43
|
+
export interface IFilteringAttributeValue {
|
|
44
|
+
eventAttributeName: string;
|
|
45
|
+
eventAttributeValue: string;
|
|
46
|
+
includeOnMatch: boolean
|
|
47
|
+
}
|
|
48
|
+
export interface IFilteringConsentRulesValue {
|
|
49
|
+
includeOnMatch: boolean;
|
|
50
|
+
values: IConsentRuleValue[];
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
export interface IConsentRuleValue {
|
|
54
|
+
consentPurpose: string;
|
|
55
|
+
hasConsented: boolean
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
|
|
42
59
|
export interface IPixelConfig {
|
|
43
60
|
name: string;
|
|
44
61
|
moduleId: number;
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { MParticleUser, SDKEvent, SDKEventCustomFlags, SDKUserIdentity } from './sdkRuntimeModels';
|
|
2
|
+
import { Dictionary } from './utils';
|
|
3
|
+
import { IKitConfigs } from './configAPIClient';
|
|
4
|
+
import { UserAttributes } from './persistence.interfaces';
|
|
5
|
+
import { IdentityApiData } from '@mparticle/web-sdk';
|
|
6
|
+
|
|
7
|
+
// The state of the kit when accessed via window.KitName via CDN
|
|
8
|
+
// or imported as an NPM package
|
|
9
|
+
export interface UnregisteredKit {
|
|
10
|
+
register(config): void;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
// The state of the kit after being added to forwarderConstructors in the CDN
|
|
14
|
+
// or after registered to SDKConfig.kits via NPM
|
|
15
|
+
export interface RegisteredKit {
|
|
16
|
+
constructor(): void;
|
|
17
|
+
name: string;
|
|
18
|
+
getId(): number;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
// The state of the kit after being configured. This is what the kit looks like when acted on.
|
|
22
|
+
export interface ConfiguredKit
|
|
23
|
+
extends Omit<IKitConfigs, 'isDebugString' | 'hasDebugString'> {
|
|
24
|
+
common: Dictionary<unknown>;
|
|
25
|
+
init(
|
|
26
|
+
settings: Dictionary<unknown>,
|
|
27
|
+
service: forwardingStatsCallback,
|
|
28
|
+
testMode: boolean,
|
|
29
|
+
trackerId: string | null,
|
|
30
|
+
userAttributes: UserAttributes,
|
|
31
|
+
userIdentities: SDKUserIdentity,
|
|
32
|
+
appVersion: string,
|
|
33
|
+
appName: string,
|
|
34
|
+
customFlags: SDKEventCustomFlags,
|
|
35
|
+
clientId: string): string;
|
|
36
|
+
onIdentifyComplete(user: MParticleUser, filteredIdentityRequest: IdentityApiData): string | KitMappedMethodFailure;
|
|
37
|
+
onLoginComplete(user: MParticleUser, filteredIdentityRequest: IdentityApiData): string | KitMappedMethodFailure;
|
|
38
|
+
onLogoutComplete(user: MParticleUser, filteredIdentityRequest: IdentityApiData): string | KitMappedMethodFailure;
|
|
39
|
+
onModifyComplete(user: MParticleUser, filteredIdentityRequest: IdentityApiData): string | KitMappedMethodFailure;
|
|
40
|
+
onUserIdentified(user: MParticleUser): string | KitMappedMethodFailure;
|
|
41
|
+
process(event: SDKEvent): string;
|
|
42
|
+
setOptOut(isOptingOut: boolean): string | KitMappedMethodFailure;
|
|
43
|
+
removeUserAttribute(key: string): string;
|
|
44
|
+
setUserAttribute(key: string, value:string): string;
|
|
45
|
+
|
|
46
|
+
// TODO: Convert type to enum during Identity migration
|
|
47
|
+
// https://go.mparticle.com/work/SQDSDKS-5218
|
|
48
|
+
setUserIdentity(id: UserIdentityId, type: UserIdentityType): void;
|
|
49
|
+
|
|
50
|
+
// TODO: https://go.mparticle.com/work/SQDSDKS-5156
|
|
51
|
+
isSandbox: boolean;
|
|
52
|
+
hasSandbox: boolean;
|
|
53
|
+
}
|
|
54
|
+
export interface KitMappedMethodFailure {
|
|
55
|
+
error: string
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
export type UserIdentityId = string;
|
|
59
|
+
export type UserIdentityType = number;
|
|
60
|
+
|
|
61
|
+
export type forwardingStatsCallback = (forwarder: ConfiguredKit, event: SDKEvent) => void;
|
package/src/forwarders.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import Types from './types';
|
|
2
2
|
import filteredMparticleUser from './filteredMparticleUser';
|
|
3
|
+
import { isEmpty } from './utils';
|
|
3
4
|
|
|
4
5
|
export default function Forwarders(mpInstance, kitBlocker) {
|
|
5
6
|
var self = this;
|
|
@@ -59,7 +60,6 @@ export default function Forwarders(mpInstance, kitBlocker) {
|
|
|
59
60
|
user ? user.getAllUserAttributes() : {},
|
|
60
61
|
forwarder.userAttributeFilters
|
|
61
62
|
);
|
|
62
|
-
|
|
63
63
|
if (!forwarder.initialized) {
|
|
64
64
|
forwarder.logger = mpInstance.Logger;
|
|
65
65
|
forwarder.init(
|
|
@@ -524,19 +524,59 @@ export default function Forwarders(mpInstance, kitBlocker) {
|
|
|
524
524
|
mpInstance._Persistence.forwardingStatsBatches.forwardingStatsEventQueue = queue;
|
|
525
525
|
};
|
|
526
526
|
|
|
527
|
-
|
|
527
|
+
// Processing forwarders is a 2 step process:
|
|
528
|
+
// 1. Configure the kit
|
|
529
|
+
// 2. Initialize the kit
|
|
530
|
+
// There are 2 types of kits:
|
|
531
|
+
// 1. UI-enabled kits
|
|
532
|
+
// 2. Sideloaded kits.
|
|
533
|
+
this.processForwarders = function(config, forwardingStatsCallback) {
|
|
534
|
+
if (!config) {
|
|
535
|
+
mpInstance.Logger.warning(
|
|
536
|
+
'No config was passed. Cannot process forwarders'
|
|
537
|
+
);
|
|
538
|
+
} else {
|
|
539
|
+
this.processUIEnabledKits(config);
|
|
540
|
+
this.processSideloadedKits(config);
|
|
541
|
+
|
|
542
|
+
self.initForwarders(
|
|
543
|
+
mpInstance._Store.SDKConfig.identifyRequest.userIdentities,
|
|
544
|
+
forwardingStatsCallback
|
|
545
|
+
);
|
|
546
|
+
}
|
|
547
|
+
};
|
|
548
|
+
|
|
549
|
+
// These are kits that are enabled via the mParticle UI.
|
|
550
|
+
// A kit that is UI-enabled will have a kit configuration that returns from
|
|
551
|
+
// the server, or in rare cases, is passed in by the developer.
|
|
552
|
+
// The kit configuration will be compared with the kit constructors to determine
|
|
553
|
+
// if there is a match before being initialized.
|
|
554
|
+
// Only kits that are configured properly can be active and used for kit forwarding.
|
|
555
|
+
this.processUIEnabledKits = function(config) {
|
|
556
|
+
try {
|
|
557
|
+
if (Array.isArray(config.kitConfigs) && config.kitConfigs.length) {
|
|
558
|
+
config.kitConfigs.forEach(function(kitConfig) {
|
|
559
|
+
self.configureUIEnabledKit(kitConfig);
|
|
560
|
+
});
|
|
561
|
+
}
|
|
562
|
+
} catch (e) {
|
|
563
|
+
mpInstance.Logger.error(
|
|
564
|
+
'MP Kits not configured propertly. Kits may not be initialized. ' +
|
|
565
|
+
e
|
|
566
|
+
);
|
|
567
|
+
}
|
|
568
|
+
};
|
|
569
|
+
|
|
570
|
+
this.configureUIEnabledKit = function(configuration) {
|
|
528
571
|
var newForwarder = null,
|
|
529
572
|
config = configuration,
|
|
530
573
|
forwarders = {};
|
|
531
574
|
|
|
532
|
-
//
|
|
533
|
-
if (
|
|
534
|
-
mpInstance._Helpers.isObject(mpInstance._Store.SDKConfig.kits) &&
|
|
535
|
-
Object.keys(mpInstance._Store.SDKConfig.kits).length > 0
|
|
536
|
-
) {
|
|
575
|
+
// If there are kits inside of mpInstance._Store.SDKConfig.kits, then mParticle is self hosted
|
|
576
|
+
if (!isEmpty(mpInstance._Store.SDKConfig.kits)) {
|
|
537
577
|
forwarders = mpInstance._Store.SDKConfig.kits;
|
|
538
578
|
// otherwise mParticle is loaded via script tag
|
|
539
|
-
} else if (mpInstance._preInit.forwarderConstructors
|
|
579
|
+
} else if (!isEmpty(mpInstance._preInit.forwarderConstructors)) {
|
|
540
580
|
mpInstance._preInit.forwarderConstructors.forEach(function(
|
|
541
581
|
forwarder
|
|
542
582
|
) {
|
|
@@ -552,38 +592,10 @@ export default function Forwarders(mpInstance, kitBlocker) {
|
|
|
552
592
|
config.isSandbox ===
|
|
553
593
|
mpInstance._Store.SDKConfig.isDevelopmentMode
|
|
554
594
|
) {
|
|
555
|
-
newForwarder =
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
newForwarder.hasSandbox = config.hasDebugString === 'true';
|
|
560
|
-
newForwarder.isVisible = config.isVisible;
|
|
561
|
-
newForwarder.settings = config.settings;
|
|
562
|
-
|
|
563
|
-
newForwarder.eventNameFilters = config.eventNameFilters;
|
|
564
|
-
newForwarder.eventTypeFilters = config.eventTypeFilters;
|
|
565
|
-
newForwarder.attributeFilters = config.attributeFilters;
|
|
566
|
-
|
|
567
|
-
newForwarder.screenNameFilters = config.screenNameFilters;
|
|
568
|
-
newForwarder.screenNameFilters = config.screenNameFilters;
|
|
569
|
-
newForwarder.screenAttributeFilters =
|
|
570
|
-
config.screenAttributeFilters;
|
|
571
|
-
|
|
572
|
-
newForwarder.userIdentityFilters =
|
|
573
|
-
config.userIdentityFilters;
|
|
574
|
-
newForwarder.userAttributeFilters =
|
|
575
|
-
config.userAttributeFilters;
|
|
576
|
-
|
|
577
|
-
newForwarder.filteringEventAttributeValue =
|
|
578
|
-
config.filteringEventAttributeValue;
|
|
579
|
-
newForwarder.filteringUserAttributeValue =
|
|
580
|
-
config.filteringUserAttributeValue;
|
|
581
|
-
newForwarder.eventSubscriptionId =
|
|
582
|
-
config.eventSubscriptionId;
|
|
583
|
-
newForwarder.filteringConsentRuleValues =
|
|
584
|
-
config.filteringConsentRuleValues;
|
|
585
|
-
newForwarder.excludeAnonymousUser =
|
|
586
|
-
config.excludeAnonymousUser;
|
|
595
|
+
newForwarder = this.returnConfiguredKit(
|
|
596
|
+
forwarders[name],
|
|
597
|
+
config
|
|
598
|
+
);
|
|
587
599
|
|
|
588
600
|
mpInstance._Store.configuredForwarders.push(newForwarder);
|
|
589
601
|
break;
|
|
@@ -592,6 +604,84 @@ export default function Forwarders(mpInstance, kitBlocker) {
|
|
|
592
604
|
}
|
|
593
605
|
};
|
|
594
606
|
|
|
607
|
+
// Sideloaded kits are not configured in the UI and do not have kit configurations
|
|
608
|
+
// They are automatically added to active forwarders.
|
|
609
|
+
|
|
610
|
+
// TODO: Sideloading kits currently requires the use of a register method
|
|
611
|
+
// which requires an object on which to be registered.
|
|
612
|
+
// In the future, when all kits are moved to the config rather than
|
|
613
|
+
// there being a separate process for MP configured kits and
|
|
614
|
+
// sideloaded kits, this will need to be refactored.
|
|
615
|
+
this.processSideloadedKits = function(config) {
|
|
616
|
+
try {
|
|
617
|
+
if (Array.isArray(config.sideloadedKits)) {
|
|
618
|
+
const sideloadedKits = { kits: {} };
|
|
619
|
+
// First register each kit's constructor onto sideloadedKits,
|
|
620
|
+
// which is typed { kits: Dictionary<constructor> }.
|
|
621
|
+
// The constructors are keyed by the name of the kit.
|
|
622
|
+
config.sideloadedKits.forEach(function(sideloadedKit) {
|
|
623
|
+
sideloadedKit.register(sideloadedKits);
|
|
624
|
+
});
|
|
625
|
+
|
|
626
|
+
// Then configure each kit
|
|
627
|
+
for (const registeredKitKey in sideloadedKits.kits) {
|
|
628
|
+
const kitConstructor =
|
|
629
|
+
sideloadedKits.kits[registeredKitKey];
|
|
630
|
+
self.configureSideloadedKit(kitConstructor);
|
|
631
|
+
}
|
|
632
|
+
}
|
|
633
|
+
} catch (e) {
|
|
634
|
+
mpInstance.Logger.error(
|
|
635
|
+
'Sideloaded Kits not configured propertly. Kits may not be initialized. ' +
|
|
636
|
+
e
|
|
637
|
+
);
|
|
638
|
+
}
|
|
639
|
+
};
|
|
640
|
+
|
|
641
|
+
// kits can be included via mParticle UI, or via sideloaded kit config API
|
|
642
|
+
this.configureSideloadedKit = function(kitConstructor) {
|
|
643
|
+
mpInstance._Store.configuredForwarders.push(
|
|
644
|
+
this.returnConfiguredKit(kitConstructor)
|
|
645
|
+
);
|
|
646
|
+
};
|
|
647
|
+
|
|
648
|
+
this.returnConfiguredKit = function(forwarder, config = {}) {
|
|
649
|
+
const newForwarder = new forwarder.constructor();
|
|
650
|
+
newForwarder.id = config.moduleId;
|
|
651
|
+
|
|
652
|
+
// TODO: isSandbox, hasSandbox is never used in any kit or in core SDK.
|
|
653
|
+
// isVisible. Investigate is only used in 1 place. It is always true if
|
|
654
|
+
// it is sent to JS. Investigate further to determine if these can be removed.
|
|
655
|
+
// https://go.mparticle.com/work/SQDSDKS-5156
|
|
656
|
+
newForwarder.isSandbox = config.isDebug || config.isSandbox;
|
|
657
|
+
newForwarder.hasSandbox = config.hasDebugString === 'true';
|
|
658
|
+
newForwarder.isVisible = config.isVisible || true;
|
|
659
|
+
newForwarder.settings = config.settings || {};
|
|
660
|
+
|
|
661
|
+
newForwarder.eventNameFilters = config.eventNameFilters || [];
|
|
662
|
+
newForwarder.eventTypeFilters = config.eventTypeFilters || [];
|
|
663
|
+
newForwarder.attributeFilters = config.attributeFilters || [];
|
|
664
|
+
|
|
665
|
+
newForwarder.screenNameFilters = config.screenNameFilters || [];
|
|
666
|
+
newForwarder.screenAttributeFilters =
|
|
667
|
+
config.screenAttributeFilters || [];
|
|
668
|
+
|
|
669
|
+
newForwarder.userIdentityFilters = config.userIdentityFilters || [];
|
|
670
|
+
newForwarder.userAttributeFilters = config.userAttributeFilters || [];
|
|
671
|
+
|
|
672
|
+
newForwarder.filteringEventAttributeValue =
|
|
673
|
+
config.filteringEventAttributeValue || {};
|
|
674
|
+
newForwarder.filteringUserAttributeValue =
|
|
675
|
+
config.filteringUserAttributeValue || {};
|
|
676
|
+
newForwarder.eventSubscriptionId = config.eventSubscriptionId || null;
|
|
677
|
+
newForwarder.filteringConsentRuleValues =
|
|
678
|
+
config.filteringConsentRuleValues || {};
|
|
679
|
+
newForwarder.excludeAnonymousUser =
|
|
680
|
+
config.excludeAnonymousUser || false;
|
|
681
|
+
|
|
682
|
+
return newForwarder;
|
|
683
|
+
};
|
|
684
|
+
|
|
595
685
|
this.configurePixel = function(settings) {
|
|
596
686
|
if (
|
|
597
687
|
settings.isDebug ===
|
|
@@ -603,39 +693,18 @@ export default function Forwarders(mpInstance, kitBlocker) {
|
|
|
603
693
|
}
|
|
604
694
|
};
|
|
605
695
|
|
|
606
|
-
this.
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
try {
|
|
613
|
-
if (
|
|
614
|
-
Array.isArray(config.kitConfigs) &&
|
|
615
|
-
config.kitConfigs.length
|
|
616
|
-
) {
|
|
617
|
-
config.kitConfigs.forEach(function(kitConfig) {
|
|
618
|
-
self.configureForwarder(kitConfig);
|
|
619
|
-
});
|
|
620
|
-
}
|
|
621
|
-
|
|
622
|
-
if (
|
|
623
|
-
Array.isArray(config.pixelConfigs) &&
|
|
624
|
-
config.pixelConfigs.length
|
|
625
|
-
) {
|
|
626
|
-
config.pixelConfigs.forEach(function(pixelConfig) {
|
|
627
|
-
self.configurePixel(pixelConfig);
|
|
628
|
-
});
|
|
629
|
-
}
|
|
630
|
-
self.initForwarders(
|
|
631
|
-
mpInstance._Store.SDKConfig.identifyRequest.userIdentities,
|
|
632
|
-
forwardingStatsCallback
|
|
633
|
-
);
|
|
634
|
-
} catch (e) {
|
|
635
|
-
mpInstance.Logger.error(
|
|
636
|
-
'Config was not parsed propertly. Forwarders may not be initialized.'
|
|
637
|
-
);
|
|
696
|
+
this.processPixelConfigs = function(config) {
|
|
697
|
+
try {
|
|
698
|
+
if (!isEmpty(config.pixelConfigs)) {
|
|
699
|
+
config.pixelConfigs.forEach(function(pixelConfig) {
|
|
700
|
+
self.configurePixel(pixelConfig);
|
|
701
|
+
});
|
|
638
702
|
}
|
|
703
|
+
} catch (e) {
|
|
704
|
+
mpInstance.Logger.error(
|
|
705
|
+
'Cookie Sync configs not configured propertly. Cookie Sync may not be initialized. ' +
|
|
706
|
+
e
|
|
707
|
+
);
|
|
639
708
|
}
|
|
640
709
|
};
|
|
641
710
|
}
|
package/src/helpers.js
CHANGED
|
@@ -26,17 +26,6 @@ export default function Helpers(mpInstance) {
|
|
|
26
26
|
return null;
|
|
27
27
|
};
|
|
28
28
|
|
|
29
|
-
/**
|
|
30
|
-
* Returns a value between 1-100 inclusive.
|
|
31
|
-
*/
|
|
32
|
-
this.getRampNumber = function(deviceId) {
|
|
33
|
-
if (!deviceId) {
|
|
34
|
-
return 100;
|
|
35
|
-
}
|
|
36
|
-
var hash = self.generateHash(deviceId);
|
|
37
|
-
return Math.abs(hash % 100) + 1;
|
|
38
|
-
};
|
|
39
|
-
|
|
40
29
|
this.invokeCallback = function(
|
|
41
30
|
callback,
|
|
42
31
|
code,
|
|
@@ -284,39 +273,6 @@ export default function Helpers(mpInstance) {
|
|
|
284
273
|
return xhr;
|
|
285
274
|
};
|
|
286
275
|
|
|
287
|
-
function generateRandomValue(a) {
|
|
288
|
-
var randomValue;
|
|
289
|
-
if (window.crypto && window.crypto.getRandomValues) {
|
|
290
|
-
randomValue = window.crypto.getRandomValues(new Uint8Array(1)); // eslint-disable-line no-undef
|
|
291
|
-
}
|
|
292
|
-
if (randomValue) {
|
|
293
|
-
return (a ^ (randomValue[0] % 16 >> (a / 4))).toString(16);
|
|
294
|
-
}
|
|
295
|
-
|
|
296
|
-
return (a ^ ((Math.random() * 16) >> (a / 4))).toString(16);
|
|
297
|
-
}
|
|
298
|
-
|
|
299
|
-
this.generateUniqueId = function(a) {
|
|
300
|
-
// https://gist.github.com/jed/982883
|
|
301
|
-
// Added support for crypto for better random
|
|
302
|
-
|
|
303
|
-
return a // if the placeholder was passed, return
|
|
304
|
-
? generateRandomValue(a) // a random number
|
|
305
|
-
: // or otherwise a concatenated string:
|
|
306
|
-
(
|
|
307
|
-
[1e7] + // 10000000 +
|
|
308
|
-
-1e3 + // -1000 +
|
|
309
|
-
-4e3 + // -4000 +
|
|
310
|
-
-8e3 + // -80000000 +
|
|
311
|
-
-1e11
|
|
312
|
-
) // -100000000000,
|
|
313
|
-
.replace(
|
|
314
|
-
// replacing
|
|
315
|
-
/[018]/g, // zeroes, ones, and eights with
|
|
316
|
-
self.generateUniqueId // random hex digits
|
|
317
|
-
);
|
|
318
|
-
};
|
|
319
|
-
|
|
320
276
|
this.filterUserIdentities = function(userIdentitiesObject, filterList) {
|
|
321
277
|
var filteredUserIdentities = [];
|
|
322
278
|
|
|
@@ -403,37 +359,6 @@ export default function Helpers(mpInstance) {
|
|
|
403
359
|
return false;
|
|
404
360
|
};
|
|
405
361
|
|
|
406
|
-
this.generateHash = function(name) {
|
|
407
|
-
var hash = 0,
|
|
408
|
-
i = 0,
|
|
409
|
-
character;
|
|
410
|
-
|
|
411
|
-
if (name === undefined || name === null) {
|
|
412
|
-
return 0;
|
|
413
|
-
}
|
|
414
|
-
|
|
415
|
-
name = name.toString().toLowerCase();
|
|
416
|
-
|
|
417
|
-
if (Array.prototype.reduce) {
|
|
418
|
-
return name.split('').reduce(function(a, b) {
|
|
419
|
-
a = (a << 5) - a + b.charCodeAt(0);
|
|
420
|
-
return a & a;
|
|
421
|
-
}, 0);
|
|
422
|
-
}
|
|
423
|
-
|
|
424
|
-
if (name.length === 0) {
|
|
425
|
-
return hash;
|
|
426
|
-
}
|
|
427
|
-
|
|
428
|
-
for (i = 0; i < name.length; i++) {
|
|
429
|
-
character = name.charCodeAt(i);
|
|
430
|
-
hash = (hash << 5) - hash + character;
|
|
431
|
-
hash = hash & hash;
|
|
432
|
-
}
|
|
433
|
-
|
|
434
|
-
return hash;
|
|
435
|
-
};
|
|
436
|
-
|
|
437
362
|
this.sanitizeAttributes = function(attrs, name) {
|
|
438
363
|
if (!attrs || !self.isObject(attrs)) {
|
|
439
364
|
return null;
|
|
@@ -501,6 +426,8 @@ export default function Helpers(mpInstance) {
|
|
|
501
426
|
}
|
|
502
427
|
};
|
|
503
428
|
|
|
429
|
+
// TODO: Refactor SDK to directly use these methods
|
|
430
|
+
// https://go.mparticle.com/work/SQDSDKS-5239
|
|
504
431
|
// Utility Functions
|
|
505
432
|
this.converted = utils.converted;
|
|
506
433
|
this.findKeyInObject = utils.findKeyInObject;
|
|
@@ -510,6 +437,8 @@ export default function Helpers(mpInstance) {
|
|
|
510
437
|
this.decoded = utils.decoded;
|
|
511
438
|
this.returnConvertedBoolean = utils.returnConvertedBoolean;
|
|
512
439
|
this.parseStringOrNumber = utils.parseStringOrNumber;
|
|
440
|
+
this.generateHash = utils.generateHash;
|
|
441
|
+
this.generateUniqueId = utils.generateUniqueId;
|
|
513
442
|
|
|
514
443
|
// Imported Validators
|
|
515
444
|
this.Validators = Validators;
|
package/src/mockBatchCreator.ts
CHANGED
package/src/mp-instance.js
CHANGED
|
@@ -1421,6 +1421,8 @@ function completeSDKInitialization(apiKey, config, mpInstance) {
|
|
|
1421
1421
|
mpInstance._APIClient.prepareForwardingStats
|
|
1422
1422
|
);
|
|
1423
1423
|
|
|
1424
|
+
mpInstance._Forwarders.processPixelConfigs(config);
|
|
1425
|
+
|
|
1424
1426
|
mpInstance._SessionManager.initialize();
|
|
1425
1427
|
mpInstance._Events.logAST();
|
|
1426
1428
|
|
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
import { Context } from '@mparticle/event-models';
|
|
2
|
+
import {
|
|
3
|
+
AllUserAttributes,
|
|
4
|
+
ConsentState,
|
|
5
|
+
IdentityApiData,
|
|
6
|
+
MPID,
|
|
7
|
+
Product,
|
|
8
|
+
UserIdentities,
|
|
9
|
+
} from '@mparticle/web-sdk';
|
|
10
|
+
import { ForwardingStatsData } from './apiClient';
|
|
11
|
+
import {
|
|
12
|
+
IntegrationAttributes,
|
|
13
|
+
ServerSettings,
|
|
14
|
+
SessionAttributes,
|
|
15
|
+
} from './store';
|
|
16
|
+
import { Dictionary } from './utils';
|
|
17
|
+
|
|
18
|
+
export type CookieSyncDate = Dictionary<string>;
|
|
19
|
+
export type UploadsTable = Dictionary<any>;
|
|
20
|
+
export interface iForwardingStatsBatches {
|
|
21
|
+
uploadsTable: UploadsTable;
|
|
22
|
+
forwardingStatsEventQueue: ForwardingStatsData[];
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
// TODO: Migrate this to @types/mparticle__web-sdk
|
|
26
|
+
// https://go.mparticle.com/work/SQDSDKS-5196
|
|
27
|
+
export type UserAttributes = AllUserAttributes;
|
|
28
|
+
|
|
29
|
+
export interface IGlobalStoreV2MinifiedKeys {
|
|
30
|
+
sid: string; // Session ID
|
|
31
|
+
ie: boolean; // Is Enabled
|
|
32
|
+
sa: SessionAttributes;
|
|
33
|
+
ss: ServerSettings;
|
|
34
|
+
dt: string; // Dev Token
|
|
35
|
+
av: string; // App Version
|
|
36
|
+
cgid: string; // Client Generated ID
|
|
37
|
+
das: string; // Device ID/ Device Application String
|
|
38
|
+
ia: IntegrationAttributes;
|
|
39
|
+
c: Context;
|
|
40
|
+
csm: MPID[]; // Current Session MPIDs
|
|
41
|
+
les: number; // Last Event Sent Timestamp
|
|
42
|
+
ssd: number; // Session Start Date
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
export interface IPersistenceMinified extends Dictionary {
|
|
46
|
+
cu: MPID; // Current User MPID
|
|
47
|
+
gs: IGlobalStoreV2MinifiedKeys;
|
|
48
|
+
l: false; // IsLoggedIn
|
|
49
|
+
|
|
50
|
+
// Persistence Minified can also store optional dictionaries with
|
|
51
|
+
// an idex of MPID
|
|
52
|
+
// [mpid: MPID]: Dictionary<any>;
|
|
53
|
+
|
|
54
|
+
// For Example:
|
|
55
|
+
// {
|
|
56
|
+
// cu: '123345',
|
|
57
|
+
// gs: {
|
|
58
|
+
// sid: '123',
|
|
59
|
+
// ie: false,
|
|
60
|
+
// sa: {},
|
|
61
|
+
// ss: {},
|
|
62
|
+
// dt: '',
|
|
63
|
+
// av: '',
|
|
64
|
+
// cgid: '123',
|
|
65
|
+
// das: 'das',
|
|
66
|
+
// ia: {},
|
|
67
|
+
// c: null,
|
|
68
|
+
// csm: ['123'],
|
|
69
|
+
// les: 0,
|
|
70
|
+
// ssd: 0,
|
|
71
|
+
// },
|
|
72
|
+
// l: false,
|
|
73
|
+
// MPID1: {
|
|
74
|
+
// csd: [],
|
|
75
|
+
// ui: {
|
|
76
|
+
// customerid: '12346',
|
|
77
|
+
// },
|
|
78
|
+
// },
|
|
79
|
+
// };
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
export interface IPersistence {
|
|
83
|
+
useLocalStorage(): boolean;
|
|
84
|
+
initializeStorage(): void;
|
|
85
|
+
update(): void;
|
|
86
|
+
storeProductsInMemory(products: Product[], mpid: MPID): void;
|
|
87
|
+
storeDataInMemory(obj: IPersistenceMinified, currentMPID: MPID): void;
|
|
88
|
+
determineLocalStorageAvailability(storage: Storage): boolean;
|
|
89
|
+
getUserProductsFromLS(mpid: MPID): Product[];
|
|
90
|
+
getAllUserProductsFromLS(): Product[];
|
|
91
|
+
setLocalStorage(): void;
|
|
92
|
+
getLocalStorage(): IPersistenceMinified | null;
|
|
93
|
+
expireCookies(cookieName: string): void;
|
|
94
|
+
getCookie(): IPersistenceMinified | null;
|
|
95
|
+
setCookie(): void;
|
|
96
|
+
reduceAndEncodePersistence(
|
|
97
|
+
persistence: IPersistenceMinified,
|
|
98
|
+
expires: string,
|
|
99
|
+
domain: string,
|
|
100
|
+
maxCookieSize: number
|
|
101
|
+
): void;
|
|
102
|
+
findPrevCookiesBasedOnUI(identityApiData: IdentityApiData): void;
|
|
103
|
+
encodePersistence(persistance: IPersistenceMinified): string;
|
|
104
|
+
decodePersistence(persistance: IPersistenceMinified): string;
|
|
105
|
+
replaceCommasWithPipes(string: string): string;
|
|
106
|
+
replacePipesWithCommas(string: string): string;
|
|
107
|
+
replaceApostrophesWithQuotes(string: string): string;
|
|
108
|
+
replaceQuotesWithApostrophes(string: string): string;
|
|
109
|
+
createCookieString(string: string): string;
|
|
110
|
+
revertCookieString(string: string): string;
|
|
111
|
+
getCookieDomain(): string;
|
|
112
|
+
getDomain(doc: string, locationHostname: string): string;
|
|
113
|
+
getUserIdentities(mpid: MPID): UserIdentities;
|
|
114
|
+
getAllUserAttributes(mpid: MPID): AllUserAttributes;
|
|
115
|
+
getCartProducts(mpid: MPID): Product[];
|
|
116
|
+
setCartProducts(allProducts: Product[]): void;
|
|
117
|
+
saveUserIdentitiesToPersistence(
|
|
118
|
+
mpid: MPID,
|
|
119
|
+
userIdentities: UserIdentities
|
|
120
|
+
): void;
|
|
121
|
+
saveUserAttributesToPersistence(
|
|
122
|
+
mpid: MPID,
|
|
123
|
+
userAttributes: UserAttributes
|
|
124
|
+
): void;
|
|
125
|
+
saveUserCookieSyncDatesToPersistence(mpid: MPID, csd: CookieSyncDate): void;
|
|
126
|
+
saveUserConsentStateToCookies(mpid, consentState: ConsentState): void;
|
|
127
|
+
savePersistence(persistance: IPersistenceMinified): void;
|
|
128
|
+
getPersistence(): IPersistenceMinified;
|
|
129
|
+
getConsentState(mpid: MPID): ConsentState | null;
|
|
130
|
+
getFirstSeenTime(mpid: MPID): string | null;
|
|
131
|
+
setFirstSeenTime(mpid: MPID, time: number): void;
|
|
132
|
+
getLastSeenTime(mpid: MPID): number | null;
|
|
133
|
+
setLastSeenTime(mpid: MPID, time: number): void;
|
|
134
|
+
getDeviceId(): string;
|
|
135
|
+
setDeviceId(guid: string): void;
|
|
136
|
+
resetPersistence(): void;
|
|
137
|
+
forwardingStatsBatches: iForwardingStatsBatches;
|
|
138
|
+
}
|