@mparticle/web-sdk 2.79.2 → 2.80.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +52 -0
- package/dist/mparticle.common.js +156 -56
- package/dist/mparticle.esm.js +156 -56
- package/dist/mparticle.js +941 -708
- package/dist/types/src/filteredMparticleUser.d.ts +15 -7
- package/dist/types/src/forwardingStatsUploader.d.ts +4 -4
- package/dist/types/src/mp-instance.d.ts +3 -2
- package/dist/types/src/nativeSdkHelpers.d.ts +3 -12
- package/dist/types/src/nativeSdkHelpers.interfaces.d.ts +15 -1
- package/dist/types/src/pageViewTracker.d.ts +35 -24
- package/dist/types/src/persistence.d.ts +3 -44
- package/dist/types/src/persistence.interfaces.d.ts +10 -10
- package/dist/types/src/sdkRuntimeModels.d.ts +5 -3
- package/dist/types/src/store.d.ts +3 -0
- package/package.json +1 -1
- package/src/events.ts +9 -1
- package/src/filteredMparticleUser.ts +160 -0
- package/src/{forwardingStatsUploader.js → forwardingStatsUploader.ts} +25 -12
- package/src/mp-instance.ts +27 -25
- package/src/nativeSdkHelpers.interfaces.ts +21 -1
- package/src/{nativeSdkHelpers.js → nativeSdkHelpers.ts} +59 -34
- package/src/pageViewTracker.ts +475 -281
- package/src/persistence.interfaces.ts +10 -10
- package/src/persistence.ts +1210 -0
- package/src/sdkRuntimeModels.ts +5 -3
- package/src/store.ts +3 -0
- package/src/filteredMparticleUser.js +0 -101
- package/src/persistence.js +0 -985
|
@@ -1,8 +1,16 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
import { IMParticleWebSDKInstance } from './mp-instance';
|
|
2
|
+
import { MPID } from '@mparticle/web-sdk';
|
|
3
|
+
import { Dictionary } from './utils';
|
|
4
|
+
import KitBlocker from './kitBlocking';
|
|
5
|
+
import { MPForwarder } from './forwarders.interfaces';
|
|
6
|
+
export interface IFilteredMparticleUser {
|
|
7
|
+
getUserIdentities(): {
|
|
8
|
+
userIdentities: Dictionary<string>;
|
|
4
9
|
};
|
|
5
|
-
getMPID
|
|
6
|
-
getUserAttributesLists
|
|
7
|
-
getAllUserAttributes
|
|
8
|
-
}
|
|
10
|
+
getMPID(): MPID;
|
|
11
|
+
getUserAttributesLists(forwarder: MPForwarder): Dictionary<string[]>;
|
|
12
|
+
getAllUserAttributes(): Dictionary;
|
|
13
|
+
}
|
|
14
|
+
export default function filteredMparticleUser(mpid: MPID, forwarder: MPForwarder | {
|
|
15
|
+
userAttributeFilters: number[];
|
|
16
|
+
}, mpInstance: IMParticleWebSDKInstance, kitBlocker?: KitBlocker): IFilteredMparticleUser;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
export
|
|
3
|
-
|
|
4
|
-
startForwardingStatsTimer: () => void;
|
|
1
|
+
import { IMParticleWebSDKInstance } from './mp-instance';
|
|
2
|
+
export interface IForwardingStatsUploader {
|
|
3
|
+
startForwardingStatsTimer(): void;
|
|
5
4
|
}
|
|
5
|
+
export default function forwardingStatsUploader(this: IForwardingStatsUploader, mpInstance: IMParticleWebSDKInstance): void;
|
|
@@ -3,7 +3,7 @@ import { ICookieSyncManager } from './cookieSyncManager';
|
|
|
3
3
|
import { ISessionManager } from './sessionManager';
|
|
4
4
|
import { IStore } from './store';
|
|
5
5
|
import { IServerModel } from './serverModel';
|
|
6
|
-
import
|
|
6
|
+
import { IForwardingStatsUploader } from './forwardingStatsUploader';
|
|
7
7
|
import { IConsent } from './consent';
|
|
8
8
|
import IdentityAPIClient from './identityApiClient';
|
|
9
9
|
import IntegrationCapture from './integrationCapture';
|
|
@@ -39,7 +39,7 @@ export interface IMParticleWebSDKInstance extends MParticleWebSDK {
|
|
|
39
39
|
_Ecommerce: IECommerce;
|
|
40
40
|
_Events: IEvents;
|
|
41
41
|
_Forwarders: any;
|
|
42
|
-
_ForwardingStatsUploader:
|
|
42
|
+
_ForwardingStatsUploader: IForwardingStatsUploader;
|
|
43
43
|
_Helpers: SDKHelpersApi;
|
|
44
44
|
_Identity: IIdentity;
|
|
45
45
|
_IdentityAPIClient: typeof IdentityAPIClient;
|
|
@@ -62,6 +62,7 @@ export interface IMParticleWebSDKInstance extends MParticleWebSDK {
|
|
|
62
62
|
captureTiming(metricName: string): any;
|
|
63
63
|
processQueueOnIdentityFailure?: () => void;
|
|
64
64
|
processQueueOnNoFunctional?: () => void;
|
|
65
|
+
uiwebviewBridgeName?: string;
|
|
65
66
|
}
|
|
66
67
|
/**
|
|
67
68
|
* <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>
|
|
@@ -1,12 +1,3 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
initializeSessionAttributes: (apiKey: any) => void;
|
|
5
|
-
isBridgeV2Available: (bridgeName: any) => boolean;
|
|
6
|
-
isWebviewEnabled: (requiredWebviewBridgeName: any, minWebviewBridgeVersion: any) => any;
|
|
7
|
-
isBridgeV1Available: () => boolean;
|
|
8
|
-
sendToNative: (path: any, value: any) => void;
|
|
9
|
-
sendViaBridgeV1: (path: any, value: any) => void;
|
|
10
|
-
sendViaIframeToIOS: (path: any, value: any) => void;
|
|
11
|
-
sendViaBridgeV2: (path: any, value: any, requiredWebviewBridgeName: any) => void;
|
|
12
|
-
}
|
|
1
|
+
import { IMParticleWebSDKInstance } from './mp-instance';
|
|
2
|
+
import { INativeSdkHelpers } from './nativeSdkHelpers.interfaces';
|
|
3
|
+
export default function NativeSdkHelpers(this: INativeSdkHelpers, mpInstance: IMParticleWebSDKInstance): void;
|
|
@@ -1,3 +1,17 @@
|
|
|
1
|
+
export interface IWKScriptMessageHandler {
|
|
2
|
+
postMessage(message: string): void;
|
|
3
|
+
}
|
|
4
|
+
export interface IAndroidNativeBridge {
|
|
5
|
+
[methodName: string]: ((payload?: string) => void) | undefined;
|
|
6
|
+
}
|
|
7
|
+
declare global {
|
|
8
|
+
interface Window {
|
|
9
|
+
webkit?: {
|
|
10
|
+
messageHandlers?: Record<string, IWKScriptMessageHandler | undefined>;
|
|
11
|
+
};
|
|
12
|
+
mParticleAndroid?: IAndroidNativeBridge;
|
|
13
|
+
}
|
|
14
|
+
}
|
|
1
15
|
export interface INativeSdkHelpers {
|
|
2
16
|
initializeSessionAttributes: (apiKey: string) => void;
|
|
3
17
|
isBridgeV2Available: (bridgeName: string) => boolean;
|
|
@@ -6,5 +20,5 @@ export interface INativeSdkHelpers {
|
|
|
6
20
|
sendToNative: (path: string, value?: string) => void;
|
|
7
21
|
sendViaBridgeV1: (path: string, value: string) => void;
|
|
8
22
|
sendViaIframeToIOS: (path: string, value: string) => void;
|
|
9
|
-
sendViaBridgeV2: (path: string, value: string, requiredWebviewBridgeName:
|
|
23
|
+
sendViaBridgeV2: (path: string, value: string, requiredWebviewBridgeName: string) => void;
|
|
10
24
|
}
|
|
@@ -1,34 +1,45 @@
|
|
|
1
1
|
import { IMParticleWebSDKInstance } from './mp-instance';
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
2
|
+
import { BaseEvent } from './sdkRuntimeModels';
|
|
3
|
+
import { Dictionary } from './utils';
|
|
4
|
+
type HistoryMethodName = 'pushState' | 'replaceState';
|
|
5
|
+
type NavigationSource = HistoryMethodName | 'popstate';
|
|
6
|
+
export declare const WIN_APV_KEY = "__mpApv__";
|
|
7
|
+
export declare const ALLOWED_QUERY_PARAMS: string[];
|
|
8
|
+
interface IPageSnapshot {
|
|
9
|
+
path: string;
|
|
10
|
+
params: Dictionary<string>;
|
|
11
|
+
}
|
|
12
|
+
interface IPageViewData extends IPageSnapshot {
|
|
13
|
+
hostname: string;
|
|
14
|
+
title: string;
|
|
15
|
+
}
|
|
16
|
+
export declare const allowedQueryParams: (href: string) => Dictionary<string>;
|
|
17
|
+
export declare const pageKey: (page: IPageSnapshot) => string;
|
|
18
|
+
export declare const isNewPage: (lastKey: string | null, candidateKey: string) => boolean;
|
|
19
|
+
export declare const supportsHistoryTracking: (win: Window | null) => boolean;
|
|
20
|
+
export declare const buildPageViewEvent: ({ params, hostname, title, path, }: IPageViewData) => BaseEvent;
|
|
21
|
+
export declare const getActiveTracker: () => PageViewTracker | undefined;
|
|
22
|
+
export declare const hasInitialPageViewFired: () => boolean;
|
|
23
|
+
export declare const markInitialPageViewFired: () => void;
|
|
24
|
+
export declare const resetPageViewTracking: () => void;
|
|
25
|
+
export declare const patchHistory: (onNavigate: (source: NavigationSource) => void, log: (message: string) => void) => (() => void) | null;
|
|
8
26
|
export declare class PageViewTracker {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
mpInstance: IMParticleWebSDKInstance;
|
|
13
|
-
private lastPath;
|
|
14
|
-
private _isActive;
|
|
15
|
-
get isActive(): boolean;
|
|
27
|
+
private readonly mpInstance;
|
|
28
|
+
private lastPage;
|
|
29
|
+
private active;
|
|
16
30
|
private pendingNavigations;
|
|
17
|
-
private
|
|
18
|
-
private originalReplaceState;
|
|
19
|
-
private pushStateWrapper;
|
|
20
|
-
private replaceStateWrapper;
|
|
31
|
+
private undoHistoryPatch;
|
|
21
32
|
private popStateListener;
|
|
22
33
|
constructor(mpInstance: IMParticleWebSDKInstance);
|
|
23
|
-
|
|
34
|
+
get isActive(): boolean;
|
|
24
35
|
init(): void;
|
|
25
|
-
|
|
26
|
-
private
|
|
36
|
+
teardown(): void;
|
|
37
|
+
private retire;
|
|
38
|
+
private takePendingNavigations;
|
|
27
39
|
private safeHandleNavigation;
|
|
28
|
-
private getCurrentKey;
|
|
29
40
|
private handleNavigation;
|
|
41
|
+
private scheduleFire;
|
|
30
42
|
private firePageView;
|
|
31
|
-
|
|
32
|
-
private restoreHistoryMethod;
|
|
33
|
-
teardown(): void;
|
|
43
|
+
private log;
|
|
34
44
|
}
|
|
45
|
+
export {};
|
|
@@ -1,44 +1,3 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
useLocalStorage: () => any;
|
|
5
|
-
initializeStorage: () => void;
|
|
6
|
-
update: () => void;
|
|
7
|
-
storeDataInMemory: (obj: any, currentMPID: any) => void;
|
|
8
|
-
determineLocalStorageAvailability: (storage: any) => any;
|
|
9
|
-
setLocalStorage: () => void;
|
|
10
|
-
getLocalStorage: () => {};
|
|
11
|
-
expireCookies: (cookieName: any) => void;
|
|
12
|
-
getCookie: () => any;
|
|
13
|
-
setCookie: () => void;
|
|
14
|
-
reduceAndEncodePersistence: (persistence: any, expires: any, domain: any, maxCookieSize: any) => string;
|
|
15
|
-
findPrevCookiesBasedOnUI: (identityApiData: any) => void;
|
|
16
|
-
encodePersistence: (persistence: any) => string;
|
|
17
|
-
decodePersistence: (persistence: any) => string;
|
|
18
|
-
getCookieDomain: () => any;
|
|
19
|
-
getDomain: (doc: any, locationHostname: any) => any;
|
|
20
|
-
saveUserCookieSyncDatesToPersistence: (mpid: any, csd: any) => void;
|
|
21
|
-
swapCurrentUser: (previousMPID: any, currentMPID: any, currentSessionMPIDs: any) => void;
|
|
22
|
-
savePersistence: (persistence: any) => void;
|
|
23
|
-
getPersistence: () => any;
|
|
24
|
-
getFirstSeenTime: (mpid: any) => any;
|
|
25
|
-
/**
|
|
26
|
-
* set the "first seen" time for a user. the time will only be set once for a given
|
|
27
|
-
* mpid after which subsequent calls will be ignored
|
|
28
|
-
*/
|
|
29
|
-
setFirstSeenTime: (mpid: any, time: any) => void;
|
|
30
|
-
/**
|
|
31
|
-
* returns the "last seen" time for a user. If the mpid represents the current user, the
|
|
32
|
-
* return value will always be the current time, otherwise it will be to stored "last seen"
|
|
33
|
-
* time
|
|
34
|
-
*/
|
|
35
|
-
getLastSeenTime: (mpid: any) => any;
|
|
36
|
-
setLastSeenTime: (mpid: any, time: any) => void;
|
|
37
|
-
getDeviceId: () => any;
|
|
38
|
-
setDeviceId: (guid: any) => void;
|
|
39
|
-
resetPersistence: () => void;
|
|
40
|
-
forwardingStatsBatches: {
|
|
41
|
-
uploadsTable: {};
|
|
42
|
-
forwardingStatsEventQueue: any[];
|
|
43
|
-
};
|
|
44
|
-
}
|
|
1
|
+
import { IMParticleWebSDKInstance } from './mp-instance';
|
|
2
|
+
import { IPersistence } from './persistence.interfaces';
|
|
3
|
+
export default function _Persistence(this: IPersistence, mpInstance: IMParticleWebSDKInstance): void;
|
|
@@ -30,7 +30,7 @@ export interface IGlobalStoreV2MinifiedKeys {
|
|
|
30
30
|
export interface IPersistenceMinified extends Dictionary {
|
|
31
31
|
cu: MPID;
|
|
32
32
|
gs: IGlobalStoreV2MinifiedKeys;
|
|
33
|
-
l: boolean;
|
|
33
|
+
l: boolean | 0 | 1;
|
|
34
34
|
}
|
|
35
35
|
export interface IUserPersistenceMinified extends Dictionary {
|
|
36
36
|
csd: CookieSyncDates;
|
|
@@ -45,8 +45,8 @@ export interface IPersistence {
|
|
|
45
45
|
useLocalStorage(): boolean;
|
|
46
46
|
initializeStorage(): void;
|
|
47
47
|
update(): void;
|
|
48
|
-
storeDataInMemory(obj: IPersistenceMinified, currentMPID
|
|
49
|
-
determineLocalStorageAvailability(storage
|
|
48
|
+
storeDataInMemory(obj: IPersistenceMinified, currentMPID?: MPID): void;
|
|
49
|
+
determineLocalStorageAvailability(storage?: Storage): boolean;
|
|
50
50
|
setLocalStorage(): void;
|
|
51
51
|
getLocalStorage(): IPersistenceMinified | null;
|
|
52
52
|
expireCookies(cookieName: string): void;
|
|
@@ -54,17 +54,17 @@ export interface IPersistence {
|
|
|
54
54
|
setCookie(): void;
|
|
55
55
|
reduceAndEncodePersistence(persistence: IPersistenceMinified, expires: string, domain: string, maxCookieSize: number): string;
|
|
56
56
|
findPrevCookiesBasedOnUI(identityApiData: IdentityApiData): void;
|
|
57
|
-
encodePersistence(persistence:
|
|
58
|
-
decodePersistence(persistenceString: string): string;
|
|
57
|
+
encodePersistence(persistence: string): string;
|
|
58
|
+
decodePersistence(persistenceString: string | null): string | void;
|
|
59
59
|
getCookieDomain(): string;
|
|
60
|
-
getDomain(doc:
|
|
60
|
+
getDomain(doc: Document, locationHostname: string): string;
|
|
61
61
|
saveUserCookieSyncDatesToPersistence(mpid: MPID, csd: CookieSyncDates): void;
|
|
62
62
|
savePersistence(persistance: IPersistenceMinified): void;
|
|
63
|
-
getPersistence(): IPersistenceMinified;
|
|
64
|
-
getFirstSeenTime(mpid: MPID):
|
|
65
|
-
setFirstSeenTime(mpid: MPID, time
|
|
63
|
+
getPersistence(): IPersistenceMinified | null;
|
|
64
|
+
getFirstSeenTime(mpid: MPID): number | null;
|
|
65
|
+
setFirstSeenTime(mpid: MPID, time?: number): void;
|
|
66
66
|
getLastSeenTime(mpid: MPID): number | null;
|
|
67
|
-
setLastSeenTime(mpid: MPID, time
|
|
67
|
+
setLastSeenTime(mpid: MPID, time?: number): void;
|
|
68
68
|
getDeviceId(): string;
|
|
69
69
|
setDeviceId(guid: string): void;
|
|
70
70
|
resetPersistence(): void;
|
|
@@ -197,6 +197,7 @@ export interface IMParticleInstanceManager extends MParticleWebSDK {
|
|
|
197
197
|
_BatchValidator: _BatchValidator;
|
|
198
198
|
_instances: Dictionary<IMParticleWebSDKInstance>;
|
|
199
199
|
_isTestEnv?: boolean;
|
|
200
|
+
_forceNoLocalStorage?: boolean;
|
|
200
201
|
config: SDKInitConfig;
|
|
201
202
|
isIOS?: boolean;
|
|
202
203
|
MPSideloadedKit: typeof MPSideloadedKit;
|
|
@@ -204,6 +205,7 @@ export interface IMParticleInstanceManager extends MParticleWebSDK {
|
|
|
204
205
|
sessionManager: Pick<ISessionManager, 'getSession'>;
|
|
205
206
|
Store: IStore;
|
|
206
207
|
getInstance(instanceName?: string): IMParticleWebSDKInstance;
|
|
208
|
+
uiwebviewBridgeName?: string;
|
|
207
209
|
}
|
|
208
210
|
export type BooleanStringLowerCase = 'false' | 'true';
|
|
209
211
|
export type BooleanStringTitleCase = 'False' | 'True';
|
|
@@ -260,7 +262,7 @@ export interface SDKHelpersApi {
|
|
|
260
262
|
createXHR?(cb: () => void): XMLHttpRequest;
|
|
261
263
|
extend?(...args: any[]): any;
|
|
262
264
|
findKeyInObject?(obj: any, key: string): string;
|
|
263
|
-
parseNumber
|
|
265
|
+
parseNumber(value: string | number): number;
|
|
264
266
|
generateUniqueId(): any;
|
|
265
267
|
generateHash?(value: string): number;
|
|
266
268
|
getFeatureFlag?(feature: string): boolean | string;
|
|
@@ -268,8 +270,8 @@ export interface SDKHelpersApi {
|
|
|
268
270
|
parseStringOrNumber?(value: string | number): string | number | null;
|
|
269
271
|
inArray?(items: any[], value: any): boolean;
|
|
270
272
|
converted?(s: string): string;
|
|
271
|
-
filterUserIdentitiesForForwarders
|
|
272
|
-
filterUserAttributes
|
|
273
|
+
filterUserIdentitiesForForwarders(userIdentities: Dictionary, filterList: number[]): Dictionary;
|
|
274
|
+
filterUserAttributes(userAttributes: Dictionary, filterList: number[]): Dictionary;
|
|
273
275
|
filterUserIdentities?(userIdentitiesObject: Dictionary<string>, filterList: number[]): ISDKUserIdentity[];
|
|
274
276
|
invokeAliasCallback(aliasCallback: IAliasCallback, number: number, errorMessage?: string): void;
|
|
275
277
|
isDelayedByIntegration?(delayedIntegrations: Dictionary<boolean>, timeoutStart: number, now: number): boolean;
|
|
@@ -29,6 +29,7 @@ export interface SDKConfig {
|
|
|
29
29
|
kits: Dictionary<UnregisteredKit>;
|
|
30
30
|
logLevel?: LogLevelType;
|
|
31
31
|
cookieDomain?: string;
|
|
32
|
+
cookieExpiration?: number;
|
|
32
33
|
maxCookieSize?: number | undefined;
|
|
33
34
|
minWebviewBridgeVersion: 1 | 2 | undefined;
|
|
34
35
|
identifyRequest: IdentifyRequest;
|
|
@@ -124,6 +125,8 @@ export interface IStore {
|
|
|
124
125
|
pixelConfigurations: IPixelConfiguration[];
|
|
125
126
|
integrationDelayTimeoutStart: number;
|
|
126
127
|
webviewBridgeEnabled?: boolean;
|
|
128
|
+
bridgeV1Available?: boolean;
|
|
129
|
+
bridgeV2Available?: boolean;
|
|
127
130
|
wrapperSDKInfo: WrapperSDKInfo;
|
|
128
131
|
roktAccountId: string | null;
|
|
129
132
|
integrationName: string | null;
|
package/package.json
CHANGED
package/src/events.ts
CHANGED
|
@@ -20,7 +20,8 @@ import {
|
|
|
20
20
|
SDKEventOptions,
|
|
21
21
|
TransactionAttributes,
|
|
22
22
|
} from '@mparticle/web-sdk';
|
|
23
|
-
import { valueof } from './utils';
|
|
23
|
+
import { getHref, valueof } from './utils';
|
|
24
|
+
import { allowedQueryParams } from './pageViewTracker';
|
|
24
25
|
|
|
25
26
|
interface DOMHandlerElement extends HTMLElement {
|
|
26
27
|
href?: string;
|
|
@@ -144,11 +145,18 @@ export default function Events(
|
|
|
144
145
|
self.logEvent({ messageType: Types.MessageType.AppStateTransition });
|
|
145
146
|
};
|
|
146
147
|
|
|
148
|
+
// The auto page view for the landing page. The SPA navigations that follow it
|
|
149
|
+
// come from PageViewTracker instead, so both emitters attach the same
|
|
150
|
+
// allowlisted query params — and this is the one that matters for campaign
|
|
151
|
+
// attribution, since utm_*/gclid live on the entry URL.
|
|
147
152
|
this.logPageView = function(): void {
|
|
148
153
|
self.logEvent({
|
|
149
154
|
messageType: Types.MessageType.PageView,
|
|
150
155
|
name: 'PageView',
|
|
151
156
|
data: {
|
|
157
|
+
// Params first so the core fields always win. See
|
|
158
|
+
// buildPageViewEvent, which does the same for SPA views.
|
|
159
|
+
...allowedQueryParams(getHref()),
|
|
152
160
|
hostname: window.location.hostname,
|
|
153
161
|
title: window.document.title,
|
|
154
162
|
},
|
|
@@ -0,0 +1,160 @@
|
|
|
1
|
+
import Types from './types';
|
|
2
|
+
import { IMParticleWebSDKInstance } from './mp-instance';
|
|
3
|
+
import { MPID, UserIdentities } from '@mparticle/web-sdk';
|
|
4
|
+
import { Dictionary } from './utils';
|
|
5
|
+
import KitBlocker from './kitBlocking';
|
|
6
|
+
import { MPForwarder } from './forwarders.interfaces';
|
|
7
|
+
|
|
8
|
+
export interface IFilteredMparticleUser {
|
|
9
|
+
getUserIdentities(): { userIdentities: Dictionary<string> };
|
|
10
|
+
getMPID(): MPID;
|
|
11
|
+
getUserAttributesLists(forwarder: MPForwarder): Dictionary<string[]>;
|
|
12
|
+
getAllUserAttributes(): Dictionary;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
function isAttributeKeyAllowed(
|
|
16
|
+
kitBlocker: KitBlocker | undefined,
|
|
17
|
+
key: string
|
|
18
|
+
): boolean {
|
|
19
|
+
return !kitBlocker?.isAttributeKeyBlocked(key);
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
function isIdentityAllowed(
|
|
23
|
+
kitBlocker: KitBlocker | undefined,
|
|
24
|
+
identityName: string
|
|
25
|
+
): boolean {
|
|
26
|
+
return !kitBlocker?.isIdentityBlocked(identityName);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
function copyUserAttributeValue(value: unknown): unknown {
|
|
30
|
+
return Array.isArray(value) ? (value as string[]).slice() : value;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
function buildUserAttributesCopy(
|
|
34
|
+
userAttributes?: Dictionary,
|
|
35
|
+
kitBlocker?: KitBlocker
|
|
36
|
+
): Dictionary {
|
|
37
|
+
const userAttributesCopy: Dictionary = {};
|
|
38
|
+
|
|
39
|
+
if (!userAttributes) {
|
|
40
|
+
return userAttributesCopy;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
for (const prop in userAttributes) {
|
|
44
|
+
if (
|
|
45
|
+
!userAttributes.hasOwnProperty(prop) ||
|
|
46
|
+
!isAttributeKeyAllowed(kitBlocker, prop)
|
|
47
|
+
) {
|
|
48
|
+
continue;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
userAttributesCopy[prop] = copyUserAttributeValue(
|
|
52
|
+
userAttributes[prop]
|
|
53
|
+
);
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
return userAttributesCopy;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
function buildUserAttributeLists(
|
|
60
|
+
userAttributes: Dictionary,
|
|
61
|
+
kitBlocker?: KitBlocker
|
|
62
|
+
): Dictionary<string[]> {
|
|
63
|
+
const userAttributesLists: Dictionary<string[]> = {};
|
|
64
|
+
|
|
65
|
+
for (const key in userAttributes) {
|
|
66
|
+
if (
|
|
67
|
+
!userAttributes.hasOwnProperty(key) ||
|
|
68
|
+
!Array.isArray(userAttributes[key]) ||
|
|
69
|
+
!isAttributeKeyAllowed(kitBlocker, key)
|
|
70
|
+
) {
|
|
71
|
+
continue;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
userAttributesLists[key] = userAttributes[key].slice();
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
return userAttributesLists;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
function buildFilteredUserIdentities(
|
|
81
|
+
identities: UserIdentities,
|
|
82
|
+
kitBlocker: KitBlocker | undefined,
|
|
83
|
+
parseNumber: (value: string | number) => number
|
|
84
|
+
): Dictionary<string> {
|
|
85
|
+
const currentUserIdentities: Dictionary<string> = {};
|
|
86
|
+
const identitiesByType = identities as Dictionary<string>;
|
|
87
|
+
|
|
88
|
+
for (const identityType in identitiesByType) {
|
|
89
|
+
if (!identitiesByType.hasOwnProperty(identityType)) {
|
|
90
|
+
continue;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
const identityName = Types.IdentityType.getIdentityName(
|
|
94
|
+
parseNumber(identityType)
|
|
95
|
+
);
|
|
96
|
+
|
|
97
|
+
if (!isIdentityAllowed(kitBlocker, identityName)) {
|
|
98
|
+
continue;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
currentUserIdentities[identityName] = identitiesByType[identityType];
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
return currentUserIdentities;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
export default function filteredMparticleUser(
|
|
108
|
+
mpid: MPID,
|
|
109
|
+
forwarder: MPForwarder | { userAttributeFilters: number[] },
|
|
110
|
+
mpInstance: IMParticleWebSDKInstance,
|
|
111
|
+
kitBlocker?: KitBlocker
|
|
112
|
+
): IFilteredMparticleUser {
|
|
113
|
+
function getAllUserAttributes(): Dictionary {
|
|
114
|
+
const userAttributesCopy = buildUserAttributesCopy(
|
|
115
|
+
mpInstance._Store.getUserAttributes(mpid),
|
|
116
|
+
kitBlocker
|
|
117
|
+
);
|
|
118
|
+
|
|
119
|
+
return mpInstance._Helpers.filterUserAttributes(
|
|
120
|
+
userAttributesCopy,
|
|
121
|
+
(forwarder as MPForwarder).userAttributeFilters
|
|
122
|
+
);
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
return {
|
|
126
|
+
getUserIdentities: function(): { userIdentities: Dictionary<string> } {
|
|
127
|
+
let currentUserIdentities = buildFilteredUserIdentities(
|
|
128
|
+
mpInstance._Store.getUserIdentities(mpid),
|
|
129
|
+
kitBlocker,
|
|
130
|
+
mpInstance._Helpers.parseNumber
|
|
131
|
+
);
|
|
132
|
+
|
|
133
|
+
currentUserIdentities = mpInstance._Helpers.filterUserIdentitiesForForwarders(
|
|
134
|
+
currentUserIdentities,
|
|
135
|
+
(forwarder as MPForwarder).userIdentityFilters
|
|
136
|
+
);
|
|
137
|
+
|
|
138
|
+
return {
|
|
139
|
+
userIdentities: currentUserIdentities,
|
|
140
|
+
};
|
|
141
|
+
},
|
|
142
|
+
getMPID: function(): MPID {
|
|
143
|
+
return mpid;
|
|
144
|
+
},
|
|
145
|
+
getUserAttributesLists: function(
|
|
146
|
+
forwarder: MPForwarder
|
|
147
|
+
): Dictionary<string[]> {
|
|
148
|
+
const userAttributesLists = buildUserAttributeLists(
|
|
149
|
+
getAllUserAttributes(),
|
|
150
|
+
kitBlocker
|
|
151
|
+
);
|
|
152
|
+
|
|
153
|
+
return mpInstance._Helpers.filterUserAttributes(
|
|
154
|
+
userAttributesLists,
|
|
155
|
+
forwarder.userAttributeFilters
|
|
156
|
+
) as Dictionary<string[]>;
|
|
157
|
+
},
|
|
158
|
+
getAllUserAttributes: getAllUserAttributes,
|
|
159
|
+
};
|
|
160
|
+
}
|
|
@@ -1,12 +1,25 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
import { IMParticleWebSDKInstance } from './mp-instance';
|
|
2
|
+
import { Dictionary } from './utils';
|
|
3
|
+
|
|
4
|
+
export interface IForwardingStatsUploader {
|
|
5
|
+
startForwardingStatsTimer(): void;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
export default function forwardingStatsUploader(
|
|
9
|
+
this: IForwardingStatsUploader,
|
|
10
|
+
mpInstance: IMParticleWebSDKInstance
|
|
11
|
+
): void {
|
|
12
|
+
this.startForwardingStatsTimer = function(): void {
|
|
13
|
+
(window.mParticle as Dictionary)._forwardingStatsTimer = setInterval(
|
|
14
|
+
function() {
|
|
15
|
+
prepareAndSendForwardingStatsBatch();
|
|
16
|
+
},
|
|
17
|
+
(mpInstance._Store.SDKConfig as Dictionary).forwarderStatsTimeout
|
|
18
|
+
);
|
|
6
19
|
};
|
|
7
20
|
|
|
8
|
-
function prepareAndSendForwardingStatsBatch() {
|
|
9
|
-
|
|
21
|
+
function prepareAndSendForwardingStatsBatch(): void {
|
|
22
|
+
const forwarderQueue = mpInstance._Forwarders.getForwarderStatsQueue(),
|
|
10
23
|
uploadsTable =
|
|
11
24
|
mpInstance._Persistence.forwardingStatsBatches.uploadsTable,
|
|
12
25
|
now = Date.now();
|
|
@@ -16,11 +29,11 @@ export default function forwardingStatsUploader(mpInstance) {
|
|
|
16
29
|
mpInstance._Forwarders.setForwarderStatsQueue([]);
|
|
17
30
|
}
|
|
18
31
|
|
|
19
|
-
for (
|
|
20
|
-
(function(date) {
|
|
32
|
+
for (const date in uploadsTable) {
|
|
33
|
+
(function(date: string) {
|
|
21
34
|
if (uploadsTable.hasOwnProperty(date)) {
|
|
22
35
|
if (uploadsTable[date].uploading === false) {
|
|
23
|
-
|
|
36
|
+
const xhrCallback = function(): void {
|
|
24
37
|
if (xhr.readyState === 4) {
|
|
25
38
|
if (xhr.status === 200 || xhr.status === 202) {
|
|
26
39
|
mpInstance.Logger.verbose(
|
|
@@ -39,8 +52,8 @@ export default function forwardingStatsUploader(mpInstance) {
|
|
|
39
52
|
}
|
|
40
53
|
};
|
|
41
54
|
|
|
42
|
-
|
|
43
|
-
|
|
55
|
+
const xhr = mpInstance._Helpers.createXHR(xhrCallback);
|
|
56
|
+
const forwardingStatsData = uploadsTable[date].data;
|
|
44
57
|
uploadsTable[date].uploading = true;
|
|
45
58
|
mpInstance._APIClient.sendBatchForwardingStatsToServer(
|
|
46
59
|
forwardingStatsData,
|