@mparticle/web-braze-kit 3.0.6 → 3.0.9
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 +21 -27
- package/dist/BrazeKit.common.js +302 -49
- package/package.json +2 -2
- package/CHANGELOG.md +0 -57
package/README.md
CHANGED
|
@@ -1,51 +1,44 @@
|
|
|
1
|
-

|
|
1
|
+

|
|
2
2
|
|
|
3
3
|
⚠️⚠️⚠️
|
|
4
|
-
#
|
|
5
|
-
mParticle's Braze Kit currently uses Braze's V3 web SDK, and Braze has made significant changes to their newest V4 web SDK. Previously, mParticle planned to release an update on 2/15/2023 for all of our CDN users which upgraded to the Brave V4 web SDK. Now, rather than migrate all CDN users to V4 at the same time, you must opt in to get the latest update. This will allow you to decide when you want to upgrade to V4 and make the appropriate code changes. Opting in to V4 will be done via a connection setting in the mParticle UI that will be available shortly.
|
|
4
|
+
# Notice! Opt in is now available for Braze Web SDK V4 - Action Required
|
|
6
5
|
|
|
7
|
-
|
|
6
|
+
You can now select what version of the Braze SDK you want to use when setting up a Braze connection in the mParticle UI. Braze occasionally makes breaking changes to their SDK, so if you call `appboy` directly in your code, you will have to update your code to ensure your website performs as expected when updating versions of Braze.
|
|
8
7
|
|
|
9
|
-
|
|
8
|
+
Please review the [Braze Changelog](https://www.braze.com/docs/developer_guide/platform_integration_guides/web/changelog#400) and [V4 migration guide](https://github.com/braze-inc/braze-web-sdk/blob/master/UPGRADE_GUIDE.md) to learn about the differences between V3 and V4 and what changes you will need to make in your code. The most significant breaking changes are the replacement of the `appboy` class name with `braze`, in addition to the removal and renaming of several APIs.
|
|
10
9
|
|
|
11
|
-
|
|
12
|
-
*
|
|
10
|
+
You can opt into the latest major version of the Braze Web SDK whether you implement mParticle's Web SDK using npm or our snippet/CDN.
|
|
11
|
+
* Customers who self-host mParticle via npm - You should add @mparticle/web-braze-kit version 4.0.0 or greater in your package.json now! You must also select `Version 4` under `Braze Web SDK Version` in the Braze connection settings.
|
|
12
|
+
* Customers who load mParticle via snippet/CDN - Opting in is available via the mParticle UI in your Braze connection settings.
|
|
13
13
|
|
|
14
|
-
|
|
14
|
+
Note that the following is only one example. Everywhere you manually call `appboy` needs to be updated similar to the below. If you are using NPM, you can skip to step 3. Please be sure to test your site fully in development prior to releasing.
|
|
15
15
|
|
|
16
|
-
Braze occasionally makes breaking changes to their SDK, so if you call Braze directly in your code, you will have to update your code to ensure your website performs as expected when updating versions of Braze.
|
|
17
|
-
|
|
18
|
-
Please review [Braze’s Changelog notes](https://www.braze.com/docs/developer_guide/platform_integration_guides/web/changelog#400) as well as Braze’s [migration guide](https://github.com/braze-inc/braze-web-sdk/blob/master/UPGRADE_GUIDE.md) between version 3 and 4 to understand these changes and what code updates are needed from your side. The largest change is the move from class name `appboy` to `braze`. Braze also removed and renamed some APIs. As a result, we are also updating our mParticle Braze web kit from 3.0.X to 4.0.X in order to support Braze’s Web SDK version 4.2.1.
|
|
19
|
-
|
|
20
|
-
Customers will be able to opt in to using the latest version of Braze's Web SDK both via npm and via snippet/CDN
|
|
21
|
-
* Customers who self-host mParticle via npm - You can use @mparticle/web-braze-kit version 4.0.0 in your package.json now! This has been available since 10/15/2022.
|
|
22
|
-
* Customers who load mParticle via snippet/CDN - Opting in will be available soon via the mParticle UI in your Braze connection settings.
|
|
23
|
-
|
|
24
|
-
Note that the following is only one example. Everywhere you manually call `appboy` needs to be updated similar to the below.
|
|
25
16
|
|
|
26
17
|
* Step 1: Legacy code sample. Find all the places where your code references the `appboy.display` namespace. Braze has removed all instances of the `display` namespace:
|
|
27
18
|
```javascript
|
|
28
19
|
window.appboy.display.destroyFeed();
|
|
29
20
|
```
|
|
30
21
|
|
|
31
|
-
Step 2: Roll out code changes to
|
|
22
|
+
Step 2: Roll out code changes prior to opting in to V4
|
|
32
23
|
```javascript
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
24
|
+
if (window.appboy) {
|
|
25
|
+
window.appboy.display.destroyFeed();
|
|
26
|
+
} else if (window.braze) {
|
|
27
|
+
window.braze.destroyFeed();
|
|
28
|
+
}
|
|
38
29
|
```
|
|
39
|
-
Step 3:
|
|
30
|
+
Step 3: Opt into Version 4. Simply navigate to your connection settings and selection `Version 4` from the new Braze Web SDK Version drop down.
|
|
31
|
+
|
|
32
|
+
Step 4: After you opt in, you can simplify your code. We recommend testing and waiting at least 24 hours between opting in and removing previous instances of `appboy` and doing thorough testing of your application in a development environment to ensure everything is working:
|
|
40
33
|
```javascript
|
|
41
34
|
window.braze.destroyFeed();
|
|
42
35
|
```
|
|
43
36
|
|
|
44
|
-
Step
|
|
45
|
-
If you use Push Notifications, we have updated the `service-worker.js` file. In our testing, Braze’s push notifications work as expected regardless of what version of the service-worker is used, but we recommend updating this file to ensure future compatibility. In your `service-worker.js` file, update the code to reference `https://static.mparticle.com/sdk/js/braze/service-worker-4.2.
|
|
37
|
+
Step 5: Push Notifications via service-worker.js
|
|
38
|
+
If you use Push Notifications, we have updated the `service-worker.js` file. In our testing, Braze’s push notifications work as expected regardless of what version of the service-worker is used, but we recommend updating this file to ensure future compatibility. In your `service-worker.js` file, update the code to reference `https://static.mparticle.com/sdk/js/braze/service-worker-4.2.1.js` instead of `https://static.mparticle.com/sdk/js/braze/service-worker-3.5.0.js`. Your `service-worker.js` file should now contain:
|
|
46
39
|
|
|
47
40
|
```javascript
|
|
48
|
-
self.imports('https://static.mparticle.com/sdk/js/braze/service-worker-4.2.
|
|
41
|
+
self.imports('https://static.mparticle.com/sdk/js/braze/service-worker-4.2.1.js')
|
|
49
42
|
```
|
|
50
43
|
|
|
51
44
|
### Transition from @mparticle/web-appboy-kit to @mparticle/web-braze-kit
|
|
@@ -54,6 +47,7 @@ The legacy @mparticle/web-appboy-kit from npm includes version 2 of the Braze We
|
|
|
54
47
|
|
|
55
48
|
|
|
56
49
|
|
|
50
|
+
|
|
57
51
|
# License
|
|
58
52
|
|
|
59
53
|
Copyright 2022 mParticle, Inc.
|
package/dist/BrazeKit.common.js
CHANGED
|
@@ -304,13 +304,15 @@ window.appboy = appboy_min;
|
|
|
304
304
|
// limitations under the License.
|
|
305
305
|
|
|
306
306
|
var name = 'Appboy',
|
|
307
|
+
suffix = 'v3',
|
|
307
308
|
moduleId = 28,
|
|
308
|
-
version = '3.0.
|
|
309
|
+
version = '3.0.9',
|
|
309
310
|
MessageType = {
|
|
310
311
|
PageView: 3,
|
|
311
312
|
PageEvent: 4,
|
|
312
313
|
Commerce: 16,
|
|
313
|
-
}
|
|
314
|
+
},
|
|
315
|
+
CommerceEventType = mParticle.CommerceEventType;
|
|
314
316
|
|
|
315
317
|
var clusterMapping = {
|
|
316
318
|
'01': 'sdk.iad-01.braze.com',
|
|
@@ -332,6 +334,7 @@ var constructor = function () {
|
|
|
332
334
|
mpCustomFlags;
|
|
333
335
|
|
|
334
336
|
self.name = name;
|
|
337
|
+
self.suffix = suffix;
|
|
335
338
|
|
|
336
339
|
var DefaultAttributeMethods = {
|
|
337
340
|
$LastName: 'setLastName',
|
|
@@ -355,32 +358,94 @@ var constructor = function () {
|
|
|
355
358
|
dob: 'setDateOfBirth',
|
|
356
359
|
};
|
|
357
360
|
|
|
361
|
+
var bundleCommerceEventData = false;
|
|
362
|
+
|
|
363
|
+
// A purchase event can either log a single event with all products
|
|
364
|
+
// or multiple purchase events (one per product)
|
|
358
365
|
function logPurchaseEvent(event) {
|
|
359
366
|
var reportEvent = false;
|
|
367
|
+
|
|
368
|
+
if (bundleCommerceEventData) {
|
|
369
|
+
reportEvent = logSinglePurchaseEventWithProducts(event);
|
|
370
|
+
} else {
|
|
371
|
+
reportEvent = logPurchaseEventPerProduct(event);
|
|
372
|
+
}
|
|
373
|
+
return reportEvent === true;
|
|
374
|
+
}
|
|
375
|
+
|
|
376
|
+
function logSinglePurchaseEventWithProducts(event) {
|
|
377
|
+
var quantity = 1;
|
|
378
|
+
var eventAttributes = mergeObjects(event.EventAttributes, {
|
|
379
|
+
products: [],
|
|
380
|
+
});
|
|
381
|
+
var eventName = getCommerceEventName(event.EventCategory);
|
|
382
|
+
|
|
383
|
+
// All commerce events except for promotion/impression events will have a
|
|
384
|
+
// ProductAction property, but if this ever changes in the future, this
|
|
385
|
+
// check will prevent errors
|
|
386
|
+
if (!event.ProductAction) {
|
|
387
|
+
return false;
|
|
388
|
+
}
|
|
389
|
+
|
|
390
|
+
if (event.ProductAction.TransactionId) {
|
|
391
|
+
eventAttributes['Transaction Id'] =
|
|
392
|
+
event.ProductAction.TransactionId;
|
|
393
|
+
}
|
|
394
|
+
|
|
395
|
+
if (
|
|
396
|
+
event.ProductAction.ProductList &&
|
|
397
|
+
event.ProductAction.ProductList.length
|
|
398
|
+
) {
|
|
399
|
+
eventAttributes.products = addProducts(
|
|
400
|
+
event.ProductAction.ProductList
|
|
401
|
+
);
|
|
402
|
+
}
|
|
403
|
+
|
|
404
|
+
kitLogger(
|
|
405
|
+
'appboy.logPurchase',
|
|
406
|
+
eventName,
|
|
407
|
+
event.ProductAction.TotalAmount,
|
|
408
|
+
event.CurrencyCode,
|
|
409
|
+
quantity,
|
|
410
|
+
eventAttributes
|
|
411
|
+
);
|
|
412
|
+
|
|
413
|
+
reportEvent = appboy.logPurchase(
|
|
414
|
+
eventName,
|
|
415
|
+
event.ProductAction.TotalAmount,
|
|
416
|
+
event.CurrencyCode,
|
|
417
|
+
quantity,
|
|
418
|
+
eventAttributes
|
|
419
|
+
);
|
|
420
|
+
}
|
|
421
|
+
|
|
422
|
+
function logPurchaseEventPerProduct(event) {
|
|
360
423
|
if (event.ProductAction.ProductList) {
|
|
361
|
-
event.ProductAction.ProductList.forEach(function
|
|
362
|
-
|
|
363
|
-
product.Attributes = {};
|
|
364
|
-
}
|
|
365
|
-
product.Attributes['Sku'] = product.Sku;
|
|
424
|
+
event.ProductAction.ProductList.forEach(function(product) {
|
|
425
|
+
var productName;
|
|
366
426
|
|
|
367
|
-
var sanitizedProductName;
|
|
368
427
|
if (forwarderSettings.forwardSkuAsProductName === 'True') {
|
|
369
|
-
|
|
370
|
-
String(product.Sku)
|
|
371
|
-
);
|
|
428
|
+
productName = product.Sku;
|
|
372
429
|
} else {
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
430
|
+
productName = product.Name;
|
|
431
|
+
}
|
|
432
|
+
var sanitizedProductName = getSanitizedValueForAppboy(
|
|
433
|
+
productName
|
|
434
|
+
);
|
|
435
|
+
|
|
436
|
+
if (product.Attributes == null) {
|
|
437
|
+
product.Attributes = {};
|
|
376
438
|
}
|
|
377
439
|
|
|
440
|
+
product.Attributes['Sku'] = product.Sku;
|
|
441
|
+
|
|
378
442
|
var productAttributes = mergeObjects(product.Attributes, {
|
|
379
443
|
'Transaction Id': event.ProductAction.TransactionId,
|
|
380
444
|
});
|
|
381
445
|
|
|
382
|
-
var sanitizedProperties =
|
|
383
|
-
|
|
446
|
+
var sanitizedProperties = getSanitizedCustomProperties(
|
|
447
|
+
productAttributes
|
|
448
|
+
);
|
|
384
449
|
|
|
385
450
|
if (sanitizedProperties == null) {
|
|
386
451
|
return (
|
|
@@ -411,6 +476,57 @@ var constructor = function () {
|
|
|
411
476
|
return reportEvent === true;
|
|
412
477
|
}
|
|
413
478
|
|
|
479
|
+
function getCommerceEventName(eventType) {
|
|
480
|
+
const eventNamePrefix = 'eCommerce';
|
|
481
|
+
let eventName;
|
|
482
|
+
|
|
483
|
+
switch (eventType) {
|
|
484
|
+
case CommerceEventType.ProductAddToCart:
|
|
485
|
+
eventName = 'add_to_cart';
|
|
486
|
+
break;
|
|
487
|
+
case CommerceEventType.ProductRemoveFromCart:
|
|
488
|
+
eventName = 'remove_from_cart';
|
|
489
|
+
break;
|
|
490
|
+
case CommerceEventType.ProductCheckout:
|
|
491
|
+
eventName = 'checkout';
|
|
492
|
+
break;
|
|
493
|
+
case CommerceEventType.ProductCheckoutOption:
|
|
494
|
+
eventName = 'checkout_option';
|
|
495
|
+
break;
|
|
496
|
+
case CommerceEventType.ProductClick:
|
|
497
|
+
eventName = 'click';
|
|
498
|
+
break;
|
|
499
|
+
case CommerceEventType.ProductViewDetail:
|
|
500
|
+
eventName = 'view_detail';
|
|
501
|
+
break;
|
|
502
|
+
case CommerceEventType.ProductPurchase:
|
|
503
|
+
eventName = 'purchase';
|
|
504
|
+
break;
|
|
505
|
+
case CommerceEventType.ProductRefund:
|
|
506
|
+
eventName = 'refund';
|
|
507
|
+
break;
|
|
508
|
+
case CommerceEventType.ProductAddToWishlist:
|
|
509
|
+
eventName = 'add_to_wishlist';
|
|
510
|
+
break;
|
|
511
|
+
case CommerceEventType.ProductRemoveFromWishlist:
|
|
512
|
+
eventName = 'remove_from_wishlist';
|
|
513
|
+
break;
|
|
514
|
+
case CommerceEventType.PromotionView:
|
|
515
|
+
eventName = 'view';
|
|
516
|
+
break;
|
|
517
|
+
case CommerceEventType.PromotionClick:
|
|
518
|
+
eventName = 'click';
|
|
519
|
+
break;
|
|
520
|
+
case CommerceEventType.ProductImpression:
|
|
521
|
+
eventName = 'Impression';
|
|
522
|
+
break;
|
|
523
|
+
default:
|
|
524
|
+
eventName = 'unknown';
|
|
525
|
+
break;
|
|
526
|
+
}
|
|
527
|
+
return [eventNamePrefix, eventName].join(' - ');
|
|
528
|
+
}
|
|
529
|
+
|
|
414
530
|
function logAppboyPageViewEvent(event) {
|
|
415
531
|
var sanitizedEventName,
|
|
416
532
|
sanitizedAttrs,
|
|
@@ -534,29 +650,8 @@ var constructor = function () {
|
|
|
534
650
|
function processEvent(event) {
|
|
535
651
|
var reportEvent = false;
|
|
536
652
|
|
|
537
|
-
if (
|
|
538
|
-
|
|
539
|
-
event.EventCategory == mParticle.CommerceEventType.ProductPurchase
|
|
540
|
-
) {
|
|
541
|
-
reportEvent = logPurchaseEvent(event);
|
|
542
|
-
} else if (event.EventDataType == MessageType.Commerce) {
|
|
543
|
-
var listOfPageEvents =
|
|
544
|
-
mParticle.eCommerce.expandCommerceEvent(event);
|
|
545
|
-
if (listOfPageEvents != null) {
|
|
546
|
-
for (var i = 0; i < listOfPageEvents.length; i++) {
|
|
547
|
-
// finalLoopResult keeps track of if any logAppBoyEvent in this loop returns true or not
|
|
548
|
-
var finalLoopResult = false;
|
|
549
|
-
try {
|
|
550
|
-
reportEvent = logAppboyEvent(listOfPageEvents[i]);
|
|
551
|
-
if (reportEvent === true) {
|
|
552
|
-
finalLoopResult = true;
|
|
553
|
-
}
|
|
554
|
-
} catch (err) {
|
|
555
|
-
return 'Error logging page event' + err.message;
|
|
556
|
-
}
|
|
557
|
-
}
|
|
558
|
-
reportEvent = finalLoopResult === true;
|
|
559
|
-
}
|
|
653
|
+
if (event.EventDataType == MessageType.Commerce) {
|
|
654
|
+
reportEvent = logCommerceEvent(event);
|
|
560
655
|
} else if (event.EventDataType == MessageType.PageEvent) {
|
|
561
656
|
reportEvent = logAppboyEvent(event);
|
|
562
657
|
} else if (event.EventDataType == MessageType.PageView) {
|
|
@@ -576,6 +671,155 @@ var constructor = function () {
|
|
|
576
671
|
}
|
|
577
672
|
}
|
|
578
673
|
|
|
674
|
+
// mParticle commerce events use different appboy methods depending on if they are
|
|
675
|
+
// a purchase event or a non-purchase commerce event
|
|
676
|
+
function logCommerceEvent(event) {
|
|
677
|
+
if (event.EventCategory === CommerceEventType.ProductPurchase) {
|
|
678
|
+
reportEvent = logPurchaseEvent(event);
|
|
679
|
+
return reportEvent === true;
|
|
680
|
+
} else {
|
|
681
|
+
reportEvent = logNonPurchaseCommerceEvent(event);
|
|
682
|
+
return reportEvent === true;
|
|
683
|
+
}
|
|
684
|
+
}
|
|
685
|
+
|
|
686
|
+
// A non-purchase commerce event can either log a single event with all products
|
|
687
|
+
// or one event per product when the commerce event is expanded
|
|
688
|
+
function logNonPurchaseCommerceEvent(event) {
|
|
689
|
+
if (bundleCommerceEventData) {
|
|
690
|
+
return logNonPurchaseCommerceEventWithProducts(event);
|
|
691
|
+
} else {
|
|
692
|
+
return logExpandedNonPurchaseCommerceEvents(event);
|
|
693
|
+
}
|
|
694
|
+
}
|
|
695
|
+
|
|
696
|
+
function logNonPurchaseCommerceEventWithProducts(mpEvent) {
|
|
697
|
+
const commerceEventAttrs = {};
|
|
698
|
+
const eventName = getCommerceEventName(mpEvent.EventCategory);
|
|
699
|
+
try {
|
|
700
|
+
switch (mpEvent.EventCategory) {
|
|
701
|
+
case CommerceEventType.PromotionClick:
|
|
702
|
+
case CommerceEventType.PromotionView:
|
|
703
|
+
commerceEventAttrs.promotions = addPromotions(
|
|
704
|
+
mpEvent.PromotionAction
|
|
705
|
+
);
|
|
706
|
+
break;
|
|
707
|
+
case CommerceEventType.ProductImpression:
|
|
708
|
+
commerceEventAttrs.impressions = addImpressions(
|
|
709
|
+
mpEvent.ProductImpressions
|
|
710
|
+
);
|
|
711
|
+
break;
|
|
712
|
+
default:
|
|
713
|
+
if (mpEvent.ProductAction.ProductList) {
|
|
714
|
+
commerceEventAttrs.products = addProducts(
|
|
715
|
+
mpEvent.ProductAction.ProductList
|
|
716
|
+
);
|
|
717
|
+
}
|
|
718
|
+
var transactionId = mpEvent.ProductAction.TransactionId;
|
|
719
|
+
if (transactionId) {
|
|
720
|
+
commerceEventAttrs['Transaction Id'] = transactionId;
|
|
721
|
+
}
|
|
722
|
+
}
|
|
723
|
+
|
|
724
|
+
var sanitizedProperties = getSanitizedCustomProperties(
|
|
725
|
+
mpEvent.EventAttributes
|
|
726
|
+
);
|
|
727
|
+
|
|
728
|
+
const brazeEvent = {
|
|
729
|
+
EventName: eventName,
|
|
730
|
+
EventAttributes: mergeObjects(
|
|
731
|
+
commerceEventAttrs,
|
|
732
|
+
sanitizedProperties
|
|
733
|
+
),
|
|
734
|
+
};
|
|
735
|
+
|
|
736
|
+
reportEvent = logAppboyEvent(brazeEvent);
|
|
737
|
+
return reportEvent;
|
|
738
|
+
} catch (err) {
|
|
739
|
+
return 'Error logging commerce event' + err.message;
|
|
740
|
+
}
|
|
741
|
+
}
|
|
742
|
+
|
|
743
|
+
function addPromotions(promotionAction) {
|
|
744
|
+
if (promotionAction && promotionAction.PromotionList) {
|
|
745
|
+
return promotionAction.PromotionList;
|
|
746
|
+
}
|
|
747
|
+
return [];
|
|
748
|
+
}
|
|
749
|
+
|
|
750
|
+
function addImpressions(productImpressions) {
|
|
751
|
+
if (productImpressions.length) {
|
|
752
|
+
return productImpressions.map(function(impression) {
|
|
753
|
+
return {
|
|
754
|
+
'Product Impression List': impression.ProductImpressionList,
|
|
755
|
+
products: addProducts(impression.ProductList),
|
|
756
|
+
};
|
|
757
|
+
});
|
|
758
|
+
} else {
|
|
759
|
+
return [];
|
|
760
|
+
}
|
|
761
|
+
}
|
|
762
|
+
|
|
763
|
+
function addProducts(productList) {
|
|
764
|
+
const productArray = [];
|
|
765
|
+
if (!productList || productList.length === 0) {
|
|
766
|
+
return productArray;
|
|
767
|
+
}
|
|
768
|
+
|
|
769
|
+
productList.forEach(function(product) {
|
|
770
|
+
{
|
|
771
|
+
var sanitizedProduct = parseProduct(
|
|
772
|
+
getSanitizedCustomProperties(product)
|
|
773
|
+
);
|
|
774
|
+
productArray.push(sanitizedProduct);
|
|
775
|
+
}
|
|
776
|
+
});
|
|
777
|
+
|
|
778
|
+
return productArray;
|
|
779
|
+
}
|
|
780
|
+
|
|
781
|
+
function parseProduct(_product) {
|
|
782
|
+
var product = {};
|
|
783
|
+
|
|
784
|
+
for (var key in _product) {
|
|
785
|
+
switch (key) {
|
|
786
|
+
case 'Sku':
|
|
787
|
+
product.Id = _product[key];
|
|
788
|
+
break;
|
|
789
|
+
case 'CouponCode':
|
|
790
|
+
product['Coupon Code'] = _product[key];
|
|
791
|
+
break;
|
|
792
|
+
case 'TotalAmount':
|
|
793
|
+
product['Total Product Amount'] = _product[key];
|
|
794
|
+
break;
|
|
795
|
+
default:
|
|
796
|
+
product[key] = _product[key];
|
|
797
|
+
}
|
|
798
|
+
}
|
|
799
|
+
|
|
800
|
+
return product;
|
|
801
|
+
}
|
|
802
|
+
|
|
803
|
+
function logExpandedNonPurchaseCommerceEvents(event) {
|
|
804
|
+
var listOfPageEvents = mParticle.eCommerce.expandCommerceEvent(event);
|
|
805
|
+
if (listOfPageEvents !== null) {
|
|
806
|
+
for (var i = 0; i < listOfPageEvents.length; i++) {
|
|
807
|
+
// finalLoopResult keeps track of if any logAppBoyEvent in this loop returns true or not
|
|
808
|
+
var finalLoopResult = false;
|
|
809
|
+
try {
|
|
810
|
+
reportEvent = logAppboyEvent(listOfPageEvents[i]);
|
|
811
|
+
if (reportEvent === true) {
|
|
812
|
+
finalLoopResult = true;
|
|
813
|
+
}
|
|
814
|
+
} catch (err) {
|
|
815
|
+
return 'Error logging page event' + err.message;
|
|
816
|
+
}
|
|
817
|
+
}
|
|
818
|
+
reportEvent = finalLoopResult === true;
|
|
819
|
+
}
|
|
820
|
+
return reportEvent;
|
|
821
|
+
}
|
|
822
|
+
|
|
579
823
|
function removeUserAttribute(key) {
|
|
580
824
|
if (!(key in DefaultAttributeMethods)) {
|
|
581
825
|
var sanitizedKey = getSanitizedValueForAppboy(key);
|
|
@@ -665,7 +909,7 @@ var constructor = function () {
|
|
|
665
909
|
// The following code block is based on Braze's best practice for implementing
|
|
666
910
|
// their push primer. We only modify it to include pushPrimer and register_inapp settings.
|
|
667
911
|
// https://www.braze.com/docs/developer_guide/platform_integration_guides/web/push_notifications/integration/#soft-push-prompts
|
|
668
|
-
appboy.subscribeToInAppMessage(function
|
|
912
|
+
appboy.subscribeToInAppMessage(function(inAppMessage) {
|
|
669
913
|
var shouldDisplay = true;
|
|
670
914
|
var pushPrimer = false;
|
|
671
915
|
if (inAppMessage instanceof appboy.InAppMessage) {
|
|
@@ -687,7 +931,7 @@ var constructor = function () {
|
|
|
687
931
|
if (inAppMessage.buttons[0] != null) {
|
|
688
932
|
// Prompt the user when the first button is clicked
|
|
689
933
|
inAppMessage.buttons[0].subscribeToClickedEvent(
|
|
690
|
-
function
|
|
934
|
+
function() {
|
|
691
935
|
appboy.registerAppboyPushMessages();
|
|
692
936
|
}
|
|
693
937
|
);
|
|
@@ -729,25 +973,27 @@ var constructor = function () {
|
|
|
729
973
|
customFlags
|
|
730
974
|
) {
|
|
731
975
|
console.warn(
|
|
732
|
-
'mParticle
|
|
976
|
+
'mParticle now supports V4 of the Braze SDK. This is an opt-in update, and we recommend you opt in to get the latest bug fixes and features from Braze. Please see https://docs.mparticle.com/integrations/braze/event for more information and necessary upgrade steps when you decide to opt in.'
|
|
733
977
|
);
|
|
734
978
|
// check to see if there is a logger for backwards compatibility, and if not, mock one to avoid errors
|
|
735
979
|
if (!self.logger) {
|
|
736
980
|
// create a logger
|
|
737
981
|
self.logger = {
|
|
738
|
-
verbose: function
|
|
982
|
+
verbose: function() {},
|
|
739
983
|
};
|
|
740
984
|
}
|
|
741
985
|
// eslint-disable-line no-unused-vars
|
|
742
986
|
mpCustomFlags = customFlags;
|
|
743
987
|
try {
|
|
744
988
|
forwarderSettings = settings;
|
|
989
|
+
bundleCommerceEventData =
|
|
990
|
+
forwarderSettings.bundleCommerceEventData === 'True';
|
|
745
991
|
reportingService = service;
|
|
746
992
|
// 30 min is Appboy default
|
|
747
993
|
options.sessionTimeoutInSeconds =
|
|
748
994
|
forwarderSettings.ABKSessionTimeoutKey || 1800;
|
|
749
995
|
options.sdkFlavor = 'mparticle';
|
|
750
|
-
options.
|
|
996
|
+
options.allowUserSuppliedJavascript =
|
|
751
997
|
forwarderSettings.enableHtmlInAppMessages == 'True';
|
|
752
998
|
options.doNotLoadFontAwesome =
|
|
753
999
|
forwarderSettings.doNotLoadFontAwesome == 'True';
|
|
@@ -908,7 +1154,7 @@ var constructor = function () {
|
|
|
908
1154
|
var nonMethodArguments = Array.prototype.slice.call(arguments, 1);
|
|
909
1155
|
msg += '\n' + method + ':\n';
|
|
910
1156
|
|
|
911
|
-
nonMethodArguments.forEach(function
|
|
1157
|
+
nonMethodArguments.forEach(function(arg) {
|
|
912
1158
|
if (isObject(arg) || Array.isArray(arg)) {
|
|
913
1159
|
msg += JSON.stringify(arg);
|
|
914
1160
|
} else {
|
|
@@ -926,9 +1172,11 @@ function getId() {
|
|
|
926
1172
|
}
|
|
927
1173
|
|
|
928
1174
|
function register(config) {
|
|
1175
|
+
var forwarderNameWithSuffix = [name, suffix].join('-');
|
|
929
1176
|
if (!config) {
|
|
930
1177
|
window.console.log(
|
|
931
|
-
'You must pass a config object to register the kit ' +
|
|
1178
|
+
'You must pass a config object to register the kit ' +
|
|
1179
|
+
forwarderNameWithSuffix
|
|
932
1180
|
);
|
|
933
1181
|
return;
|
|
934
1182
|
}
|
|
@@ -941,17 +1189,19 @@ function register(config) {
|
|
|
941
1189
|
}
|
|
942
1190
|
|
|
943
1191
|
if (isObject(config.kits)) {
|
|
944
|
-
config.kits[
|
|
1192
|
+
config.kits[forwarderNameWithSuffix] = {
|
|
945
1193
|
constructor: constructor,
|
|
946
1194
|
};
|
|
947
1195
|
} else {
|
|
948
1196
|
config.kits = {};
|
|
949
|
-
config.kits[
|
|
1197
|
+
config.kits[forwarderNameWithSuffix] = {
|
|
950
1198
|
constructor: constructor,
|
|
951
1199
|
};
|
|
952
1200
|
}
|
|
953
1201
|
window.console.log(
|
|
954
|
-
'Successfully registered ' +
|
|
1202
|
+
'Successfully registered ' +
|
|
1203
|
+
forwarderNameWithSuffix +
|
|
1204
|
+
' to your mParticle configuration'
|
|
955
1205
|
);
|
|
956
1206
|
}
|
|
957
1207
|
|
|
@@ -960,6 +1210,9 @@ if (window && window.mParticle && window.mParticle.addForwarder) {
|
|
|
960
1210
|
name: name,
|
|
961
1211
|
constructor: constructor,
|
|
962
1212
|
getId: getId,
|
|
1213
|
+
// A suffix is added if there are multiple different versions of
|
|
1214
|
+
// a client kit. This matches the suffix in the DB.
|
|
1215
|
+
suffix: suffix,
|
|
963
1216
|
});
|
|
964
1217
|
}
|
|
965
1218
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mparticle/web-braze-kit",
|
|
3
|
-
"version": "3.0.
|
|
3
|
+
"version": "3.0.9",
|
|
4
4
|
"author": "mParticle Developers <developers@mparticle.com> (https://www.mparticle.com)",
|
|
5
5
|
"description": "mParticle integration sdk for Braze",
|
|
6
6
|
"main": "dist/BrazeKit.common.js",
|
|
@@ -31,7 +31,7 @@
|
|
|
31
31
|
},
|
|
32
32
|
"dependencies": {
|
|
33
33
|
"@braze/web-sdk": "^3.5.0",
|
|
34
|
-
"@mparticle/web-sdk": "^2.
|
|
34
|
+
"@mparticle/web-sdk": "^2.23.0"
|
|
35
35
|
},
|
|
36
36
|
"license": "Apache-2.0"
|
|
37
37
|
}
|
package/CHANGELOG.md
DELETED
|
@@ -1,57 +0,0 @@
|
|
|
1
|
-
## Releases
|
|
2
|
-
|
|
3
|
-
--
|
|
4
|
-
|
|
5
|
-
#### 3.0.5 - 2023-02-15
|
|
6
|
-
- refactor: Update console warning and readme to reflect new rollout plans (#19)
|
|
7
|
-
|
|
8
|
-
#### 3.0.5 - 2022-10-20
|
|
9
|
-
- docs: Update README to alert developers about v4 kit upgrade date, add console warning to current CDN users (#15)
|
|
10
|
-
|
|
11
|
-
#### 3.0.4 - 2022-09-06
|
|
12
|
-
- fix: Add Transaction Id to Purchase Commerce Events
|
|
13
|
-
|
|
14
|
-
#### 3.0.3 - 2022-08-24
|
|
15
|
-
- feat: Add logging for debugging
|
|
16
|
-
|
|
17
|
-
#### 3.0.2 - 2022-06-16
|
|
18
|
-
- fix: add register_inapp and pushPrimer variables
|
|
19
|
-
|
|
20
|
-
#### 3.0.1 - 2022-05-18
|
|
21
|
-
|
|
22
|
-
- consume initOptions customFlags - this allows a customer to pass a callback to include additional options that mParticle doesn't support in the UI
|
|
23
|
-
|
|
24
|
-
#### 3.0.0 - 2022-03-28
|
|
25
|
-
|
|
26
|
-
⚠️ **Breaking** - If you reference any of the below deprecations and implement mParticle via snippet, you will have to make changes to your codebase before June 8, 2022 to be compatible with both version 2 and version 3 of the Braze SDK to ensure your code continues to work.
|
|
27
|
-
* Our partner, Braze, has made a few significant changes to their web SDK. As a result, we are also updating our mParticle Braze web kit to support Braze’s Web SDK version 3.5.0, which includes breaking changes to the Braze SDK behavior. The updated mParticle Braze Web kit will be available via CDN on June 8, 2022 and is currently available on NPM at @mparticle/web-braze-kit v3.0.0. Also note that we have updated the name of our npm package from @mparticle/web-appboy-kit to @mparticle/web-braze-kit.
|
|
28
|
-
* We highly recommend that you review the changes between version 2 and 3 of the Braze Web SDK to understand these changes, which can be found here. To summarize:
|
|
29
|
-
* The `appboy.ab` namespace has been removed and everything lives under the `appboy` namespace now.
|
|
30
|
-
* `InAppMessage.Button` has been renamed to `InAppMessageButton`
|
|
31
|
-
* Full details can be found in the README at our [AppBoy Repo](https://github.com/mparticle-integrations/mparticle-javascript-integration-appboy#readme).
|
|
32
|
-
|
|
33
|
-
#### 2.0.7 - 2022-02-09
|
|
34
|
-
|
|
35
|
-
- Feat - add new Braze clusters
|
|
36
|
-
|
|
37
|
-
#### 2.0.6 - 2020-12-10
|
|
38
|
-
|
|
39
|
-
- Feat - Add additional Braze clusters to URL mapping table
|
|
40
|
-
|
|
41
|
-
#### 2.0.5 - 2020-06-04
|
|
42
|
-
|
|
43
|
-
- Update Braze to 2.5.2
|
|
44
|
-
|
|
45
|
-
#### 2.0.4 - 2020-02-12
|
|
46
|
-
|
|
47
|
-
- Send SKU if forwardSkuAsProductName is set
|
|
48
|
-
|
|
49
|
-
#### 2.0.2 - 2020-01-23
|
|
50
|
-
|
|
51
|
-
- Feat - Set event name sent to Braze as user provided pageName
|
|
52
|
-
|
|
53
|
-
#### 2.0.1 - 2019-12-03
|
|
54
|
-
|
|
55
|
-
- Bugfix - Respect userId choice in mParticle UI dropdown
|
|
56
|
-
- Add version number
|
|
57
|
-
- Remove isObject dependency
|