@mparticle/web-sdk 2.32.2 → 2.32.4
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 +46 -74
- package/dist/mparticle.esm.js +46 -74
- package/dist/mparticle.js +558 -579
- package/package.json +1 -1
- package/src/apiClient.ts +8 -4
- package/src/batchUploader.ts +35 -28
- package/src/configAPIClient.ts +3 -3
- package/src/consent.ts +2 -8
- package/src/constants.ts +8 -0
- package/src/cookieSyncManager.ts +2 -2
- package/src/ecommerce.interfaces.ts +201 -0
- package/src/ecommerce.js +9 -0
- package/src/events.interfaces.ts +83 -0
- package/src/events.js +3 -0
- package/src/forwarders.interfaces.ts +0 -3
- package/src/identity-user-interfaces.ts +12 -12
- package/src/identity.js +2 -3
- package/src/identityApiClient.ts +125 -58
- package/src/integrationCapture.ts +19 -15
- package/src/kitBlocking.ts +3 -2
- package/src/kitFilterHelper.ts +6 -7
- package/src/mockBatchCreator.ts +5 -6
- package/src/{mp-instance.js → mp-instance.ts} +110 -61
- package/src/{mparticle-instance-manager.js → mparticle-instance-manager.ts} +29 -16
- package/src/nativeSdkHelpers.interfaces.ts +1 -1
- package/src/pre-init-utils.ts +11 -0
- package/src/sdkRuntimeModels.ts +93 -50
- package/src/sdkToEventsApiConverter.ts +3 -3
- package/src/serverModel.ts +4 -4
- package/src/sessionManager.ts +2 -2
- package/src/sideloadedKit.ts +12 -11
- package/src/store.ts +7 -6
- package/src/types.ts +404 -0
- package/src/uploaders.ts +5 -3
- package/src/utils.ts +1 -1
- package/src/type-utils.ts +0 -66
- package/src/types.interfaces.ts +0 -56
- package/src/types.js +0 -338
package/package.json
CHANGED
package/src/apiClient.ts
CHANGED
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
import Constants from './constants';
|
|
2
2
|
import Types from './types';
|
|
3
3
|
import { BatchUploader } from './batchUploader';
|
|
4
|
-
import {
|
|
4
|
+
import { SDKEvent, SDKDataPlan } from './sdkRuntimeModels';
|
|
5
5
|
import KitBlocker from './kitBlocking';
|
|
6
|
-
import { Dictionary,
|
|
6
|
+
import { Dictionary, isEmpty, parseNumber } from './utils';
|
|
7
7
|
import { IUploadObject } from './serverModel';
|
|
8
8
|
import { MPForwarder } from './forwarders.interfaces';
|
|
9
9
|
import { IMParticleUser, ISDKUserAttributes } from './identity-user-interfaces';
|
|
10
10
|
import { AsyncUploader, FetchUploader, XHRUploader } from './uploaders';
|
|
11
|
+
import { IMParticleWebSDKInstance } from './mp-instance';
|
|
11
12
|
|
|
12
13
|
export interface IAPIClient {
|
|
13
14
|
uploader: BatchUploader | null;
|
|
@@ -43,7 +44,7 @@ export interface IForwardingStatsData {
|
|
|
43
44
|
|
|
44
45
|
export default function APIClient(
|
|
45
46
|
this: IAPIClient,
|
|
46
|
-
mpInstance:
|
|
47
|
+
mpInstance: IMParticleWebSDKInstance,
|
|
47
48
|
kitBlocker: KitBlocker
|
|
48
49
|
) {
|
|
49
50
|
this.uploader = null;
|
|
@@ -135,7 +136,10 @@ export default function APIClient(
|
|
|
135
136
|
this.queueEventForBatchUpload(event);
|
|
136
137
|
}
|
|
137
138
|
|
|
138
|
-
|
|
139
|
+
// https://go.mparticle.com/work/SQDSDKS-6935
|
|
140
|
+
// While Event Name is 'usually' a string, there are some cases where it is a number
|
|
141
|
+
// in that it could be a type of MessageType Enum
|
|
142
|
+
if (event.EventName as unknown as number !== Types.MessageType.AppStateTransition) {
|
|
139
143
|
if (kitBlocker && kitBlocker.kitBlockingEnabled) {
|
|
140
144
|
event = kitBlocker.createBlockedEvent(event);
|
|
141
145
|
}
|
package/src/batchUploader.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { Batch } from '@mparticle/event-models';
|
|
2
2
|
import Constants from './constants';
|
|
3
|
-
import { SDKEvent,
|
|
3
|
+
import { SDKEvent, SDKLoggerApi } from './sdkRuntimeModels';
|
|
4
4
|
import { convertEvents } from './sdkToEventsApiConverter';
|
|
5
|
-
import
|
|
5
|
+
import { MessageType } from './types';
|
|
6
6
|
import { getRampNumber, isEmpty } from './utils';
|
|
7
7
|
import { SessionStorageVault, LocalStorageVault } from './vault';
|
|
8
8
|
import {
|
|
@@ -12,6 +12,7 @@ import {
|
|
|
12
12
|
IFetchPayload,
|
|
13
13
|
} from './uploaders';
|
|
14
14
|
import { IMParticleUser } from './identity-user-interfaces';
|
|
15
|
+
import { IMParticleWebSDKInstance } from './mp-instance';
|
|
15
16
|
|
|
16
17
|
/**
|
|
17
18
|
* BatchUploader contains all the logic to store/retrieve events and batches
|
|
@@ -36,7 +37,7 @@ export class BatchUploader {
|
|
|
36
37
|
uploadIntervalMillis: number;
|
|
37
38
|
eventsQueuedForProcessing: SDKEvent[];
|
|
38
39
|
batchesQueuedForProcessing: Batch[];
|
|
39
|
-
mpInstance:
|
|
40
|
+
mpInstance: IMParticleWebSDKInstance;
|
|
40
41
|
uploadUrl: string;
|
|
41
42
|
batchingEnabled: boolean;
|
|
42
43
|
private eventVault: SessionStorageVault<SDKEvent[]>;
|
|
@@ -46,10 +47,10 @@ export class BatchUploader {
|
|
|
46
47
|
|
|
47
48
|
/**
|
|
48
49
|
* Creates an instance of a BatchUploader
|
|
49
|
-
* @param {
|
|
50
|
+
* @param {IMParticleWebSDKInstance} mpInstance - the mParticle SDK instance
|
|
50
51
|
* @param {number} uploadInterval - the desired upload interval in milliseconds
|
|
51
52
|
*/
|
|
52
|
-
constructor(mpInstance:
|
|
53
|
+
constructor(mpInstance: IMParticleWebSDKInstance, uploadInterval: number) {
|
|
53
54
|
this.mpInstance = mpInstance;
|
|
54
55
|
this.uploadIntervalMillis = uploadInterval;
|
|
55
56
|
this.batchingEnabled =
|
|
@@ -167,29 +168,35 @@ export class BatchUploader {
|
|
|
167
168
|
* @param event event that should be queued
|
|
168
169
|
*/
|
|
169
170
|
public queueEvent(event: SDKEvent): void {
|
|
170
|
-
if (
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
this.eventVault.store(this.eventsQueuedForProcessing);
|
|
174
|
-
}
|
|
175
|
-
this.mpInstance.Logger.verbose(
|
|
176
|
-
`Queuing event: ${JSON.stringify(event)}`
|
|
177
|
-
);
|
|
178
|
-
this.mpInstance.Logger.verbose(
|
|
179
|
-
`Queued event count: ${this.eventsQueuedForProcessing.length}`
|
|
180
|
-
);
|
|
171
|
+
if (isEmpty(event)) {
|
|
172
|
+
return;
|
|
173
|
+
}
|
|
181
174
|
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
175
|
+
const { verbose } = this.mpInstance.Logger;
|
|
176
|
+
|
|
177
|
+
this.eventsQueuedForProcessing.push(event);
|
|
178
|
+
if (this.offlineStorageEnabled && this.eventVault) {
|
|
179
|
+
this.eventVault.store(this.eventsQueuedForProcessing);
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
verbose(`Queuing event: ${JSON.stringify(event)}`);
|
|
183
|
+
verbose(`Queued event count: ${this.eventsQueuedForProcessing.length}`);
|
|
184
|
+
|
|
185
|
+
if (this.shouldTriggerImmediateUpload(event.EventDataType)) {
|
|
186
|
+
this.prepareAndUpload(false, false);
|
|
190
187
|
}
|
|
191
188
|
}
|
|
192
189
|
|
|
190
|
+
// https://go.mparticle.com/work/SQDSDKS-3720
|
|
191
|
+
private shouldTriggerImmediateUpload (eventDataType: number): boolean {
|
|
192
|
+
const priorityEvents = [
|
|
193
|
+
MessageType.Commerce,
|
|
194
|
+
MessageType.UserIdentityChange,
|
|
195
|
+
] as const;
|
|
196
|
+
|
|
197
|
+
return !this.batchingEnabled || priorityEvents.includes(eventDataType as typeof priorityEvents[number]);
|
|
198
|
+
};
|
|
199
|
+
|
|
193
200
|
/**
|
|
194
201
|
* This implements crucial logic to:
|
|
195
202
|
* - bucket pending events by MPID, and then by Session, and upload individual batches for each bucket.
|
|
@@ -202,7 +209,7 @@ export class BatchUploader {
|
|
|
202
209
|
private static createNewBatches(
|
|
203
210
|
sdkEvents: SDKEvent[],
|
|
204
211
|
defaultUser: IMParticleUser,
|
|
205
|
-
mpInstance:
|
|
212
|
+
mpInstance: IMParticleWebSDKInstance
|
|
206
213
|
): Batch[] | null {
|
|
207
214
|
if (!defaultUser || !sdkEvents || !sdkEvents.length) {
|
|
208
215
|
return null;
|
|
@@ -274,9 +281,9 @@ export class BatchUploader {
|
|
|
274
281
|
* @param triggerFuture whether to trigger the loop again - for manual/forced uploads this should be false
|
|
275
282
|
* @param useBeacon whether to use the beacon API - used when the page is being unloaded
|
|
276
283
|
*/
|
|
277
|
-
|
|
278
|
-
triggerFuture: boolean,
|
|
279
|
-
useBeacon: boolean
|
|
284
|
+
public async prepareAndUpload(
|
|
285
|
+
triggerFuture: boolean = false,
|
|
286
|
+
useBeacon: boolean = false,
|
|
280
287
|
): Promise<void> {
|
|
281
288
|
// Fetch current user so that events can be grouped by MPID
|
|
282
289
|
const currentUser = this.mpInstance.Identity.getCurrentUser();
|
package/src/configAPIClient.ts
CHANGED
|
@@ -2,7 +2,6 @@ import { DataPlanConfig } from '@mparticle/web-sdk';
|
|
|
2
2
|
import {
|
|
3
3
|
BooleanStringLowerCase,
|
|
4
4
|
DataPlanResult,
|
|
5
|
-
MParticleWebSDK,
|
|
6
5
|
SDKEventCustomFlags,
|
|
7
6
|
SDKInitConfig,
|
|
8
7
|
} from './sdkRuntimeModels';
|
|
@@ -14,6 +13,7 @@ import {
|
|
|
14
13
|
XHRUploader,
|
|
15
14
|
} from './uploaders';
|
|
16
15
|
import { IPixelConfiguration } from './cookieSyncManager';
|
|
16
|
+
import { IMParticleWebSDKInstance } from './mp-instance';
|
|
17
17
|
|
|
18
18
|
export interface IKitConfigs extends IKitFilterSettings {
|
|
19
19
|
name: string;
|
|
@@ -82,7 +82,7 @@ export interface IConfigResponse {
|
|
|
82
82
|
export interface IConfigAPIClient {
|
|
83
83
|
apiKey: string;
|
|
84
84
|
config: SDKInitConfig;
|
|
85
|
-
mpInstance:
|
|
85
|
+
mpInstance: IMParticleWebSDKInstance;
|
|
86
86
|
getSDKConfiguration: () => Promise<IConfigResponse>;
|
|
87
87
|
}
|
|
88
88
|
|
|
@@ -113,7 +113,7 @@ export default function ConfigAPIClient(
|
|
|
113
113
|
this: IConfigAPIClient,
|
|
114
114
|
apiKey: string,
|
|
115
115
|
config: SDKInitConfig,
|
|
116
|
-
mpInstance:
|
|
116
|
+
mpInstance: IMParticleWebSDKInstance
|
|
117
117
|
): void {
|
|
118
118
|
const baseUrl = 'https://' + mpInstance._Store.SDKConfig.configUrl;
|
|
119
119
|
const { isDevelopmentMode } = config;
|
package/src/consent.ts
CHANGED
|
@@ -4,11 +4,11 @@ import {
|
|
|
4
4
|
GDPRConsentState,
|
|
5
5
|
PrivacyConsentState,
|
|
6
6
|
} from '@mparticle/web-sdk';
|
|
7
|
-
import { MParticleWebSDK } from './sdkRuntimeModels';
|
|
8
7
|
import { Dictionary, isObject } from './utils';
|
|
9
8
|
import KitFilterHelper from './kitFilterHelper';
|
|
10
9
|
import Constants from './constants';
|
|
11
10
|
import { IMParticleUser } from './identity-user-interfaces';
|
|
11
|
+
import { IMParticleWebSDKInstance } from './mp-instance';
|
|
12
12
|
|
|
13
13
|
const { CCPAPurpose } = Constants;
|
|
14
14
|
|
|
@@ -36,12 +36,6 @@ export interface SDKConsentApi {
|
|
|
36
36
|
createGDPRConsent: ICreatePrivacyConsentFunction;
|
|
37
37
|
createCCPAConsent: ICreatePrivacyConsentFunction;
|
|
38
38
|
createConsentState: (consentState?: ConsentState) => ConsentState;
|
|
39
|
-
ConsentSerialization: IConsentSerialization;
|
|
40
|
-
createPrivacyConsent: ICreatePrivacyConsentFunction;
|
|
41
|
-
isEnabledForUserConsent: (
|
|
42
|
-
consentRules: IConsentRules,
|
|
43
|
-
user: IMParticleUser
|
|
44
|
-
) => boolean;
|
|
45
39
|
}
|
|
46
40
|
|
|
47
41
|
export interface IConsentSerialization {
|
|
@@ -120,7 +114,7 @@ export interface IConsent {
|
|
|
120
114
|
ConsentSerialization: IConsentSerialization;
|
|
121
115
|
}
|
|
122
116
|
|
|
123
|
-
export default function Consent(this: IConsent, mpInstance:
|
|
117
|
+
export default function Consent(this: IConsent, mpInstance: IMParticleWebSDKInstance) {
|
|
124
118
|
const self = this;
|
|
125
119
|
|
|
126
120
|
// this function is called when consent is required to
|
package/src/constants.ts
CHANGED
|
@@ -184,6 +184,11 @@ const Constants = {
|
|
|
184
184
|
Login: 'login',
|
|
185
185
|
Identify: 'identify',
|
|
186
186
|
},
|
|
187
|
+
|
|
188
|
+
Environment: {
|
|
189
|
+
Development: 'development',
|
|
190
|
+
Production: 'production',
|
|
191
|
+
},
|
|
187
192
|
} as const;
|
|
188
193
|
|
|
189
194
|
export default Constants;
|
|
@@ -196,4 +201,7 @@ export const MILLIS_IN_ONE_SEC = 1000;
|
|
|
196
201
|
export const HTTP_OK = 200 as const;
|
|
197
202
|
export const HTTP_ACCEPTED = 202 as const;
|
|
198
203
|
export const HTTP_BAD_REQUEST = 400 as const;
|
|
204
|
+
export const HTTP_UNAUTHORIZED = 401 as const;
|
|
199
205
|
export const HTTP_FORBIDDEN = 403 as const;
|
|
206
|
+
export const HTTP_NOT_FOUND = 404 as const;
|
|
207
|
+
export const HTTP_SERVER_ERROR = 500 as const;
|
package/src/cookieSyncManager.ts
CHANGED
|
@@ -4,9 +4,9 @@ import {
|
|
|
4
4
|
createCookieSyncUrl,
|
|
5
5
|
} from './utils';
|
|
6
6
|
import Constants from './constants';
|
|
7
|
-
import { MParticleWebSDK } from './sdkRuntimeModels';
|
|
8
7
|
import { MPID } from '@mparticle/web-sdk';
|
|
9
8
|
import { IConsentRules } from './consent';
|
|
9
|
+
import { IMParticleWebSDKInstance } from './mp-instance';
|
|
10
10
|
|
|
11
11
|
const { Messages } = Constants;
|
|
12
12
|
const { InformationMessages } = Messages;
|
|
@@ -47,7 +47,7 @@ export interface ICookieSyncManager {
|
|
|
47
47
|
|
|
48
48
|
export default function CookieSyncManager(
|
|
49
49
|
this: ICookieSyncManager,
|
|
50
|
-
mpInstance:
|
|
50
|
+
mpInstance: IMParticleWebSDKInstance
|
|
51
51
|
) {
|
|
52
52
|
const self = this;
|
|
53
53
|
|
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
import {
|
|
2
|
+
ProductAction,
|
|
3
|
+
Product,
|
|
4
|
+
Promotion,
|
|
5
|
+
CommerceEvent,
|
|
6
|
+
} from '@mparticle/event-models';
|
|
7
|
+
import {
|
|
8
|
+
SDKEventAttrs,
|
|
9
|
+
SDKEventOptions,
|
|
10
|
+
TransactionAttributes,
|
|
11
|
+
} from '@mparticle/web-sdk';
|
|
12
|
+
import { valueof } from './utils';
|
|
13
|
+
import {
|
|
14
|
+
ProductActionType,
|
|
15
|
+
PromotionActionType,
|
|
16
|
+
CommerceEventType,
|
|
17
|
+
EventType,
|
|
18
|
+
} from './types';
|
|
19
|
+
import {
|
|
20
|
+
SDKEvent,
|
|
21
|
+
SDKEventCustomFlags,
|
|
22
|
+
SDKImpression,
|
|
23
|
+
SDKProduct,
|
|
24
|
+
SDKProductImpression,
|
|
25
|
+
SDKPromotion,
|
|
26
|
+
} from './sdkRuntimeModels';
|
|
27
|
+
|
|
28
|
+
interface IECommerceShared {
|
|
29
|
+
createProduct(
|
|
30
|
+
name: string,
|
|
31
|
+
sku: string | number,
|
|
32
|
+
price: string | number,
|
|
33
|
+
quantity?: string | number,
|
|
34
|
+
variant?: string,
|
|
35
|
+
category?: string,
|
|
36
|
+
brand?: string,
|
|
37
|
+
position?: number,
|
|
38
|
+
couponCode?: string,
|
|
39
|
+
attributes?: SDKEventAttrs
|
|
40
|
+
): SDKProduct | null;
|
|
41
|
+
createImpression(name: string, product: Product): SDKImpression | null;
|
|
42
|
+
createPromotion(
|
|
43
|
+
id: string | number,
|
|
44
|
+
creative?: string,
|
|
45
|
+
name?: string,
|
|
46
|
+
position?: number
|
|
47
|
+
): SDKPromotion | null;
|
|
48
|
+
createTransactionAttributes(
|
|
49
|
+
id: string | number,
|
|
50
|
+
affiliation?: string,
|
|
51
|
+
couponCode?: string,
|
|
52
|
+
revenue?: string | number,
|
|
53
|
+
shipping?: string | number,
|
|
54
|
+
tax?: number
|
|
55
|
+
): TransactionAttributes | null;
|
|
56
|
+
expandCommerceEvent(event: CommerceEvent): SDKEvent[] | null;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
export interface SDKCart {
|
|
60
|
+
add(product: SDKProduct | SDKProduct[], logEvent?: boolean): void;
|
|
61
|
+
remove(product: SDKProduct | SDKProduct[], logEvent?: boolean): void;
|
|
62
|
+
clear(): void;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
// Used for the public `eCommerce` namespace
|
|
66
|
+
export interface SDKECommerceAPI extends IECommerceShared {
|
|
67
|
+
logCheckout(
|
|
68
|
+
step: number,
|
|
69
|
+
option?: string,
|
|
70
|
+
attrs?: SDKEventAttrs,
|
|
71
|
+
customFlags?: SDKEventCustomFlags
|
|
72
|
+
): void;
|
|
73
|
+
logImpression(
|
|
74
|
+
impression: SDKProductImpression,
|
|
75
|
+
attrs?: SDKEventAttrs,
|
|
76
|
+
customFlags?: SDKEventCustomFlags,
|
|
77
|
+
eventOptions?: SDKEventOptions
|
|
78
|
+
): void;
|
|
79
|
+
logProductAction(
|
|
80
|
+
productActionType: valueof<typeof ProductActionType>,
|
|
81
|
+
product: SDKProduct | SDKProduct[],
|
|
82
|
+
attrs?: SDKEventAttrs,
|
|
83
|
+
customFlags?: SDKEventCustomFlags,
|
|
84
|
+
transactionAttributes?: TransactionAttributes,
|
|
85
|
+
eventOptions?: SDKEventOptions
|
|
86
|
+
): void;
|
|
87
|
+
logPromotion(
|
|
88
|
+
type: valueof<typeof PromotionActionType>,
|
|
89
|
+
promotion: SDKPromotion,
|
|
90
|
+
attrs?: SDKEventAttrs,
|
|
91
|
+
customFlags?: SDKEventCustomFlags,
|
|
92
|
+
eventOptions?: SDKEventOptions
|
|
93
|
+
): void;
|
|
94
|
+
setCurrencyCode(code: string): void;
|
|
95
|
+
|
|
96
|
+
/*
|
|
97
|
+
* @deprecated
|
|
98
|
+
*/
|
|
99
|
+
Cart: SDKCart;
|
|
100
|
+
|
|
101
|
+
/*
|
|
102
|
+
* @deprecated
|
|
103
|
+
*/
|
|
104
|
+
logPurchase(
|
|
105
|
+
transactionAttributes: TransactionAttributes,
|
|
106
|
+
product: SDKProduct | SDKProduct[],
|
|
107
|
+
clearCart?: boolean,
|
|
108
|
+
attrs?: SDKEventAttrs,
|
|
109
|
+
customFlags?: SDKEventCustomFlags
|
|
110
|
+
): void;
|
|
111
|
+
|
|
112
|
+
/*
|
|
113
|
+
* @deprecated
|
|
114
|
+
*/
|
|
115
|
+
logRefund(
|
|
116
|
+
transactionAttributes: TransactionAttributes,
|
|
117
|
+
product: SDKProduct | SDKProduct[],
|
|
118
|
+
clearCart?: boolean,
|
|
119
|
+
attrs?: SDKEventAttrs,
|
|
120
|
+
customFlags?: SDKEventCustomFlags
|
|
121
|
+
): void;
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
interface ExtractedActionAttributes {
|
|
125
|
+
Affiliation?: string;
|
|
126
|
+
'Coupon Code'?: string;
|
|
127
|
+
'Total Amount'?: number;
|
|
128
|
+
'Shipping Amount'?: number;
|
|
129
|
+
'Tax Amount'?: number;
|
|
130
|
+
'Checkout Option'?: string;
|
|
131
|
+
'Checkout Step'?: number;
|
|
132
|
+
'Transaction ID'?: string;
|
|
133
|
+
}
|
|
134
|
+
interface ExtractedProductAttributes {
|
|
135
|
+
'Coupon Code'?: string;
|
|
136
|
+
Brand?: string;
|
|
137
|
+
Category?: string;
|
|
138
|
+
Name?: string;
|
|
139
|
+
Id?: string;
|
|
140
|
+
'Item Price'?: number;
|
|
141
|
+
Quantity?: number;
|
|
142
|
+
Position?: number;
|
|
143
|
+
Variant?: string;
|
|
144
|
+
'Total Product Amount': number;
|
|
145
|
+
}
|
|
146
|
+
interface ExtractedPromotionAttributes {
|
|
147
|
+
Id?: string;
|
|
148
|
+
Creative?: string;
|
|
149
|
+
Name?: string;
|
|
150
|
+
Position?: number;
|
|
151
|
+
}
|
|
152
|
+
interface ExtractedTransactionId {
|
|
153
|
+
'Transaction ID'?: string;
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
// Used for the private `_Ecommerce` namespace
|
|
157
|
+
export interface IECommerce extends IECommerceShared {
|
|
158
|
+
buildProductList(event: SDKEvent, product: Product | Product[]): Product[];
|
|
159
|
+
convertProductActionToEventType(
|
|
160
|
+
productActionType: valueof<typeof ProductActionType>
|
|
161
|
+
): // https://go.mparticle.com/work/SQDSDKS-4801
|
|
162
|
+
typeof CommerceEventType | typeof EventType | null;
|
|
163
|
+
convertPromotionActionToEventType(
|
|
164
|
+
promotionActionType: valueof<typeof PromotionActionType>
|
|
165
|
+
): typeof CommerceEventType | null;
|
|
166
|
+
convertTransactionAttributesToProductAction(
|
|
167
|
+
transactionAttributes: TransactionAttributes,
|
|
168
|
+
productAction: ProductAction
|
|
169
|
+
): void;
|
|
170
|
+
createCommerceEventObject(
|
|
171
|
+
customFlags: SDKEventCustomFlags,
|
|
172
|
+
options?: SDKEventOptions
|
|
173
|
+
): SDKEvent | null;
|
|
174
|
+
expandProductAction(commerceEvent: CommerceEvent): SDKEvent[];
|
|
175
|
+
expandProductImpression(commerceEvent: CommerceEvent): SDKEvent[];
|
|
176
|
+
expandPromotionAction(commerceEvent: CommerceEvent): SDKEvent[];
|
|
177
|
+
extractActionAttributes(
|
|
178
|
+
attributes: ExtractedActionAttributes,
|
|
179
|
+
productAction: ProductAction
|
|
180
|
+
): void;
|
|
181
|
+
extractProductAttributes(
|
|
182
|
+
attributes: ExtractedProductAttributes,
|
|
183
|
+
product: Product
|
|
184
|
+
): void;
|
|
185
|
+
extractPromotionAttributes(
|
|
186
|
+
attributes: ExtractedPromotionAttributes,
|
|
187
|
+
promotion: Promotion
|
|
188
|
+
): void;
|
|
189
|
+
extractTransactionId(
|
|
190
|
+
attributes: ExtractedTransactionId,
|
|
191
|
+
productAction: ProductAction
|
|
192
|
+
): void;
|
|
193
|
+
generateExpandedEcommerceName(eventName: string, plusOne: boolean): string;
|
|
194
|
+
getProductActionEventName(
|
|
195
|
+
productActionType: valueof<typeof ProductActionType>
|
|
196
|
+
): string;
|
|
197
|
+
getPromotionActionEventName(
|
|
198
|
+
promotionActionType: valueof<typeof PromotionActionType>
|
|
199
|
+
): string;
|
|
200
|
+
sanitizeAmount(amount: string | number, category: string): number;
|
|
201
|
+
}
|
package/src/ecommerce.js
CHANGED
|
@@ -5,6 +5,8 @@ var Messages = Constants.Messages;
|
|
|
5
5
|
|
|
6
6
|
export default function Ecommerce(mpInstance) {
|
|
7
7
|
var self = this;
|
|
8
|
+
|
|
9
|
+
// https://go.mparticle.com/work/SQDSDKS-4801
|
|
8
10
|
this.convertTransactionAttributesToProductAction = function(
|
|
9
11
|
transactionAttributes,
|
|
10
12
|
productAction
|
|
@@ -103,8 +105,11 @@ export default function Ecommerce(mpInstance) {
|
|
|
103
105
|
return Types.CommerceEventType.ProductRemoveFromCart;
|
|
104
106
|
case Types.ProductActionType.RemoveFromWishlist:
|
|
105
107
|
return Types.CommerceEventType.ProductRemoveFromWishlist;
|
|
108
|
+
|
|
109
|
+
// https://go.mparticle.com/work/SQDSDKS-4801
|
|
106
110
|
case Types.ProductActionType.Unknown:
|
|
107
111
|
return Types.EventType.Unknown;
|
|
112
|
+
|
|
108
113
|
case Types.ProductActionType.ViewDetail:
|
|
109
114
|
return Types.CommerceEventType.ProductViewDetail;
|
|
110
115
|
default:
|
|
@@ -139,6 +144,7 @@ export default function Ecommerce(mpInstance) {
|
|
|
139
144
|
);
|
|
140
145
|
};
|
|
141
146
|
|
|
147
|
+
// https://go.mparticle.com/work/SQDSDKS-4801
|
|
142
148
|
this.extractProductAttributes = function(attributes, product) {
|
|
143
149
|
if (product.CouponCode) {
|
|
144
150
|
attributes['Coupon Code'] = product.CouponCode;
|
|
@@ -170,12 +176,14 @@ export default function Ecommerce(mpInstance) {
|
|
|
170
176
|
attributes['Total Product Amount'] = product.TotalAmount || 0;
|
|
171
177
|
};
|
|
172
178
|
|
|
179
|
+
// https://go.mparticle.com/work/SQDSDKS-4801
|
|
173
180
|
this.extractTransactionId = function(attributes, productAction) {
|
|
174
181
|
if (productAction.TransactionId) {
|
|
175
182
|
attributes['Transaction Id'] = productAction.TransactionId;
|
|
176
183
|
}
|
|
177
184
|
};
|
|
178
185
|
|
|
186
|
+
// https://go.mparticle.com/work/SQDSDKS-4801
|
|
179
187
|
this.extractActionAttributes = function(attributes, productAction) {
|
|
180
188
|
self.extractTransactionId(attributes, productAction);
|
|
181
189
|
|
|
@@ -208,6 +216,7 @@ export default function Ecommerce(mpInstance) {
|
|
|
208
216
|
}
|
|
209
217
|
};
|
|
210
218
|
|
|
219
|
+
// https://go.mparticle.com/work/SQDSDKS-4801
|
|
211
220
|
this.extractPromotionAttributes = function(attributes, promotion) {
|
|
212
221
|
if (promotion.Id) {
|
|
213
222
|
attributes['Id'] = promotion.Id;
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import {
|
|
2
|
+
Callback,
|
|
3
|
+
SDKEventAttrs,
|
|
4
|
+
SDKEventOptions,
|
|
5
|
+
TransactionAttributes,
|
|
6
|
+
} from '@mparticle/web-sdk';
|
|
7
|
+
import {
|
|
8
|
+
BaseEvent,
|
|
9
|
+
SDKEvent,
|
|
10
|
+
SDKEventCustomFlags,
|
|
11
|
+
SDKProduct,
|
|
12
|
+
SDKProductImpression,
|
|
13
|
+
SDKPromotion,
|
|
14
|
+
} from './sdkRuntimeModels';
|
|
15
|
+
import { valueof } from './utils';
|
|
16
|
+
import { EventType, ProductActionType, PromotionActionType } from './types';
|
|
17
|
+
|
|
18
|
+
// Supports wrapping event handlers functions that will ideally return a specific type
|
|
19
|
+
type EventHandlerFunction<T> = (element: HTMLLinkElement | HTMLFormElement) => T;
|
|
20
|
+
|
|
21
|
+
export interface IEvents {
|
|
22
|
+
addEventHandler(
|
|
23
|
+
domEvent: string,
|
|
24
|
+
selector: string | Node,
|
|
25
|
+
eventName: EventHandlerFunction<string> | string,
|
|
26
|
+
data: EventHandlerFunction<SDKEventAttrs> | SDKEventAttrs,
|
|
27
|
+
eventType: valueof<typeof EventType>
|
|
28
|
+
): void;
|
|
29
|
+
logAST(): void;
|
|
30
|
+
logCheckoutEvent(
|
|
31
|
+
step: number,
|
|
32
|
+
|
|
33
|
+
// User options specified during the checkout process
|
|
34
|
+
// e.g., FedEx, DHL, UPS for delivery options;
|
|
35
|
+
// Visa, MasterCard, AmEx for payment options.
|
|
36
|
+
option?: string,
|
|
37
|
+
|
|
38
|
+
attrs?: SDKEventAttrs,
|
|
39
|
+
customFlags?: SDKEventCustomFlags
|
|
40
|
+
): void;
|
|
41
|
+
logCommerceEvent(
|
|
42
|
+
commerceEvent: SDKEvent,
|
|
43
|
+
attrs?: SDKEventAttrs,
|
|
44
|
+
options?: SDKEventOptions
|
|
45
|
+
): void;
|
|
46
|
+
logEvent(event: BaseEvent, eventOptions?: SDKEventOptions): void;
|
|
47
|
+
logImpressionEvent(
|
|
48
|
+
impression: SDKProductImpression,
|
|
49
|
+
attrs?: SDKEventAttrs,
|
|
50
|
+
customFlags?: SDKEventCustomFlags,
|
|
51
|
+
eventOptions?: SDKEventOptions
|
|
52
|
+
);
|
|
53
|
+
logOptOut(): void;
|
|
54
|
+
logProductActionEvent(
|
|
55
|
+
productActionType: valueof<typeof ProductActionType>,
|
|
56
|
+
product: SDKProduct | SDKProduct[],
|
|
57
|
+
attrs?: SDKEventAttrs,
|
|
58
|
+
customFlags?: SDKEventCustomFlags,
|
|
59
|
+
transactionAttributes?: TransactionAttributes,
|
|
60
|
+
eventOptions?: SDKEventOptions
|
|
61
|
+
): void;
|
|
62
|
+
logPromotionEvent(
|
|
63
|
+
promotionType: valueof<typeof PromotionActionType>,
|
|
64
|
+
promotion: SDKPromotion,
|
|
65
|
+
attrs?: SDKEventAttrs,
|
|
66
|
+
customFlags?: SDKEventCustomFlags,
|
|
67
|
+
eventOptions?: SDKEventOptions
|
|
68
|
+
): void;
|
|
69
|
+
logPurchaseEvent(
|
|
70
|
+
transactionAttributes: TransactionAttributes,
|
|
71
|
+
product: SDKProduct | SDKProduct[],
|
|
72
|
+
attrs?: SDKEventAttrs,
|
|
73
|
+
customFlags?: SDKEventCustomFlags
|
|
74
|
+
): void;
|
|
75
|
+
logRefundEvent(
|
|
76
|
+
transactionAttributes: TransactionAttributes,
|
|
77
|
+
product: SDKProduct | SDKProduct[],
|
|
78
|
+
attrs?: SDKEventAttrs,
|
|
79
|
+
customFlags?: SDKEventCustomFlags
|
|
80
|
+
): void;
|
|
81
|
+
startTracking(callback: Callback): void;
|
|
82
|
+
stopTracking(): void;
|
|
83
|
+
}
|
package/src/events.js
CHANGED
|
@@ -438,10 +438,13 @@ export default function Events(mpInstance) {
|
|
|
438
438
|
element = elements[i];
|
|
439
439
|
|
|
440
440
|
if (element.addEventListener) {
|
|
441
|
+
// Modern browsers
|
|
441
442
|
element.addEventListener(domEvent, handler, false);
|
|
442
443
|
} else if (element.attachEvent) {
|
|
444
|
+
// IE < 9
|
|
443
445
|
element.attachEvent('on' + domEvent, handler);
|
|
444
446
|
} else {
|
|
447
|
+
// All other browsers
|
|
445
448
|
element['on' + domEvent] = handler;
|
|
446
449
|
}
|
|
447
450
|
}
|
|
@@ -63,9 +63,6 @@ export interface ConfiguredKit
|
|
|
63
63
|
setOptOut(isOptingOut: boolean): string | KitMappedMethodFailure;
|
|
64
64
|
removeUserAttribute(key: string): string;
|
|
65
65
|
setUserAttribute(key: string, value: string): string;
|
|
66
|
-
|
|
67
|
-
// TODO: Convert type to enum during Identity migration
|
|
68
|
-
// https://go.mparticle.com/work/SQDSDKS-5218
|
|
69
66
|
setUserIdentity(id: UserIdentityId, type: UserIdentityType): void;
|
|
70
67
|
|
|
71
68
|
// TODO: https://go.mparticle.com/work/SQDSDKS-5156
|