@mparticle/web-braze-kit 4.1.2 → 4.2.0

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 ADDED
@@ -0,0 +1,93 @@
1
+ ## Releases
2
+
3
+ --
4
+
5
+ ## 4.2.0 - 2024-10-24
6
+
7
+ - fix: Report purchase events to mParticle when bundling ecommerce data [#50](https://github.com/mparticle-integrations/mparticle-javascript-integration-braze/pull/50)
8
+ - feat: Implement Google EU Consent [#51](https://github.com/mparticle-integrations/mparticle-javascript-integration-braze/pull/51)
9
+
10
+ ## 4.1.5 - 2024-05-07
11
+
12
+ - fix: Allow any userIdentificationType to be used when initializing kit (#48)
13
+
14
+ ## 4.1.4 - 2024-01-24
15
+
16
+ - fix: Forward SKU as product name when ecommerce events are bundled [#47](https://github.com/mparticle-integrations/mparticle-javascript-integration-braze/pull/47)
17
+
18
+ ## 4.1.3 - 2023-09-25
19
+
20
+ - fix: Add custom logging for onUserIdentified [#42](https://github.com/mparticle-integrations/mparticle-javascript-integration-braze/pull/42))
21
+
22
+ ## 4.1.2 - 2023-07-25
23
+
24
+ - fix: Set MPID before open session ([#41](https://github.com/mparticle-integrations/mparticle-javascript-integration-braze/pull/41))
25
+
26
+ ## 4.1.1 - 2023-06-30
27
+ - fix: Support bundling products, impressions, and promotions as a single event (#36)
28
+
29
+ ## 4.1.0 - 2023-06-28
30
+ - feat: Support bundling products, impressions, and promotions as a single event (#36)
31
+
32
+ ## 4.0.2 - 2023-06-26
33
+ - fix: Update @mparticle/web-sdk version in package.json
34
+ - ci: Update node version (#35)
35
+ - docs: Update readme to include Braze V4 SDK option (#28)
36
+
37
+ ## 4.0.1 - 2023-06-12
38
+ - fix: Add suffix of v4 to forwarder (#21)
39
+
40
+ ## 4.0.0 - 2022-10-19
41
+
42
+ ⚠️ **Breaking** - The mParticle web Braze kit now supports Braze's Web SDK V4.2.1.
43
+ * Our partner, Braze, has made 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 4.2.1. The updated mParticle Braze Web kit will be available via CDN on Feb 15, 2023 and is currently available on npm at @mparticle/web-braze-kit v4.0.0.
44
+ * There are lots of breaking changes, most notably Braze deprecating the entire `appboy` namespace in favor of `braze`, so please proceed with caution when updating to v4.0.0 via NPM. If you implement mParticle via snippet, you will have to make changes to your codebase before Feb 15, 2023 to be compatible with both version 3 and version 4 of the Braze SDK to ensure your code continues to work.
45
+ * Full details about the changes and recommended code changes can be found on mParticle's [Braze integration docs page](https://docs.mparticle.com/integrations/braze/event).
46
+
47
+ #### 3.0.4 - 2022-09-06
48
+ - fix: Add Transaction Id to Purchase Commerce Events
49
+
50
+ #### 3.0.3 - 2022-08-24
51
+ - feat: Add logging for debugging
52
+
53
+ #### 3.0.2 - 2022-06-16
54
+ - fix: add register_inapp and pushPrimer variables
55
+
56
+ #### 3.0.1 - 2022-05-18
57
+
58
+ - consume initOptions customFlags - this allows a customer to pass a callback to include additional options that mParticle doesn't support in the UI
59
+
60
+ #### 3.0.0 - 2022-03-28
61
+
62
+ ⚠️ **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.
63
+ * 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.
64
+ * 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:
65
+ * The `appboy.ab` namespace has been removed and everything lives under the `appboy` namespace now.
66
+ * `InAppMessage.Button` has been renamed to `InAppMessageButton`
67
+ * Full details can be found in the README at our [AppBoy Repo](https://github.com/mparticle-integrations/mparticle-javascript-integration-appboy#readme).
68
+
69
+ #### 2.0.7 - 2022-02-09
70
+
71
+ - Feat - add new Braze clusters
72
+
73
+ #### 2.0.6 - 2020-12-10
74
+
75
+ - Feat - Add additional Braze clusters to URL mapping table
76
+
77
+ #### 2.0.5 - 2020-06-04
78
+
79
+ - Update Braze to 2.5.2
80
+
81
+ #### 2.0.4 - 2020-02-12
82
+
83
+ - Send SKU if forwardSkuAsProductName is set
84
+
85
+ #### 2.0.2 - 2020-01-23
86
+
87
+ - Feat - Set event name sent to Braze as user provided pageName
88
+
89
+ #### 2.0.1 - 2019-12-03
90
+
91
+ - Bugfix - Respect userId choice in mParticle UI dropdown
92
+ - Add version number
93
+ - Remove isObject dependency
package/README.md CHANGED
@@ -8,8 +8,8 @@ You can now select what version of the Braze SDK you want to use when setting up
8
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.
9
9
 
10
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 can use @mparticle/web-braze-kit version 4.0.0 in your package.json now! This has been available since 10/15/2022.
12
- * Customers who load mParticle via snippet/CDN - Opting in is available via the mParticle UI in your Braze connection settings.
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. You must also select `Version 4` under `Braze Web SDK Version` in the Braze connection settings.
12
+ * Customers who load mParticle via snippet/CDN - You must select `Version 4` under `Braze Web SDK Version` in the 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
 
@@ -27,7 +27,7 @@ if (window.appboy) {
27
27
  window.braze.destroyFeed();
28
28
  }
29
29
  ```
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.
30
+ Step 3: Whether you are using the snippet or self hosting, you need to navigate to your Braze connection settings and select `Version 4` from the `Braze Web SDK Version` drop down.
31
31
 
32
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:
33
33
  ```javascript
@@ -9172,7 +9172,7 @@ window.braze = require$$0;
9172
9172
  var name = 'Appboy',
9173
9173
  suffix = 'v4',
9174
9174
  moduleId = 28,
9175
- version = '4.1.2',
9175
+ version = '4.2.0',
9176
9176
  MessageType = {
9177
9177
  PageView: 3,
9178
9178
  PageEvent: 4,
@@ -9197,6 +9197,8 @@ var constructor = function () {
9197
9197
  forwarderSettings,
9198
9198
  options = {},
9199
9199
  reportingService,
9200
+ hasConsentMappings,
9201
+ parsedConsentMappings,
9200
9202
  mpCustomFlags;
9201
9203
 
9202
9204
  self.name = name;
@@ -9224,6 +9226,14 @@ var constructor = function () {
9224
9226
  };
9225
9227
 
9226
9228
  var bundleCommerceEventData = false;
9229
+ var forwardSkuAsProductName = false;
9230
+
9231
+ var brazeConsentKeys = [
9232
+ '$google_ad_user_data',
9233
+ '$google_ad_personalization'
9234
+ ];
9235
+
9236
+ var latestUserBrazeConsentString;
9227
9237
 
9228
9238
  // A purchase event can either log a single event with all products
9229
9239
  // or multiple purchase events (one per product)
@@ -9282,6 +9292,8 @@ var constructor = function () {
9282
9292
  quantity,
9283
9293
  eventAttributes
9284
9294
  );
9295
+
9296
+ return reportEvent === true;
9285
9297
  }
9286
9298
 
9287
9299
  function logPurchaseEventPerProduct(event) {
@@ -9289,7 +9301,7 @@ var constructor = function () {
9289
9301
  event.ProductAction.ProductList.forEach(function(product) {
9290
9302
  var productName;
9291
9303
 
9292
- if (forwarderSettings.forwardSkuAsProductName === 'True') {
9304
+ if (forwardSkuAsProductName) {
9293
9305
  productName = product.Sku;
9294
9306
  } else {
9295
9307
  productName = product.Name;
@@ -9515,6 +9527,7 @@ var constructor = function () {
9515
9527
  /**************************/
9516
9528
  function processEvent(event) {
9517
9529
  var reportEvent = false;
9530
+ maybeSetConsentBeforeEventLogged(event);
9518
9531
 
9519
9532
  if (event.EventDataType == MessageType.Commerce) {
9520
9533
  reportEvent = logCommerceEvent(event);
@@ -9664,12 +9677,16 @@ var constructor = function () {
9664
9677
 
9665
9678
  function parseProduct(_product) {
9666
9679
  var product = {};
9667
-
9668
9680
  for (var key in _product) {
9669
9681
  switch (key) {
9670
9682
  case 'Sku':
9671
9683
  product.Id = _product[key];
9672
9684
  break;
9685
+ case 'Name':
9686
+ product.Name = forwardSkuAsProductName
9687
+ ? _product.Sku
9688
+ : _product.Name;
9689
+ break;
9673
9690
  case 'CouponCode':
9674
9691
  product['Coupon Code'] = _product[key];
9675
9692
  break;
@@ -9766,26 +9783,37 @@ var constructor = function () {
9766
9783
 
9767
9784
  // onUserIdentified is not used in version 1 so there is no need to check for version number
9768
9785
  function onUserIdentified(user) {
9769
- var brazeUserIDType,
9770
- userIdentities = user.getUserIdentities().userIdentities;
9786
+ kitLogger('calling MpBrazeKit.onUserIdentified');
9771
9787
 
9772
- if (forwarderSettings.userIdentificationType === 'MPID') {
9773
- brazeUserIDType = user.getMPID();
9774
- } else {
9775
- brazeUserIDType =
9776
- userIdentities[
9777
- forwarderSettings.userIdentificationType.toLowerCase()
9778
- ];
9779
- }
9788
+ try {
9789
+ var brazeUserIDType,
9790
+ userIdentities = user.getUserIdentities().userIdentities;
9780
9791
 
9781
- kitLogger('braze.changeUser', brazeUserIDType);
9792
+ if (forwarderSettings.userIdentificationType === 'MPID') {
9793
+ brazeUserIDType = user.getMPID();
9794
+ } else {
9795
+ brazeUserIDType =
9796
+ userIdentities[
9797
+ forwarderSettings.userIdentificationType.toLowerCase()
9798
+ ];
9799
+ }
9782
9800
 
9783
- braze.changeUser(brazeUserIDType);
9801
+ if (brazeUserIDType) {
9802
+ kitLogger('braze.changeUser', brazeUserIDType);
9803
+
9804
+ braze.changeUser(brazeUserIDType);
9805
+ }
9784
9806
 
9785
- if (userIdentities.email) {
9786
- kitLogger('braze.getUser().setEmail', userIdentities.email);
9807
+ if (userIdentities.email) {
9808
+ kitLogger('braze.getUser().setEmail', userIdentities.email);
9787
9809
 
9788
- braze.getUser().setEmail(userIdentities.email);
9810
+ braze.getUser().setEmail(userIdentities.email);
9811
+ }
9812
+ } catch (e) {
9813
+ kitLogger(
9814
+ 'Error in calling MpBrazeKit.onUserIdentified',
9815
+ e.message
9816
+ );
9789
9817
  }
9790
9818
  }
9791
9819
 
@@ -9845,6 +9873,110 @@ var constructor = function () {
9845
9873
  }
9846
9874
  }
9847
9875
 
9876
+ function prepareInitialConsent(user) {
9877
+ var userConsentState = getUserConsentState(user);
9878
+
9879
+ var currentConsentPayload = generateBrazeConsentStatePayload(
9880
+ userConsentState
9881
+ );
9882
+
9883
+ if (!isEmpty(currentConsentPayload)) {
9884
+ latestUserBrazeConsentString = JSON.stringify(
9885
+ currentConsentPayload
9886
+ );
9887
+
9888
+ setConsentOnBraze(currentConsentPayload);
9889
+ }
9890
+ }
9891
+
9892
+ function setConsentOnBraze(currentConsentPayload) {
9893
+ for (var key in currentConsentPayload) {
9894
+ braze
9895
+ .getUser()
9896
+ .setCustomUserAttribute(key, currentConsentPayload[key]);
9897
+ }
9898
+ }
9899
+
9900
+ function maybeSetConsentBeforeEventLogged(event) {
9901
+ if (latestUserBrazeConsentString && !isEmpty(parsedConsentMappings)) {
9902
+ var eventConsentState = getEventConsentState(event.ConsentState);
9903
+
9904
+ if (!isEmpty(eventConsentState)) {
9905
+ var eventBrazeConsent = generateBrazeConsentStatePayload(
9906
+ eventConsentState
9907
+ );
9908
+ var eventBrazeConsentAsString = JSON.stringify(
9909
+ eventBrazeConsent
9910
+ );
9911
+
9912
+ if (
9913
+ eventBrazeConsentAsString !== latestUserBrazeConsentString
9914
+ ) {
9915
+ setConsentOnBraze(eventBrazeConsent);
9916
+ latestUserBrazeConsentString = eventBrazeConsentAsString;
9917
+ }
9918
+ }
9919
+ }
9920
+ }
9921
+
9922
+ function getEventConsentState(eventConsentState) {
9923
+ return eventConsentState && eventConsentState.getGDPRConsentState
9924
+ ? eventConsentState.getGDPRConsentState()
9925
+ : {};
9926
+ }
9927
+
9928
+ function generateBrazeConsentStatePayload(consentState) {
9929
+ if (!parsedConsentMappings) return {};
9930
+
9931
+ var payload = {};
9932
+
9933
+ // These are Braze's consent constants for Braze's Audience Sync to Google
9934
+ // https://www.braze.com/docs/partners/canvas_steps/google_audience_sync
9935
+
9936
+ var googleToBrazeConsentMap = {
9937
+ google_ad_user_data: '$google_ad_user_data',
9938
+ google_ad_personalization: '$google_ad_personalization',
9939
+ };
9940
+
9941
+ for (var i = 0; i <= parsedConsentMappings.length - 1; i++) {
9942
+ var mappingEntry = parsedConsentMappings[i];
9943
+ // Although consent purposes can be inputted into the UI in any casing
9944
+ // the SDK will automatically lowercase them to prevent pseudo-duplicate
9945
+ // consent purposes, so we call `toLowerCase` on the consentMapping purposes here
9946
+ var mpMappedConsentName = mappingEntry.map.toLowerCase();
9947
+ // that mappingEntry.value returned from the server does not have a $ appended, so we have to add it
9948
+ var brazeMappedConsentName =
9949
+ googleToBrazeConsentMap[mappingEntry.value];
9950
+
9951
+ if (
9952
+ consentState[mpMappedConsentName] &&
9953
+ brazeMappedConsentName &&
9954
+ brazeConsentKeys.indexOf(brazeMappedConsentName) !== -1
9955
+ ) {
9956
+ payload[brazeMappedConsentName] =
9957
+ consentState[mpMappedConsentName].Consented;
9958
+ }
9959
+ }
9960
+
9961
+ return payload;
9962
+ }
9963
+
9964
+ function getUserConsentState(user) {
9965
+ var userConsentState = {};
9966
+
9967
+ var consentState = user.getConsentState();
9968
+
9969
+ if (consentState && consentState.getGDPRConsentState) {
9970
+ userConsentState = consentState.getGDPRConsentState();
9971
+ }
9972
+
9973
+ return userConsentState;
9974
+ }
9975
+
9976
+ function parseConsentSettingsString(consentMappingString) {
9977
+ return JSON.parse(consentMappingString.replace(/&quot;/g, '"'));
9978
+ }
9979
+
9848
9980
  function initForwarder(
9849
9981
  settings,
9850
9982
  service,
@@ -9869,6 +10001,8 @@ var constructor = function () {
9869
10001
  forwarderSettings = settings;
9870
10002
  bundleCommerceEventData =
9871
10003
  forwarderSettings.bundleCommerceEventData === 'True';
10004
+ forwardSkuAsProductName =
10005
+ forwarderSettings.forwardSkuAsProductName === 'True';
9872
10006
  reportingService = service;
9873
10007
  // 30 min is Braze default
9874
10008
  options.sessionTimeoutInSeconds =
@@ -9889,6 +10023,15 @@ var constructor = function () {
9889
10023
  forwarderSettings.serviceWorkerLocation;
9890
10024
  }
9891
10025
 
10026
+ if (forwarderSettings.consentMappingSDK) {
10027
+ parsedConsentMappings = parseConsentSettingsString(
10028
+ forwarderSettings.consentMappingSDK
10029
+ );
10030
+ if (parsedConsentMappings.length) {
10031
+ hasConsentMappings = true;
10032
+ }
10033
+ }
10034
+
9892
10035
  var cluster =
9893
10036
  forwarderSettings.cluster ||
9894
10037
  forwarderSettings.dataCenterLocation;
@@ -9930,10 +10073,19 @@ var constructor = function () {
9930
10073
  braze.addSdkMetadata(['mp']);
9931
10074
  primeBrazeWebPush();
9932
10075
 
9933
- if (forwarderSettings.userIdentificationType === 'MPID' && mParticle.Identity != null && mParticle.Identity.getCurrentUser().getMPID() != null) {
9934
- onUserIdentified(mParticle.Identity.getCurrentUser());
10076
+ const currentUser =
10077
+ mParticle.Identity !== null
10078
+ ? mParticle.Identity.getCurrentUser()
10079
+ : null;
10080
+ const mpid = currentUser ? currentUser.getMPID() : null;
10081
+
10082
+ if (currentUser && mpid) {
10083
+ onUserIdentified(currentUser);
10084
+ if (hasConsentMappings) {
10085
+ prepareInitialConsent(currentUser);
10086
+ }
9935
10087
  }
9936
-
10088
+
9937
10089
  openSession(forwarderSettings);
9938
10090
  }
9939
10091
 
@@ -10120,6 +10272,10 @@ function isObject(val) {
10120
10272
  );
10121
10273
  }
10122
10274
 
10275
+ function isEmpty(value) {
10276
+ return value == null || !(Object.keys(value) || value).length;
10277
+ }
10278
+
10123
10279
  var BrazeKitDev = {
10124
10280
  register: register,
10125
10281
  getVersion: function () {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mparticle/web-braze-kit",
3
- "version": "4.1.2",
3
+ "version": "4.2.0",
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",
@@ -12,7 +12,9 @@
12
12
  "scripts": {
13
13
  "build": "rollup --config rollup.config.js",
14
14
  "watch": "rollup --config rollup.config.js -w",
15
- "test": "node test/boilerplate/test-karma.js"
15
+ "test": "node test/boilerplate/test-karma.js",
16
+ "watch:tests": "ENVIRONMENT=production rollup --config rollup.test.config.js -w",
17
+ "test:debug": "npm run build && npm run build:test && DEBUG=true karma start test/karma.config.js"
16
18
  },
17
19
  "devDependencies": {
18
20
  "@rollup/plugin-commonjs": "22.0.1",