@mparticle/web-sdk 2.26.1 → 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.common.js +74 -53
- package/dist/mparticle.esm.js +74 -53
- package/dist/mparticle.js +1139 -1099
- package/package.json +1 -1
- package/src/identity.js +158 -218
- package/src/identityApiClient.js +2 -0
- package/src/persistence.interfaces.ts +1 -2
- package/src/persistence.js +17 -0
- package/src/sdkRuntimeModels.ts +12 -6
- package/src/serverModel.ts +4 -0
- package/src/store.ts +18 -0
- package/src/type-utils.ts +66 -0
- package/src/types.js +3 -44
- package/src/user-utils.ts +12 -0
- package/src/utils.ts +4 -0
package/src/sdkRuntimeModels.ts
CHANGED
|
@@ -26,7 +26,10 @@ export interface SDKEvent {
|
|
|
26
26
|
IsFirstRun: boolean;
|
|
27
27
|
EventName: string;
|
|
28
28
|
EventCategory: number;
|
|
29
|
+
|
|
30
|
+
// https://go.mparticle.com/work/SQDSDKS-5196
|
|
29
31
|
UserAttributes?: { [key: string]: string | string[] | null };
|
|
32
|
+
|
|
30
33
|
UserIdentities?: SDKUserIdentity[];
|
|
31
34
|
SourceMessageId: string;
|
|
32
35
|
MPID: string;
|
|
@@ -304,13 +307,16 @@ export interface SDKConfigApi {
|
|
|
304
307
|
onCreateBatch(batch: EventsApi.Batch): EventsApi.Batch;
|
|
305
308
|
}
|
|
306
309
|
|
|
307
|
-
//
|
|
308
|
-
// https://go.mparticle.com/work/SQDSDKS-5033
|
|
310
|
+
// https://go.mparticle.com/work/SQDSDKS-5033
|
|
309
311
|
export interface MParticleUser {
|
|
310
|
-
getMPID(): string;
|
|
311
|
-
getConsentState(): SDKConsentState;
|
|
312
|
-
|
|
313
|
-
|
|
312
|
+
getMPID?(): string;
|
|
313
|
+
getConsentState?(): SDKConsentState;
|
|
314
|
+
|
|
315
|
+
// https://go.mparticle.com/work/SQDSDKS-5196
|
|
316
|
+
getAllUserAttributes?(): any;
|
|
317
|
+
|
|
318
|
+
getUserIdentities?(): IdentityApiData;
|
|
319
|
+
isLoggedIn?(): boolean;
|
|
314
320
|
}
|
|
315
321
|
|
|
316
322
|
export interface SDKUserIdentityChangeData {
|
package/src/serverModel.ts
CHANGED
|
@@ -27,6 +27,7 @@ import {
|
|
|
27
27
|
IPrivacyV2DTO,
|
|
28
28
|
SDKConsentState,
|
|
29
29
|
} from './consent';
|
|
30
|
+
import { UserAttributes } from './persistence.interfaces';
|
|
30
31
|
|
|
31
32
|
const MessageType = Types.MessageType;
|
|
32
33
|
const ApplicationTransitionType = Types.ApplicationTransitionType;
|
|
@@ -47,7 +48,10 @@ export interface IServerV2DTO {
|
|
|
47
48
|
dp_v?: number;
|
|
48
49
|
n?: string;
|
|
49
50
|
et?: number;
|
|
51
|
+
|
|
52
|
+
// https://go.mparticle.com/work/SQDSDKS-5196
|
|
50
53
|
ua?: Dictionary<string | string[]>;
|
|
54
|
+
|
|
51
55
|
ui?: SDKUserIdentity[];
|
|
52
56
|
ia?: Dictionary<Dictionary<string>>;
|
|
53
57
|
str?: ServerSettings;
|
package/src/store.ts
CHANGED
|
@@ -26,6 +26,7 @@ import {
|
|
|
26
26
|
isEmpty,
|
|
27
27
|
isNumber,
|
|
28
28
|
isObject,
|
|
29
|
+
moveElementToEnd,
|
|
29
30
|
parseNumber,
|
|
30
31
|
returnConvertedBoolean,
|
|
31
32
|
} from './utils';
|
|
@@ -185,6 +186,7 @@ export interface IStore {
|
|
|
185
186
|
getLastSeenTime?(mpid: MPID): number;
|
|
186
187
|
setLastSeenTime?(mpid: MPID, time?: number): void;
|
|
187
188
|
|
|
189
|
+
addMpidToSessionHistory?(mpid: MPID, previousMpid?: MPID): void;
|
|
188
190
|
hasInvalidIdentifyRequest?: () => boolean;
|
|
189
191
|
nullifySession?: () => void;
|
|
190
192
|
processConfig(config: SDKInitConfig): void;
|
|
@@ -493,6 +495,22 @@ export default function Store(
|
|
|
493
495
|
mpInstance._Persistence.update();
|
|
494
496
|
};
|
|
495
497
|
|
|
498
|
+
this.addMpidToSessionHistory = (mpid: MPID, previousMPID?: MPID): void => {
|
|
499
|
+
const indexOfMPID = this.currentSessionMPIDs.indexOf(mpid);
|
|
500
|
+
|
|
501
|
+
if (mpid && previousMPID !== mpid && indexOfMPID < 0) {
|
|
502
|
+
this.currentSessionMPIDs.push(mpid);
|
|
503
|
+
return;
|
|
504
|
+
}
|
|
505
|
+
|
|
506
|
+
if (indexOfMPID >= 0) {
|
|
507
|
+
this.currentSessionMPIDs = moveElementToEnd(
|
|
508
|
+
this.currentSessionMPIDs,
|
|
509
|
+
indexOfMPID
|
|
510
|
+
);
|
|
511
|
+
}
|
|
512
|
+
};
|
|
513
|
+
|
|
496
514
|
this.getFirstSeenTime = (mpid: MPID) => {
|
|
497
515
|
if (!mpid) {
|
|
498
516
|
return null;
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import { IdentityType } from './types.interfaces';
|
|
2
|
+
import { parseNumber } from './utils';
|
|
3
|
+
|
|
4
|
+
export interface IIdentitiesByType {
|
|
5
|
+
[key: number]: string;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
export function getNewIdentitiesByName(newIdentitiesByType: IIdentitiesByType) {
|
|
9
|
+
const newIdentitiesByName = {};
|
|
10
|
+
|
|
11
|
+
for (var key in newIdentitiesByType) {
|
|
12
|
+
const identityNameKey = getIdentityName(parseNumber(key));
|
|
13
|
+
newIdentitiesByName[identityNameKey] = newIdentitiesByType[key];
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
return newIdentitiesByName;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export function getIdentityName(identityType: IdentityType): string | null {
|
|
20
|
+
switch (identityType) {
|
|
21
|
+
case IdentityType.Other:
|
|
22
|
+
return 'other';
|
|
23
|
+
case IdentityType.CustomerId:
|
|
24
|
+
return 'customerid';
|
|
25
|
+
case IdentityType.Facebook:
|
|
26
|
+
return 'facebook';
|
|
27
|
+
case IdentityType.Twitter:
|
|
28
|
+
return 'twitter';
|
|
29
|
+
case IdentityType.Google:
|
|
30
|
+
return 'google';
|
|
31
|
+
case IdentityType.Microsoft:
|
|
32
|
+
return 'microsoft';
|
|
33
|
+
case IdentityType.Yahoo:
|
|
34
|
+
return 'yahoo';
|
|
35
|
+
case IdentityType.Email:
|
|
36
|
+
return 'email';
|
|
37
|
+
case IdentityType.FacebookCustomAudienceId:
|
|
38
|
+
return 'facebookcustomaudienceid';
|
|
39
|
+
case IdentityType.Other2:
|
|
40
|
+
return 'other2';
|
|
41
|
+
case IdentityType.Other3:
|
|
42
|
+
return 'other3';
|
|
43
|
+
case IdentityType.Other4:
|
|
44
|
+
return 'other4';
|
|
45
|
+
case IdentityType.Other5:
|
|
46
|
+
return 'other5';
|
|
47
|
+
case IdentityType.Other6:
|
|
48
|
+
return 'other6';
|
|
49
|
+
case IdentityType.Other7:
|
|
50
|
+
return 'other7';
|
|
51
|
+
case IdentityType.Other8:
|
|
52
|
+
return 'other8';
|
|
53
|
+
case IdentityType.Other9:
|
|
54
|
+
return 'other9';
|
|
55
|
+
case IdentityType.Other10:
|
|
56
|
+
return 'other10';
|
|
57
|
+
case IdentityType.MobileNumber:
|
|
58
|
+
return 'mobile_number';
|
|
59
|
+
case IdentityType.PhoneNumber2:
|
|
60
|
+
return 'phone_number_2';
|
|
61
|
+
case IdentityType.PhoneNumber3:
|
|
62
|
+
return 'phone_number_3';
|
|
63
|
+
default:
|
|
64
|
+
return null;
|
|
65
|
+
}
|
|
66
|
+
}
|
package/src/types.js
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { getIdentityName } from './type-utils';
|
|
2
|
+
|
|
1
3
|
var MessageType = {
|
|
2
4
|
SessionStart: 1,
|
|
3
5
|
SessionEnd: 2,
|
|
@@ -209,50 +211,7 @@ IdentityType.getIdentityType = function(identityName) {
|
|
|
209
211
|
};
|
|
210
212
|
|
|
211
213
|
IdentityType.getIdentityName = function(identityType) {
|
|
212
|
-
|
|
213
|
-
case IdentityType.Other:
|
|
214
|
-
return 'other';
|
|
215
|
-
case IdentityType.CustomerId:
|
|
216
|
-
return 'customerid';
|
|
217
|
-
case IdentityType.Facebook:
|
|
218
|
-
return 'facebook';
|
|
219
|
-
case IdentityType.Twitter:
|
|
220
|
-
return 'twitter';
|
|
221
|
-
case IdentityType.Google:
|
|
222
|
-
return 'google';
|
|
223
|
-
case IdentityType.Microsoft:
|
|
224
|
-
return 'microsoft';
|
|
225
|
-
case IdentityType.Yahoo:
|
|
226
|
-
return 'yahoo';
|
|
227
|
-
case IdentityType.Email:
|
|
228
|
-
return 'email';
|
|
229
|
-
case IdentityType.FacebookCustomAudienceId:
|
|
230
|
-
return 'facebookcustomaudienceid';
|
|
231
|
-
case IdentityType.Other2:
|
|
232
|
-
return 'other2';
|
|
233
|
-
case IdentityType.Other3:
|
|
234
|
-
return 'other3';
|
|
235
|
-
case IdentityType.Other4:
|
|
236
|
-
return 'other4';
|
|
237
|
-
case IdentityType.Other5:
|
|
238
|
-
return 'other5';
|
|
239
|
-
case IdentityType.Other6:
|
|
240
|
-
return 'other6';
|
|
241
|
-
case IdentityType.Other7:
|
|
242
|
-
return 'other7';
|
|
243
|
-
case IdentityType.Other8:
|
|
244
|
-
return 'other8';
|
|
245
|
-
case IdentityType.Other9:
|
|
246
|
-
return 'other9';
|
|
247
|
-
case IdentityType.Other10:
|
|
248
|
-
return 'other10';
|
|
249
|
-
case IdentityType.MobileNumber:
|
|
250
|
-
return 'mobile_number';
|
|
251
|
-
case IdentityType.PhoneNumber2:
|
|
252
|
-
return 'phone_number_2';
|
|
253
|
-
case IdentityType.PhoneNumber3:
|
|
254
|
-
return 'phone_number_3';
|
|
255
|
-
}
|
|
214
|
+
return getIdentityName(identityType);
|
|
256
215
|
};
|
|
257
216
|
|
|
258
217
|
var ProductActionType = {
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { MParticleUser } from './sdkRuntimeModels';
|
|
2
|
+
|
|
3
|
+
export function didUserChange(
|
|
4
|
+
previousUser: MParticleUser,
|
|
5
|
+
newUser: MParticleUser
|
|
6
|
+
): boolean {
|
|
7
|
+
return (
|
|
8
|
+
!previousUser ||
|
|
9
|
+
newUser.getMPID() !== previousUser.getMPID() ||
|
|
10
|
+
previousUser.isLoggedIn() !== newUser.isLoggedIn()
|
|
11
|
+
);
|
|
12
|
+
}
|
package/src/utils.ts
CHANGED
|
@@ -227,6 +227,9 @@ const mergeObjects = <T extends object>(...objects: T[]): T => {
|
|
|
227
227
|
return Object.assign({}, ...objects);
|
|
228
228
|
};
|
|
229
229
|
|
|
230
|
+
const moveElementToEnd = <T>(array: T[], index: number): T[] =>
|
|
231
|
+
array.slice(0, index).concat(array.slice(index + 1), array[index]);
|
|
232
|
+
|
|
230
233
|
export {
|
|
231
234
|
createCookieString,
|
|
232
235
|
revertCookieString,
|
|
@@ -256,4 +259,5 @@ export {
|
|
|
256
259
|
isEmpty,
|
|
257
260
|
isValidCustomFlagProperty,
|
|
258
261
|
mergeObjects,
|
|
262
|
+
moveElementToEnd,
|
|
259
263
|
};
|