@mparticle/web-braze-kit 3.0.0 → 3.0.3
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/CHANGELOG.md +10 -0
- package/README.md +7 -7
- package/dist/BrazeKit.common.js +132 -9
- package/package.json +2 -2
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,16 @@
|
|
|
2
2
|
|
|
3
3
|
--
|
|
4
4
|
|
|
5
|
+
#### 3.0.3 - 2022-08-24
|
|
6
|
+
- feat: Add logging for debugging
|
|
7
|
+
|
|
8
|
+
#### 3.0.2 - 2022-06-16
|
|
9
|
+
- fix: add register_inapp and pushPrimer variables
|
|
10
|
+
|
|
11
|
+
#### 3.0.1 - 2022-05-18
|
|
12
|
+
|
|
13
|
+
- consume initOptions customFlags - this allows a customer to pass a callback to include additional options that mParticle doesn't support in the UI
|
|
14
|
+
|
|
5
15
|
#### 3.0.0 - 2022-03-28
|
|
6
16
|
|
|
7
17
|
⚠️ **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.
|
package/README.md
CHANGED
|
@@ -1,29 +1,29 @@
|
|
|
1
1
|

|
|
2
2
|
|
|
3
3
|
⚠️⚠️⚠️
|
|
4
|
-
# Notice! Timeline for Breaking Changes for mParticle Web Braze Kit- 3/28/2022 - 6/
|
|
4
|
+
# Notice! Timeline for Breaking Changes for mParticle Web Braze Kit- 3/28/2022 - 6/14/2022
|
|
5
5
|
This repository renames and replaces our [mParticle Appboy Web Kit](https://github.com/mparticle-integrations/mparticle-javascript-integration-appboy), which will be archived in the future.
|
|
6
6
|
|
|
7
|
-
Braze has breaking changes between version 2.5.2 and 3.5.0 of their SDK. As a result, we too are updating our [mParticle Braze web kit](https://github.com/mparticle-integrations/mparticle-javascript-integration-appboy) to support Braze’s Web SDK version 3.5.0. The updated mParticle Braze Web kit will be available via CDN on June
|
|
7
|
+
Braze has breaking changes between version 2.5.2 and 3.5.0 of their SDK. As a result, we too are updating our [mParticle Braze web kit](https://github.com/mparticle-integrations/mparticle-javascript-integration-appboy) to support Braze’s Web SDK version 3.5.0. The updated mParticle Braze Web kit will be available via CDN on June 14, 2022 and is currently available on NPM as [@mparticle/web-braze-kit](https://www.npmjs.com/package/@mparticle/web-braze-kit) v3.0.1.
|
|
8
8
|
|
|
9
9
|
**How do you know if your code is affected?**
|
|
10
10
|
|
|
11
|
-
You may notice errors on your site if you load mParticle [via snippet](https://docs.mparticle.com/developers/sdk/web/getting-started/#add-the-sdk-snippet) (as most of our clients do), and you reference any deprecated Braze APIs starting 6/
|
|
11
|
+
You may notice errors on your site if you load mParticle [via snippet](https://docs.mparticle.com/developers/sdk/web/getting-started/#add-the-sdk-snippet) (as most of our clients do), and you reference any deprecated Braze APIs starting 6/14/2022.
|
|
12
12
|
|
|
13
13
|
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](https://www.braze.com/docs/developer_guide/platform_integration_guides/web/changelog/#300). To summarize:
|
|
14
14
|
* The `appboy.ab` namespace has been removed and everything lives under the `appboy` namespace now.
|
|
15
15
|
* `InAppMessage.Button` has been renamed to `InAppMessageButton`
|
|
16
16
|
|
|
17
|
-
If you reference any of the above deprecations, you will have to makes changes to your codebase before June
|
|
17
|
+
If you reference any of the above deprecations, you will have to makes changes to your codebase before June 14, 2022 to be compatible with both version 2 and version 3 of the Braze SDK to ensure your code continues to work. We recommend a 3 step approach. Here are some code samples of what this code could look like today (step 1), preparing for the update (step 2) and after the change is live (step 3).
|
|
18
18
|
|
|
19
|
-
The below recommendations apply only to customers who load mParticle [via snippet](https://docs.mparticle.com/developers/sdk/web/getting-started/#add-the-sdk-snippet). Customers who [self host via NPM](https://docs.mparticle.com/developers/sdk/web/self-hosting/) can ignore step 1 and jump straight to step 3 after updating their mParticle Braze kit to v3.0.
|
|
19
|
+
The below recommendations apply only to customers who load mParticle [via snippet](https://docs.mparticle.com/developers/sdk/web/getting-started/#add-the-sdk-snippet). Customers who [self host via NPM](https://docs.mparticle.com/developers/sdk/web/self-hosting/) can ignore step 1 and jump straight to step 3 after updating their mParticle Braze kit to v3.0.1.
|
|
20
20
|
|
|
21
21
|
Step 1: Legacy code sample. If your code references the `ab` namespace (like below) or `InAppMessage.Button`, you should change it following Step 2’s example:
|
|
22
22
|
```javascript
|
|
23
23
|
let banner = new appboy.ab.Banner(‘test’);
|
|
24
24
|
```
|
|
25
25
|
|
|
26
|
-
Step 2: Rollout code sample to be used before June
|
|
26
|
+
Step 2: Rollout code sample to be used before June 14, 2022:
|
|
27
27
|
```javascript
|
|
28
28
|
let banner;
|
|
29
29
|
if (appboy.hasOwnProperty(‘ab’)) {
|
|
@@ -32,7 +32,7 @@ if (appboy.hasOwnProperty(‘ab’)) {
|
|
|
32
32
|
banner = new appboy.Banner(‘test’);
|
|
33
33
|
}
|
|
34
34
|
```
|
|
35
|
-
Step 3: After June
|
|
35
|
+
Step 3: After June 14, 2022, you can simplify your code to the following once the mParticle Braze Web kit has been released to our CDN:
|
|
36
36
|
```javascript
|
|
37
37
|
let banner = new appboy.Banner(‘test’);
|
|
38
38
|
```
|
package/dist/BrazeKit.common.js
CHANGED
|
@@ -305,7 +305,7 @@ window.appboy = appboy_min;
|
|
|
305
305
|
|
|
306
306
|
var name = 'Appboy',
|
|
307
307
|
moduleId = 28,
|
|
308
|
-
version = '
|
|
308
|
+
version = '3.0.3',
|
|
309
309
|
MessageType = {
|
|
310
310
|
PageView: 3,
|
|
311
311
|
PageEvent: 4,
|
|
@@ -328,7 +328,8 @@ var constructor = function() {
|
|
|
328
328
|
var self = this,
|
|
329
329
|
forwarderSettings,
|
|
330
330
|
options = {},
|
|
331
|
-
reportingService
|
|
331
|
+
reportingService,
|
|
332
|
+
mpCustomFlags;
|
|
332
333
|
|
|
333
334
|
self.name = name;
|
|
334
335
|
|
|
@@ -384,10 +385,20 @@ var constructor = function() {
|
|
|
384
385
|
sanitizedProductName
|
|
385
386
|
);
|
|
386
387
|
}
|
|
388
|
+
var price = parseFloat(product.Price);
|
|
389
|
+
|
|
390
|
+
kitLogger(
|
|
391
|
+
'appboy.logPurchase',
|
|
392
|
+
sanitizedProductName,
|
|
393
|
+
price,
|
|
394
|
+
event.CurrencyCode,
|
|
395
|
+
product.Quantity,
|
|
396
|
+
sanitizedProperties
|
|
397
|
+
);
|
|
387
398
|
|
|
388
399
|
reportEvent = appboy.logPurchase(
|
|
389
400
|
sanitizedProductName,
|
|
390
|
-
|
|
401
|
+
price,
|
|
391
402
|
event.CurrencyCode,
|
|
392
403
|
product.Quantity,
|
|
393
404
|
sanitizedProperties
|
|
@@ -413,6 +424,9 @@ var constructor = function() {
|
|
|
413
424
|
}
|
|
414
425
|
sanitizedEventName = getSanitizedValueForAppboy(eventName);
|
|
415
426
|
sanitizedAttrs = getSanitizedCustomProperties(attrs);
|
|
427
|
+
|
|
428
|
+
kitLogger('appboy.logCustomEvent', sanitizedEventName, sanitizedAttrs);
|
|
429
|
+
|
|
416
430
|
var reportEvent = appboy.logCustomEvent(
|
|
417
431
|
sanitizedEventName,
|
|
418
432
|
sanitizedAttrs
|
|
@@ -429,6 +443,13 @@ var constructor = function() {
|
|
|
429
443
|
", removeUserAttribute or setUserAttribute must set 'dob' to a date"
|
|
430
444
|
);
|
|
431
445
|
} else {
|
|
446
|
+
kitLogger(
|
|
447
|
+
'appoy.getUser().setDateOfBirth',
|
|
448
|
+
value.getFullYear(),
|
|
449
|
+
value.getMonth() + 1,
|
|
450
|
+
value.getDate()
|
|
451
|
+
);
|
|
452
|
+
|
|
432
453
|
appboy
|
|
433
454
|
.getUser()
|
|
434
455
|
.setDateOfBirth(
|
|
@@ -440,6 +461,9 @@ var constructor = function() {
|
|
|
440
461
|
} else if (key === '$Age') {
|
|
441
462
|
if (typeof value === 'number') {
|
|
442
463
|
var year = new Date().getFullYear() - value;
|
|
464
|
+
|
|
465
|
+
kitLogger('appboy.getUser().setDateOfBirth', year, 1, 1);
|
|
466
|
+
|
|
443
467
|
appboy.getUser().setDateOfBirth(year, 1, 1);
|
|
444
468
|
} else {
|
|
445
469
|
return '$Age must be a number';
|
|
@@ -457,6 +481,12 @@ var constructor = function() {
|
|
|
457
481
|
}
|
|
458
482
|
var params = [];
|
|
459
483
|
params.push(value);
|
|
484
|
+
|
|
485
|
+
kitLogger(
|
|
486
|
+
'appboy.getUser().' + DefaultAttributeMethods[key],
|
|
487
|
+
params
|
|
488
|
+
);
|
|
489
|
+
|
|
460
490
|
var u = appboy.getUser();
|
|
461
491
|
//This method uses the setLastName, setFirstName, setEmail, setCountry, setHomeCity, setPhoneNumber, setAvatarImageUrl, setDateOfBirth, setGender, setEmailNotificationSubscriptionType, and setPushNotificationSubscriptionType methods
|
|
462
492
|
if (!u[DefaultAttributeMethods[key]].apply(u, params)) {
|
|
@@ -481,10 +511,17 @@ var constructor = function() {
|
|
|
481
511
|
);
|
|
482
512
|
}
|
|
483
513
|
|
|
514
|
+
kitLogger(
|
|
515
|
+
'appboy.logCustomEvent',
|
|
516
|
+
sanitizedEventName,
|
|
517
|
+
sanitizedProperties
|
|
518
|
+
);
|
|
519
|
+
|
|
484
520
|
var reportEvent = appboy.logCustomEvent(
|
|
485
521
|
sanitizedEventName,
|
|
486
522
|
sanitizedProperties
|
|
487
523
|
);
|
|
524
|
+
|
|
488
525
|
return reportEvent === true;
|
|
489
526
|
}
|
|
490
527
|
|
|
@@ -540,6 +577,13 @@ var constructor = function() {
|
|
|
540
577
|
function removeUserAttribute(key) {
|
|
541
578
|
if (!(key in DefaultAttributeMethods)) {
|
|
542
579
|
var sanitizedKey = getSanitizedValueForAppboy(key);
|
|
580
|
+
|
|
581
|
+
kitLogger(
|
|
582
|
+
'appboy.getUser().setCustomUserAttribute',
|
|
583
|
+
sanitizedKey,
|
|
584
|
+
null
|
|
585
|
+
);
|
|
586
|
+
|
|
543
587
|
appboy.getUser().setCustomUserAttribute(sanitizedKey, null);
|
|
544
588
|
} else {
|
|
545
589
|
return setDefaultAttribute(key, null);
|
|
@@ -553,6 +597,13 @@ var constructor = function() {
|
|
|
553
597
|
if (value != null && sanitizedValue == null) {
|
|
554
598
|
return 'Value did not pass validation for ' + key;
|
|
555
599
|
}
|
|
600
|
+
|
|
601
|
+
kitLogger(
|
|
602
|
+
'appboy.getUser().setCustomUserAttribute',
|
|
603
|
+
sanitizedKey,
|
|
604
|
+
sanitizedValue
|
|
605
|
+
);
|
|
606
|
+
|
|
556
607
|
appboy
|
|
557
608
|
.getUser()
|
|
558
609
|
.setCustomUserAttribute(sanitizedKey, sanitizedValue);
|
|
@@ -566,8 +617,12 @@ var constructor = function() {
|
|
|
566
617
|
// Other versions use onUserIdentified, which is called after setUserIdentity from core SDK
|
|
567
618
|
if (window.mParticle.getVersion().split('.')[0] === '1') {
|
|
568
619
|
if (type == window.mParticle.IdentityType.CustomerId) {
|
|
620
|
+
kitLogger('appboy.changeUser', id);
|
|
621
|
+
|
|
569
622
|
appboy.changeUser(id);
|
|
570
623
|
} else if (type == window.mParticle.IdentityType.Email) {
|
|
624
|
+
kitLogger('appboy.getUser().setEmail', id);
|
|
625
|
+
|
|
571
626
|
appboy.getUser().setEmail(id);
|
|
572
627
|
} else {
|
|
573
628
|
return (
|
|
@@ -593,26 +648,31 @@ var constructor = function() {
|
|
|
593
648
|
];
|
|
594
649
|
}
|
|
595
650
|
|
|
651
|
+
kitLogger('appboy.changeUser', appboyUserIDType);
|
|
652
|
+
|
|
596
653
|
appboy.changeUser(appboyUserIDType);
|
|
597
654
|
|
|
598
655
|
if (userIdentities.email) {
|
|
656
|
+
kitLogger('appboy.getUser().setEmail', userIdentities.email);
|
|
657
|
+
|
|
599
658
|
appboy.getUser().setEmail(userIdentities.email);
|
|
600
659
|
}
|
|
601
660
|
}
|
|
602
661
|
|
|
603
662
|
function primeAppBoyWebPush() {
|
|
604
|
-
// The following code block is Braze's best practice for implementing
|
|
605
|
-
// their push primer.
|
|
663
|
+
// The following code block is based on Braze's best practice for implementing
|
|
664
|
+
// their push primer. We only modify it to include pushPrimer and register_inapp settings.
|
|
606
665
|
// https://www.braze.com/docs/developer_guide/platform_integration_guides/web/push_notifications/integration/#soft-push-prompts
|
|
607
666
|
appboy.subscribeToInAppMessage(function(inAppMessage) {
|
|
608
667
|
var shouldDisplay = true;
|
|
609
|
-
|
|
668
|
+
var pushPrimer = false;
|
|
610
669
|
if (inAppMessage instanceof appboy.InAppMessage) {
|
|
611
670
|
// Read the key-value pair for msg-id
|
|
612
671
|
var msgId = inAppMessage.extras['msg-id'];
|
|
613
672
|
|
|
614
673
|
// If this is our push primer message
|
|
615
674
|
if (msgId == 'push-primer') {
|
|
675
|
+
pushPrimer = true;
|
|
616
676
|
// We don't want to display the soft push prompt to users on browsers that don't support push, or if the user
|
|
617
677
|
// has already granted/blocked permission
|
|
618
678
|
if (
|
|
@@ -633,8 +693,11 @@ var constructor = function() {
|
|
|
633
693
|
}
|
|
634
694
|
}
|
|
635
695
|
|
|
636
|
-
// Display the message
|
|
637
|
-
if (
|
|
696
|
+
// Display the message if it's a push primer message and shouldDisplay is true
|
|
697
|
+
if (
|
|
698
|
+
(pushPrimer && shouldDisplay) ||
|
|
699
|
+
(!pushPrimer && forwarderSettings.register_inapp === 'True')
|
|
700
|
+
) {
|
|
638
701
|
appboy.display.showInAppMessage(inAppMessage);
|
|
639
702
|
}
|
|
640
703
|
});
|
|
@@ -643,12 +706,35 @@ var constructor = function() {
|
|
|
643
706
|
function openSession(forwarderSettings) {
|
|
644
707
|
appboy.openSession();
|
|
645
708
|
if (forwarderSettings.softPushCustomEventName) {
|
|
709
|
+
kitLogger(
|
|
710
|
+
'appboy.logCustomEvent',
|
|
711
|
+
forwarderSettings.softPushCustomEventName
|
|
712
|
+
);
|
|
713
|
+
|
|
646
714
|
appboy.logCustomEvent(forwarderSettings.softPushCustomEventName);
|
|
647
715
|
}
|
|
648
716
|
}
|
|
649
717
|
|
|
650
|
-
function initForwarder(
|
|
718
|
+
function initForwarder(
|
|
719
|
+
settings,
|
|
720
|
+
service,
|
|
721
|
+
testMode,
|
|
722
|
+
trackerId,
|
|
723
|
+
userAttributes,
|
|
724
|
+
userIdentities,
|
|
725
|
+
appVersion,
|
|
726
|
+
appName,
|
|
727
|
+
customFlags
|
|
728
|
+
) {
|
|
729
|
+
// check to see if there is a logger for backwards compatibility, and if not, mock one to avoid errors
|
|
730
|
+
if (!self.logger) {
|
|
731
|
+
// create a logger
|
|
732
|
+
self.logger = {
|
|
733
|
+
verbose: function() {},
|
|
734
|
+
};
|
|
735
|
+
}
|
|
651
736
|
// eslint-disable-line no-unused-vars
|
|
737
|
+
mpCustomFlags = customFlags;
|
|
652
738
|
try {
|
|
653
739
|
forwarderSettings = settings;
|
|
654
740
|
reportingService = service;
|
|
@@ -683,6 +769,14 @@ var constructor = function() {
|
|
|
683
769
|
options.baseUrl = customUrl;
|
|
684
770
|
}
|
|
685
771
|
}
|
|
772
|
+
|
|
773
|
+
if (mpCustomFlags && mpCustomFlags[moduleId.toString()]) {
|
|
774
|
+
var brazeFlags = mpCustomFlags[moduleId.toString()];
|
|
775
|
+
if (typeof brazeFlags.initOptions === 'function') {
|
|
776
|
+
brazeFlags.initOptions(options);
|
|
777
|
+
}
|
|
778
|
+
}
|
|
779
|
+
|
|
686
780
|
if (testMode !== true) {
|
|
687
781
|
appboy.initialize(forwarderSettings.apiKey, options);
|
|
688
782
|
finishAppboyInitialization(forwarderSettings);
|
|
@@ -791,6 +885,35 @@ var constructor = function() {
|
|
|
791
885
|
this.onUserIdentified = onUserIdentified;
|
|
792
886
|
this.removeUserAttribute = removeUserAttribute;
|
|
793
887
|
this.decodeClusterSetting = decodeClusterSetting;
|
|
888
|
+
|
|
889
|
+
/* An example output of this logger if we pass in a purchase event for 1 iPhone
|
|
890
|
+
with a SKU of iphoneSku that cost $999 with a product attribute of
|
|
891
|
+
color: blue would be:
|
|
892
|
+
mParticle - Braze Web Kit log:
|
|
893
|
+
appboy.logPurchase:
|
|
894
|
+
iphone,
|
|
895
|
+
999,
|
|
896
|
+
USD,
|
|
897
|
+
1,
|
|
898
|
+
{\"color\":\"blue\",\"Sku":"iphoneSKU"},\n`;
|
|
899
|
+
*/
|
|
900
|
+
function kitLogger(method) {
|
|
901
|
+
var msg = 'mParticle - Braze Web Kit log:';
|
|
902
|
+
|
|
903
|
+
var nonMethodArguments = Array.prototype.slice.call(arguments, 1);
|
|
904
|
+
msg += '\n' + method + ':\n';
|
|
905
|
+
|
|
906
|
+
nonMethodArguments.forEach(function(arg) {
|
|
907
|
+
if (isObject(arg) || Array.isArray(arg)) {
|
|
908
|
+
msg += JSON.stringify(arg);
|
|
909
|
+
} else {
|
|
910
|
+
msg += arg;
|
|
911
|
+
}
|
|
912
|
+
msg += ',\n';
|
|
913
|
+
});
|
|
914
|
+
|
|
915
|
+
self.logger.verbose(msg);
|
|
916
|
+
}
|
|
794
917
|
};
|
|
795
918
|
|
|
796
919
|
function getId() {
|
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.3",
|
|
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.17.0"
|
|
35
35
|
},
|
|
36
36
|
"license": "Apache-2.0"
|
|
37
37
|
}
|