@mparticle/web-sdk 2.79.3 → 2.80.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 +220 -574
- package/dist/mparticle.esm.js +220 -574
- package/dist/mparticle.js +1489 -1793
- package/dist/types/src/configAPIClient.d.ts +1 -0
- package/dist/types/src/ecommerce.d.ts +3 -53
- package/dist/types/src/ecommerce.interfaces.d.ts +11 -12
- package/dist/types/src/events.interfaces.d.ts +1 -1
- package/dist/types/src/forwarders.d.ts +4 -26
- package/dist/types/src/forwarders.interfaces.d.ts +41 -10
- package/dist/types/src/identity-utils.d.ts +3 -3
- package/dist/types/src/identity.d.ts +3 -0
- package/dist/types/src/identity.interfaces.d.ts +45 -11
- package/dist/types/src/identityApiClient.d.ts +5 -4
- package/dist/types/src/mp-instance.d.ts +2 -2
- package/dist/types/src/pageViewTracker.d.ts +12 -5
- package/dist/types/src/persistence.d.ts +3 -44
- package/dist/types/src/persistence.interfaces.d.ts +12 -13
- package/dist/types/src/sdkRuntimeModels.d.ts +3 -2
- package/dist/types/src/store.d.ts +5 -3
- package/package.json +1 -1
- package/src/configAPIClient.ts +1 -0
- package/src/ecommerce.interfaces.ts +12 -21
- package/src/{ecommerce.js → ecommerce.ts} +144 -73
- package/src/events.interfaces.ts +1 -1
- package/src/events.ts +10 -2
- package/src/forwarders.interfaces.ts +73 -10
- package/src/{forwarders.js → forwarders.ts} +214 -176
- package/src/helpers.ts +7 -3
- package/src/identity-utils.ts +2 -2
- package/src/identity.interfaces.ts +58 -14
- package/src/{identity.js → identity.ts} +237 -192
- package/src/identityApiClient.ts +9 -9
- package/src/mp-instance.ts +2 -2
- package/src/pageViewTracker.ts +176 -42
- package/src/persistence.interfaces.ts +12 -13
- package/src/persistence.ts +1210 -0
- package/src/sdkRuntimeModels.ts +3 -1
- package/src/store.ts +5 -3
- package/src/persistence.js +0 -985
|
@@ -1,19 +1,10 @@
|
|
|
1
|
-
import {
|
|
2
|
-
ProductAction,
|
|
3
|
-
Product,
|
|
4
|
-
Promotion,
|
|
5
|
-
CommerceEvent,
|
|
6
|
-
} from '@mparticle/event-models';
|
|
7
1
|
import {
|
|
8
2
|
SDKEventAttrs,
|
|
9
3
|
SDKEventOptions,
|
|
10
4
|
TransactionAttributes,
|
|
11
5
|
} from '@mparticle/web-sdk';
|
|
12
6
|
import { valueof } from './utils';
|
|
13
|
-
import {
|
|
14
|
-
ProductActionType,
|
|
15
|
-
PromotionActionType,
|
|
16
|
-
} from './types';
|
|
7
|
+
import { ProductActionType, PromotionActionType } from './types';
|
|
17
8
|
import {
|
|
18
9
|
SDKEvent,
|
|
19
10
|
SDKEventCustomFlags,
|
|
@@ -36,7 +27,7 @@ interface IECommerceShared {
|
|
|
36
27
|
couponCode?: string,
|
|
37
28
|
attributes?: SDKEventAttrs
|
|
38
29
|
): SDKProduct | null;
|
|
39
|
-
createImpression(name: string, product:
|
|
30
|
+
createImpression(name: string, product: SDKProduct): SDKImpression | null;
|
|
40
31
|
createPromotion(
|
|
41
32
|
id: string | number,
|
|
42
33
|
creative?: string,
|
|
@@ -51,7 +42,7 @@ interface IECommerceShared {
|
|
|
51
42
|
shipping?: string | number,
|
|
52
43
|
tax?: number
|
|
53
44
|
): TransactionAttributes | null;
|
|
54
|
-
expandCommerceEvent(event:
|
|
45
|
+
expandCommerceEvent(event: SDKEvent): SDKEvent[] | null;
|
|
55
46
|
}
|
|
56
47
|
|
|
57
48
|
export interface SDKCart {
|
|
@@ -84,7 +75,7 @@ export interface SDKECommerceAPI extends IECommerceShared {
|
|
|
84
75
|
): void;
|
|
85
76
|
logPromotion(
|
|
86
77
|
type: valueof<typeof PromotionActionType>,
|
|
87
|
-
promotion: SDKPromotion,
|
|
78
|
+
promotion: SDKPromotion | SDKPromotion[],
|
|
88
79
|
attrs?: SDKEventAttrs,
|
|
89
80
|
customFlags?: SDKEventCustomFlags,
|
|
90
81
|
eventOptions?: SDKEventOptions
|
|
@@ -175,26 +166,26 @@ export interface IECommerce extends IECommerceShared {
|
|
|
175
166
|
customFlags: SDKEventCustomFlags,
|
|
176
167
|
options?: SDKEventOptions
|
|
177
168
|
): SDKEvent | null;
|
|
178
|
-
expandProductAction(commerceEvent:
|
|
179
|
-
expandProductImpression(commerceEvent:
|
|
180
|
-
expandPromotionAction(commerceEvent:
|
|
169
|
+
expandProductAction(commerceEvent: SDKEvent): SDKEvent[];
|
|
170
|
+
expandProductImpression(commerceEvent: SDKEvent): SDKEvent[];
|
|
171
|
+
expandPromotionAction(commerceEvent: SDKEvent): SDKEvent[];
|
|
181
172
|
extractActionAttributes(
|
|
182
173
|
attributes: ExtractedActionAttributes,
|
|
183
|
-
productAction:
|
|
174
|
+
productAction: SDKProductAction
|
|
184
175
|
): void;
|
|
185
176
|
extractProductAttributes(
|
|
186
177
|
attributes: ExtractedProductAttributes,
|
|
187
|
-
product:
|
|
178
|
+
product: SDKProduct
|
|
188
179
|
): void;
|
|
189
180
|
extractPromotionAttributes(
|
|
190
181
|
attributes: ExtractedPromotionAttributes,
|
|
191
|
-
promotion:
|
|
182
|
+
promotion: SDKPromotion
|
|
192
183
|
): void;
|
|
193
184
|
extractTransactionId(
|
|
194
185
|
attributes: ExtractedTransactionId,
|
|
195
|
-
productAction:
|
|
186
|
+
productAction: SDKProductAction
|
|
196
187
|
): void;
|
|
197
|
-
generateExpandedEcommerceName(eventName: string, plusOne
|
|
188
|
+
generateExpandedEcommerceName(eventName: string, plusOne?: boolean): string;
|
|
198
189
|
getProductActionEventName(
|
|
199
190
|
productActionType: valueof<typeof ProductActionType>
|
|
200
191
|
): string;
|
|
@@ -1,19 +1,40 @@
|
|
|
1
|
-
import Types from './types';
|
|
1
|
+
import Types, { ProductActionType, PromotionActionType } from './types';
|
|
2
2
|
import Constants from './constants';
|
|
3
|
-
import { extend, parseNumber } from './utils';
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
3
|
+
import { extend, parseNumber, valueof } from './utils';
|
|
4
|
+
import { IMParticleWebSDKInstance } from './mp-instance';
|
|
5
|
+
import { IECommerce } from './ecommerce.interfaces';
|
|
6
|
+
import {
|
|
7
|
+
SDKEvent,
|
|
8
|
+
SDKEventCustomFlags,
|
|
9
|
+
SDKImpression,
|
|
10
|
+
SDKProduct,
|
|
11
|
+
SDKProductAction,
|
|
12
|
+
SDKPromotion,
|
|
13
|
+
} from './sdkRuntimeModels';
|
|
14
|
+
import {
|
|
15
|
+
SDKEventAttrs,
|
|
16
|
+
SDKEventOptions,
|
|
17
|
+
TransactionAttributes,
|
|
18
|
+
} from '@mparticle/web-sdk';
|
|
19
|
+
|
|
20
|
+
const { Messages } = Constants;
|
|
21
|
+
|
|
22
|
+
export default function Ecommerce(
|
|
23
|
+
this: IECommerce,
|
|
24
|
+
mpInstance: IMParticleWebSDKInstance
|
|
25
|
+
): void {
|
|
26
|
+
const self = this;
|
|
9
27
|
|
|
10
28
|
// https://go.mparticle.com/work/SQDSDKS-4801
|
|
11
29
|
this.convertTransactionAttributesToProductAction = function(
|
|
12
|
-
transactionAttributes
|
|
13
|
-
|
|
14
|
-
|
|
30
|
+
transactionAttributes: TransactionAttributes & {
|
|
31
|
+
Step?: number;
|
|
32
|
+
Option?: string;
|
|
33
|
+
},
|
|
34
|
+
productAction: SDKProductAction
|
|
35
|
+
): void {
|
|
15
36
|
if (transactionAttributes.hasOwnProperty('Id')) {
|
|
16
|
-
productAction.TransactionId = transactionAttributes.Id;
|
|
37
|
+
productAction.TransactionId = transactionAttributes.Id as unknown as string;
|
|
17
38
|
}
|
|
18
39
|
if (transactionAttributes.hasOwnProperty('Affiliation')) {
|
|
19
40
|
productAction.Affiliation = transactionAttributes.Affiliation;
|
|
@@ -51,7 +72,9 @@ export default function Ecommerce(mpInstance) {
|
|
|
51
72
|
// transactionAttributes.Revenue, derive it from the product list
|
|
52
73
|
// (quantity * price) plus shipping and tax. A total that the caller provided
|
|
53
74
|
// (including 0) is never overwritten.
|
|
54
|
-
this.calculateProductActionTotalAmount = function(
|
|
75
|
+
this.calculateProductActionTotalAmount = function(
|
|
76
|
+
productAction: SDKProductAction
|
|
77
|
+
): SDKProductAction {
|
|
55
78
|
if (!productAction || productAction.TotalAmount != null) {
|
|
56
79
|
return productAction;
|
|
57
80
|
}
|
|
@@ -74,7 +97,9 @@ export default function Ecommerce(mpInstance) {
|
|
|
74
97
|
return productAction;
|
|
75
98
|
};
|
|
76
99
|
|
|
77
|
-
this.getProductActionEventName = function(
|
|
100
|
+
this.getProductActionEventName = function(
|
|
101
|
+
productActionType: valueof<typeof ProductActionType>
|
|
102
|
+
): string {
|
|
78
103
|
switch (productActionType) {
|
|
79
104
|
case Types.ProductActionType.AddToCart:
|
|
80
105
|
return 'AddToCart';
|
|
@@ -118,7 +143,9 @@ export default function Ecommerce(mpInstance) {
|
|
|
118
143
|
}
|
|
119
144
|
};
|
|
120
145
|
|
|
121
|
-
this.getPromotionActionEventName = function(
|
|
146
|
+
this.getPromotionActionEventName = function(
|
|
147
|
+
promotionActionType: valueof<typeof PromotionActionType>
|
|
148
|
+
): string {
|
|
122
149
|
switch (promotionActionType) {
|
|
123
150
|
case Types.PromotionActionType.PromotionClick:
|
|
124
151
|
return 'PromotionClick';
|
|
@@ -129,7 +156,9 @@ export default function Ecommerce(mpInstance) {
|
|
|
129
156
|
}
|
|
130
157
|
};
|
|
131
158
|
|
|
132
|
-
this.convertProductActionToEventType = function(
|
|
159
|
+
this.convertProductActionToEventType = function(
|
|
160
|
+
productActionType: valueof<typeof ProductActionType>
|
|
161
|
+
): number | null {
|
|
133
162
|
switch (productActionType) {
|
|
134
163
|
case Types.ProductActionType.AddToCart:
|
|
135
164
|
return Types.CommerceEventType.ProductAddToCart;
|
|
@@ -178,7 +207,9 @@ export default function Ecommerce(mpInstance) {
|
|
|
178
207
|
}
|
|
179
208
|
};
|
|
180
209
|
|
|
181
|
-
this.convertPromotionActionToEventType = function(
|
|
210
|
+
this.convertPromotionActionToEventType = function(
|
|
211
|
+
promotionActionType: valueof<typeof PromotionActionType>
|
|
212
|
+
): number | null {
|
|
182
213
|
switch (promotionActionType) {
|
|
183
214
|
case Types.PromotionActionType.PromotionClick:
|
|
184
215
|
return Types.CommerceEventType.PromotionClick;
|
|
@@ -194,14 +225,20 @@ export default function Ecommerce(mpInstance) {
|
|
|
194
225
|
}
|
|
195
226
|
};
|
|
196
227
|
|
|
197
|
-
this.generateExpandedEcommerceName = function(
|
|
228
|
+
this.generateExpandedEcommerceName = function(
|
|
229
|
+
eventName: string,
|
|
230
|
+
plusOne?: boolean
|
|
231
|
+
): string {
|
|
198
232
|
return (
|
|
199
233
|
'eCommerce - ' + eventName + ' - ' + (plusOne ? 'Total' : 'Item')
|
|
200
234
|
);
|
|
201
235
|
};
|
|
202
236
|
|
|
203
237
|
// https://go.mparticle.com/work/SQDSDKS-4801
|
|
204
|
-
this.extractProductAttributes = function(
|
|
238
|
+
this.extractProductAttributes = function(
|
|
239
|
+
attributes: { [key: string]: any },
|
|
240
|
+
product: SDKProduct
|
|
241
|
+
): void {
|
|
205
242
|
if (product.CouponCode) {
|
|
206
243
|
attributes['Coupon Code'] = product.CouponCode;
|
|
207
244
|
}
|
|
@@ -233,14 +270,20 @@ export default function Ecommerce(mpInstance) {
|
|
|
233
270
|
};
|
|
234
271
|
|
|
235
272
|
// https://go.mparticle.com/work/SQDSDKS-4801
|
|
236
|
-
this.extractTransactionId = function(
|
|
273
|
+
this.extractTransactionId = function(
|
|
274
|
+
attributes: { [key: string]: any },
|
|
275
|
+
productAction: SDKProductAction
|
|
276
|
+
): void {
|
|
237
277
|
if (productAction.TransactionId) {
|
|
238
278
|
attributes['Transaction Id'] = productAction.TransactionId;
|
|
239
279
|
}
|
|
240
280
|
};
|
|
241
281
|
|
|
242
282
|
// https://go.mparticle.com/work/SQDSDKS-4801
|
|
243
|
-
this.extractActionAttributes = function(
|
|
283
|
+
this.extractActionAttributes = function(
|
|
284
|
+
attributes: { [key: string]: any },
|
|
285
|
+
productAction: SDKProductAction
|
|
286
|
+
): void {
|
|
244
287
|
self.extractTransactionId(attributes, productAction);
|
|
245
288
|
|
|
246
289
|
if (productAction.Affiliation) {
|
|
@@ -273,7 +316,10 @@ export default function Ecommerce(mpInstance) {
|
|
|
273
316
|
};
|
|
274
317
|
|
|
275
318
|
// https://go.mparticle.com/work/SQDSDKS-4801
|
|
276
|
-
this.extractPromotionAttributes = function(
|
|
319
|
+
this.extractPromotionAttributes = function(
|
|
320
|
+
attributes: { [key: string]: any },
|
|
321
|
+
promotion: SDKPromotion
|
|
322
|
+
): void {
|
|
277
323
|
if (promotion.Id) {
|
|
278
324
|
attributes['Id'] = promotion.Id;
|
|
279
325
|
}
|
|
@@ -291,7 +337,10 @@ export default function Ecommerce(mpInstance) {
|
|
|
291
337
|
}
|
|
292
338
|
};
|
|
293
339
|
|
|
294
|
-
this.buildProductList = function(
|
|
340
|
+
this.buildProductList = function(
|
|
341
|
+
event: SDKEvent,
|
|
342
|
+
product: SDKProduct | SDKProduct[]
|
|
343
|
+
): SDKProduct[] {
|
|
295
344
|
if (product) {
|
|
296
345
|
if (Array.isArray(product)) {
|
|
297
346
|
return product;
|
|
@@ -304,17 +353,17 @@ export default function Ecommerce(mpInstance) {
|
|
|
304
353
|
};
|
|
305
354
|
|
|
306
355
|
this.createProduct = function(
|
|
307
|
-
name,
|
|
308
|
-
sku,
|
|
309
|
-
price,
|
|
310
|
-
quantity,
|
|
311
|
-
variant,
|
|
312
|
-
category,
|
|
313
|
-
brand,
|
|
314
|
-
position,
|
|
315
|
-
couponCode,
|
|
316
|
-
attributes
|
|
317
|
-
) {
|
|
356
|
+
name: string,
|
|
357
|
+
sku: string | number,
|
|
358
|
+
price: string | number,
|
|
359
|
+
quantity?: string | number,
|
|
360
|
+
variant?: string,
|
|
361
|
+
category?: string,
|
|
362
|
+
brand?: string,
|
|
363
|
+
position?: number,
|
|
364
|
+
couponCode?: string,
|
|
365
|
+
attributes?: SDKEventAttrs
|
|
366
|
+
): SDKProduct | null {
|
|
318
367
|
attributes = mpInstance._Helpers.sanitizeAttributes(attributes, name);
|
|
319
368
|
|
|
320
369
|
if (typeof name !== 'string') {
|
|
@@ -342,7 +391,7 @@ export default function Ecommerce(mpInstance) {
|
|
|
342
391
|
mpInstance.Logger.error(
|
|
343
392
|
'Position must be a number, it will be set to null.'
|
|
344
393
|
);
|
|
345
|
-
position = null;
|
|
394
|
+
position = null as unknown as number;
|
|
346
395
|
}
|
|
347
396
|
|
|
348
397
|
if (!mpInstance._Helpers.Validators.isStringOrNumber(quantity)) {
|
|
@@ -353,34 +402,42 @@ export default function Ecommerce(mpInstance) {
|
|
|
353
402
|
|
|
354
403
|
return {
|
|
355
404
|
Name: name,
|
|
356
|
-
Sku: sku,
|
|
357
|
-
Price: price,
|
|
358
|
-
Quantity: quantity,
|
|
405
|
+
Sku: sku as unknown as string,
|
|
406
|
+
Price: price as number,
|
|
407
|
+
Quantity: quantity as number,
|
|
359
408
|
Brand: brand,
|
|
360
409
|
Variant: variant,
|
|
361
410
|
Category: category,
|
|
362
411
|
Position: position,
|
|
363
412
|
CouponCode: couponCode,
|
|
364
|
-
TotalAmount: quantity * price,
|
|
413
|
+
TotalAmount: (quantity as number) * (price as number),
|
|
365
414
|
Attributes: attributes,
|
|
366
415
|
};
|
|
367
416
|
};
|
|
368
417
|
|
|
369
|
-
this.createPromotion = function(
|
|
418
|
+
this.createPromotion = function(
|
|
419
|
+
id: string | number,
|
|
420
|
+
creative?: string,
|
|
421
|
+
name?: string,
|
|
422
|
+
position?: number
|
|
423
|
+
): SDKPromotion | null {
|
|
370
424
|
if (!mpInstance._Helpers.Validators.isStringOrNumber(id)) {
|
|
371
425
|
mpInstance.Logger.error(Messages.ErrorMessages.PromotionIdRequired);
|
|
372
426
|
return null;
|
|
373
427
|
}
|
|
374
428
|
|
|
375
429
|
return {
|
|
376
|
-
Id: id,
|
|
430
|
+
Id: id as unknown as string,
|
|
377
431
|
Creative: creative,
|
|
378
432
|
Name: name,
|
|
379
|
-
Position: position,
|
|
433
|
+
Position: position as unknown as string,
|
|
380
434
|
};
|
|
381
435
|
};
|
|
382
436
|
|
|
383
|
-
this.createImpression = function(
|
|
437
|
+
this.createImpression = function(
|
|
438
|
+
name: string,
|
|
439
|
+
product: SDKProduct
|
|
440
|
+
): SDKImpression | null {
|
|
384
441
|
if (typeof name !== 'string') {
|
|
385
442
|
mpInstance.Logger.error(
|
|
386
443
|
'Name is required when creating an impression.'
|
|
@@ -402,13 +459,13 @@ export default function Ecommerce(mpInstance) {
|
|
|
402
459
|
};
|
|
403
460
|
|
|
404
461
|
this.createTransactionAttributes = function(
|
|
405
|
-
id,
|
|
406
|
-
affiliation,
|
|
407
|
-
couponCode,
|
|
408
|
-
revenue,
|
|
409
|
-
shipping,
|
|
410
|
-
tax
|
|
411
|
-
) {
|
|
462
|
+
id: string | number,
|
|
463
|
+
affiliation?: string,
|
|
464
|
+
couponCode?: string,
|
|
465
|
+
revenue?: string | number,
|
|
466
|
+
shipping?: string | number,
|
|
467
|
+
tax?: number
|
|
468
|
+
): TransactionAttributes | null {
|
|
412
469
|
if (!mpInstance._Helpers.Validators.isStringOrNumber(id)) {
|
|
413
470
|
mpInstance.Logger.error(
|
|
414
471
|
Messages.ErrorMessages.TransactionIdRequired
|
|
@@ -420,14 +477,16 @@ export default function Ecommerce(mpInstance) {
|
|
|
420
477
|
Id: id,
|
|
421
478
|
Affiliation: affiliation,
|
|
422
479
|
CouponCode: couponCode,
|
|
423
|
-
Revenue: revenue,
|
|
424
|
-
Shipping: shipping,
|
|
480
|
+
Revenue: revenue as number,
|
|
481
|
+
Shipping: shipping as string,
|
|
425
482
|
Tax: tax,
|
|
426
483
|
};
|
|
427
484
|
};
|
|
428
485
|
|
|
429
|
-
this.expandProductImpression = function(
|
|
430
|
-
|
|
486
|
+
this.expandProductImpression = function(
|
|
487
|
+
commerceEvent: SDKEvent
|
|
488
|
+
): SDKEvent[] {
|
|
489
|
+
const appEvents = [];
|
|
431
490
|
if (!commerceEvent.ProductImpressions) {
|
|
432
491
|
return appEvents;
|
|
433
492
|
}
|
|
@@ -450,7 +509,7 @@ export default function Ecommerce(mpInstance) {
|
|
|
450
509
|
attributes['Product Impression List'] =
|
|
451
510
|
productImpression.ProductImpressionList;
|
|
452
511
|
}
|
|
453
|
-
|
|
512
|
+
const appEvent = mpInstance._ServerModel.createEventObject({
|
|
454
513
|
messageType: Types.MessageType.PageEvent,
|
|
455
514
|
name: self.generateExpandedEcommerceName('Impression'),
|
|
456
515
|
data: attributes,
|
|
@@ -464,7 +523,9 @@ export default function Ecommerce(mpInstance) {
|
|
|
464
523
|
return appEvents;
|
|
465
524
|
};
|
|
466
525
|
|
|
467
|
-
this.expandCommerceEvent = function(
|
|
526
|
+
this.expandCommerceEvent = function(
|
|
527
|
+
event: SDKEvent
|
|
528
|
+
): SDKEvent[] | null {
|
|
468
529
|
if (!event) {
|
|
469
530
|
return null;
|
|
470
531
|
}
|
|
@@ -474,21 +535,23 @@ export default function Ecommerce(mpInstance) {
|
|
|
474
535
|
.concat(self.expandProductImpression(event));
|
|
475
536
|
};
|
|
476
537
|
|
|
477
|
-
this.expandPromotionAction = function(
|
|
478
|
-
|
|
538
|
+
this.expandPromotionAction = function(
|
|
539
|
+
commerceEvent: SDKEvent
|
|
540
|
+
): SDKEvent[] {
|
|
541
|
+
const appEvents = [];
|
|
479
542
|
if (!commerceEvent.PromotionAction) {
|
|
480
543
|
return appEvents;
|
|
481
544
|
}
|
|
482
|
-
|
|
545
|
+
const promotions = commerceEvent.PromotionAction.PromotionList;
|
|
483
546
|
promotions.forEach(function(promotion) {
|
|
484
547
|
let attributes = extend(false, {}, commerceEvent.EventAttributes);
|
|
485
548
|
self.extractPromotionAttributes(attributes, promotion);
|
|
486
549
|
|
|
487
|
-
|
|
550
|
+
const appEvent = mpInstance._ServerModel.createEventObject({
|
|
488
551
|
messageType: Types.MessageType.PageEvent,
|
|
489
552
|
name: self.generateExpandedEcommerceName(
|
|
490
553
|
Types.PromotionActionType.getExpansionName(
|
|
491
|
-
commerceEvent.PromotionAction.PromotionActionType
|
|
554
|
+
commerceEvent.PromotionAction.PromotionActionType as unknown as number
|
|
492
555
|
)
|
|
493
556
|
),
|
|
494
557
|
data: attributes,
|
|
@@ -499,12 +562,14 @@ export default function Ecommerce(mpInstance) {
|
|
|
499
562
|
return appEvents;
|
|
500
563
|
};
|
|
501
564
|
|
|
502
|
-
this.expandProductAction = function(
|
|
503
|
-
|
|
565
|
+
this.expandProductAction = function(
|
|
566
|
+
commerceEvent: SDKEvent
|
|
567
|
+
): SDKEvent[] {
|
|
568
|
+
const appEvents = [];
|
|
504
569
|
if (!commerceEvent.ProductAction) {
|
|
505
570
|
return appEvents;
|
|
506
571
|
}
|
|
507
|
-
|
|
572
|
+
let shouldExtractActionAttributes = false;
|
|
508
573
|
if (
|
|
509
574
|
commerceEvent.ProductAction.ProductActionType ===
|
|
510
575
|
Types.ProductActionType.Purchase ||
|
|
@@ -523,11 +588,11 @@ export default function Ecommerce(mpInstance) {
|
|
|
523
588
|
if (commerceEvent.CurrencyCode) {
|
|
524
589
|
attributes['Currency Code'] = commerceEvent.CurrencyCode;
|
|
525
590
|
}
|
|
526
|
-
|
|
591
|
+
const plusOneEvent = mpInstance._ServerModel.createEventObject({
|
|
527
592
|
messageType: Types.MessageType.PageEvent,
|
|
528
593
|
name: self.generateExpandedEcommerceName(
|
|
529
594
|
Types.ProductActionType.getExpansionName(
|
|
530
|
-
commerceEvent.ProductAction.ProductActionType
|
|
595
|
+
commerceEvent.ProductAction.ProductActionType as number
|
|
531
596
|
),
|
|
532
597
|
true
|
|
533
598
|
),
|
|
@@ -539,7 +604,7 @@ export default function Ecommerce(mpInstance) {
|
|
|
539
604
|
shouldExtractActionAttributes = true;
|
|
540
605
|
}
|
|
541
606
|
|
|
542
|
-
|
|
607
|
+
const products = commerceEvent.ProductAction.ProductList;
|
|
543
608
|
|
|
544
609
|
if (!products) {
|
|
545
610
|
return appEvents;
|
|
@@ -564,11 +629,11 @@ export default function Ecommerce(mpInstance) {
|
|
|
564
629
|
}
|
|
565
630
|
self.extractProductAttributes(attributes, product);
|
|
566
631
|
|
|
567
|
-
|
|
632
|
+
const productEvent = mpInstance._ServerModel.createEventObject({
|
|
568
633
|
messageType: Types.MessageType.PageEvent,
|
|
569
634
|
name: self.generateExpandedEcommerceName(
|
|
570
635
|
Types.ProductActionType.getExpansionName(
|
|
571
|
-
commerceEvent.ProductAction.ProductActionType
|
|
636
|
+
commerceEvent.ProductAction.ProductActionType as number
|
|
572
637
|
)
|
|
573
638
|
),
|
|
574
639
|
data: attributes,
|
|
@@ -580,10 +645,13 @@ export default function Ecommerce(mpInstance) {
|
|
|
580
645
|
return appEvents;
|
|
581
646
|
};
|
|
582
647
|
|
|
583
|
-
this.createCommerceEventObject = function(
|
|
584
|
-
|
|
648
|
+
this.createCommerceEventObject = function(
|
|
649
|
+
customFlags?: SDKEventCustomFlags,
|
|
650
|
+
options?: SDKEventOptions
|
|
651
|
+
): SDKEvent | null {
|
|
652
|
+
let baseEvent;
|
|
585
653
|
// https://go.mparticle.com/work/SQDSDKS-4801
|
|
586
|
-
|
|
654
|
+
const { extend } = mpInstance._Helpers;
|
|
587
655
|
|
|
588
656
|
mpInstance.Logger.verbose(
|
|
589
657
|
Messages.InformationMessages.StartingLogCommerceEvent
|
|
@@ -611,9 +679,12 @@ export default function Ecommerce(mpInstance) {
|
|
|
611
679
|
};
|
|
612
680
|
|
|
613
681
|
// sanitizes any non number, non string value to 0
|
|
614
|
-
this.sanitizeAmount = function(
|
|
682
|
+
this.sanitizeAmount = function(
|
|
683
|
+
amount: string | number,
|
|
684
|
+
category: string
|
|
685
|
+
): number {
|
|
615
686
|
if (!mpInstance._Helpers.Validators.isStringOrNumber(amount)) {
|
|
616
|
-
|
|
687
|
+
const message = [
|
|
617
688
|
category,
|
|
618
689
|
'must be of type number. A',
|
|
619
690
|
typeof amount,
|
package/src/events.interfaces.ts
CHANGED
|
@@ -62,7 +62,7 @@ export interface IEvents {
|
|
|
62
62
|
): void;
|
|
63
63
|
logPromotionEvent(
|
|
64
64
|
promotionType: valueof<typeof PromotionActionType>,
|
|
65
|
-
promotion: SDKPromotion,
|
|
65
|
+
promotion: SDKPromotion | SDKPromotion[],
|
|
66
66
|
attrs?: SDKEventAttrs,
|
|
67
67
|
customFlags?: SDKEventCustomFlags,
|
|
68
68
|
eventOptions?: SDKEventOptions
|
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
|
},
|
|
@@ -334,7 +342,7 @@ export default function Events(
|
|
|
334
342
|
|
|
335
343
|
this.logPromotionEvent = function(
|
|
336
344
|
promotionType: valueof<typeof PromotionActionType>,
|
|
337
|
-
promotion: SDKPromotion,
|
|
345
|
+
promotion: SDKPromotion | SDKPromotion[],
|
|
338
346
|
attrs?: SDKEventAttrs,
|
|
339
347
|
customFlags?: SDKEventCustomFlags,
|
|
340
348
|
eventOptions?: SDKEventOptions
|