From cdc03d763af7549626c438eb1dee0fa77fd6d6da Mon Sep 17 00:00:00 2001 From: Jeriel Ng Date: Wed, 10 May 2023 09:54:08 -0400 Subject: [PATCH] Release Cordova SDK version 4.0.0 --- CHANGELOG.md | 25 ++ README.md | 6 +- package.json | 6 +- plugin.xml | 15 +- sample-project/config.xml | 36 +-- sample-project/package.json | 6 +- sample-project/www/css/index.css | 6 +- sample-project/www/index.html | 36 ++- sample-project/www/js/index.js | 318 ++++++++++++++---------- src/android/BrazePlugin.kt | 94 +++++-- src/android/build-extras.gradle | 3 +- src/ios/AppDelegate+Braze.m | 4 +- src/ios/BrazePlugin.h | 3 + src/ios/BrazePlugin.m | 104 ++++++-- www/{AppboyPlugin.js => BrazePlugin.js} | 256 +++++++++++-------- 15 files changed, 579 insertions(+), 339 deletions(-) rename www/{AppboyPlugin.js => BrazePlugin.js} (59%) diff --git a/CHANGELOG.md b/CHANGELOG.md index e3fbc7b..eaf372f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,28 @@ +## 4.0.0 + +##### Breaking +- Renamed instances of `Appboy` to `Braze`. + - To ensure that your project is properly migrated to the new naming conventions, note and replace the following instances in your project: + - The plugin has been renamed from `cordova-plugin-appboy` to `cordova-plugin-braze`. + - Ensure that you run `cordova plugin remove cordova-plugin-appboy` and then re-add the plugin using the instructions in the [README](./README.md). + - This GitHub repository has been moved to the URL `https://github.com/braze-inc/braze-cordova-sdk`. + - In your project's `config.xml` file, rename instances of `com.appboy` to `com.braze` for each of your configuration property keys. + - The JavaScript class interface `AppboyPlugin` has been renamed to `BrazePlugin`. +- Updated to [Braze Android SDK 25.0.0](https://github.com/braze-inc/braze-android-sdk/blob/master/CHANGELOG.md#2500). +- Updated to [Braze Swift SDK 5.13.0](https://github.com/braze-inc/braze-swift-sdk/releases/tag/5.13.0). + - This update fixes the iOS behavior introduced in version `2.33.0` when logging clicks for content cards. Calling `logContentCardClicked` now only sends a click event for metrics, instead of both sending a click event as well as redirecting to the associated `url` field. + - For instance, to log a content card click and redirect to a URL, you will need two commands: + ``` + BrazePlugin.logContentCardClicked(contentCardId); + + // Your own custom implementation + YourApp.openUrl(contentCard["url"]); + ``` + - This brings the iOS behavior to match pre-`2.33.0` versions and bring parity with Android's behavior. + +##### Added +- Added property methods for Feature Flags: `getFeatureFlagBooleanProperty(id, key)`, `getFeatureFlagStringProperty(id, key)`, `getFeatureFlagNumberProperty(id, key)` + ## 3.0.0 ##### Added diff --git a/README.md b/README.md index 8f5d42e..9bb1b7f 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ - + # Cordova SDK @@ -9,8 +9,8 @@ See our [Technical Documentation for Android](https://www.braze.com/docs/develop # Running the sample application ``` -cordova plugin remove cordova-plugin-appboy -cordova plugin add https://github.com/appboy/appboy-cordova-sdk#master +cordova plugin remove cordova-plugin-braze +cordova plugin add https://github.com/braze-inc/braze-cordova-sdk#master # To run android cordova run android diff --git a/package.json b/package.json index e5339a1..062d0aa 100644 --- a/package.json +++ b/package.json @@ -1,5 +1,5 @@ { - "name": "appboy-cordova-sdk", - "version": "3.0.0", - "main": "www/AppboyPlugin.js" + "name": "braze-cordova-sdk", + "version": "4.0.0", + "main": "www/BrazePlugin.js" } diff --git a/plugin.xml b/plugin.xml index af88866..41f4b70 100644 --- a/plugin.xml +++ b/plugin.xml @@ -1,18 +1,19 @@ + id="cordova-plugin-braze" version="4.0.0"> Device Braze Cordova SDK MIT cordova,appboy,braze - + + - + @@ -38,7 +39,7 @@ - + @@ -53,9 +54,9 @@ - - - + + + diff --git a/sample-project/config.xml b/sample-project/config.xml index db55161..f87e424 100755 --- a/sample-project/config.xml +++ b/sample-project/config.xml @@ -1,5 +1,5 @@ - - - - - - - - - - + + + + + + + + + - - - - - - - + + + + + + + - + diff --git a/sample-project/package.json b/sample-project/package.json index 5a41884..b7aad68 100644 --- a/sample-project/package.json +++ b/sample-project/package.json @@ -1,5 +1,5 @@ { - "name": "com.appboy.hellocordova", + "name": "com.braze.hellocordova", "version": "2.3.2", "displayName": "HelloCordova", "cordova": { @@ -8,7 +8,7 @@ "android" ], "plugins": { - "cordova-plugin-appboy": {} + "cordova-plugin-braze": {} } }, "dependencies": { @@ -22,7 +22,7 @@ "xcode": "^3.0.1" }, "devDependencies": { - "appboy-cordova-sdk": "file:../local", + "braze-cordova-sdk": "file:../local", "cordova-android": "^11.0.0", "cordova-ios": "^6.2.0" } diff --git a/sample-project/www/css/index.css b/sample-project/www/css/index.css index f041791..199e48e 100755 --- a/sample-project/www/css/index.css +++ b/sample-project/www/css/index.css @@ -128,7 +128,6 @@ h1 { #snackbar { visibility: hidden; /* Hidden by default. Visible on click */ min-width: 250px; /* Set a default minimum width */ - margin-left: -125px; /* Divide value of min-width by 2 */ background-color: #333; /* Black background color */ color: #fff; /* White text color */ text-align: center; /* Centered text */ @@ -136,8 +135,11 @@ h1 { padding: 16px; /* Padding */ position: fixed; /* Sit on top of the screen */ z-index: 1; /* Add a z-index if needed */ - left: 50%; /* Center the snackbar */ + left: 10%; /* Position the snackbar 10% from the left edge of the viewport */ + right: 10%; /* Position the snackbar 10% from the right edge of the viewport */ bottom: 30px; /* 30px from the bottom */ + max-width: calc(80%); /* Set a maximum width to keep the snackbar within the viewport */ + overflow-wrap: break-word; /* Prevent inner HTML from overflowing */ } /* Show the snackbar when clicking on a button (class added with JavaScript) */ diff --git a/sample-project/www/index.html b/sample-project/www/index.html index 8e7c860..6ecd119 100755 --- a/sample-project/www/index.html +++ b/sample-project/www/index.html @@ -39,44 +39,68 @@

Apache Cordova

+
+ - +
+ +
+ + + + +
- - +
+ + +
+
+
+ + + - - + +
+ + + +
diff --git a/sample-project/www/js/index.js b/sample-project/www/js/index.js index c11a656..aa1f39e 100755 --- a/sample-project/www/js/index.js +++ b/sample-project/www/js/index.js @@ -18,114 +18,148 @@ */ var app = { // Application Constructor -initialize: function() { - this.bindEvents(); -}, - // Bind Event Listeners - // - // Bind any events that are required on startup. Common events are: - // 'load', 'deviceready', 'offline', and 'online'. -bindEvents: function() { - document.addEventListener('deviceready', this.onDeviceReady, false); -}, - // deviceready Event Handler - // - // The scope of 'this' is the event. In order to call the 'receivedEvent' - // function, we must explicitly call 'app.receivedEvent(...);' -onDeviceReady: function() { - app.receivedEvent('deviceready'); - document.getElementById("getFeatureFlagBtn").addEventListener("click", getFeatureFlag); - document.getElementById("getAllFeatureFlagsBtn").addEventListener("click", getAllFeatureFlags); - document.getElementById("refreshFeatureFlagsBtn").addEventListener("click", refreshFeatureFlags); - document.getElementById("subscribeToFeatureFlagsBtn").addEventListener("click", subscribeToFeatureFlags) - document.getElementById("changeUserBtn").addEventListener("click", changeUser); - document.getElementById("logCustomEventBtn").addEventListener("click", logCustomEvent); - document.getElementById("logPurchaseBtn").addEventListener("click", logPurchase); - document.getElementById("setCustomUserAttributeBtn").addEventListener("click", setCustomUserAttribute); - document.getElementById("setUserPropertiesBtn").addEventListener("click", setUserProperties); - document.getElementById("launchNewsFeedBtn").addEventListener("click", launchNewsFeed); - document.getElementById("launchContentCardsBtn").addEventListener("click", launchContentCards); - document.getElementById("unsetCustomUserAttributeBtn").addEventListener("click", unsetCustomUserAttribute); - document.getElementById("setCustomUserAttributeArrayBtn").addEventListener("click", setCustomUserAttributeArray); - document.getElementById("incrementCustomUserAttributeBtn").addEventListener("click", incrementCustomUserAttribute); - document.getElementById("addToCustomUserAttributeArrayBtn").addEventListener("click", addToCustomUserAttributeArray); - document.getElementById("removeFromCustomUserAttributeArrayBtn").addEventListener("click", removeFromCustomUserAttributeArray); - document.getElementById("setAttributionDataBtn").addEventListener("click", setAttributionData); - document.getElementById("getNewsFeedUnreadCountBtn").addEventListener("click", getNewsFeedUnreadCount); - document.getElementById("getNewsFeedCardCountBtn").addEventListener("click", getNewsFeedCardCount); - document.getElementById("getCardCountForCategoriesBtn").addEventListener("click", getCardCountForCategories); - document.getElementById("getUnreadCardCountForCategoriesBtn").addEventListener("click", getUnreadCardCountForCategories); - document.getElementById("getAllNewsFeedCardsBtn").addEventListener("click", getAllNewsFeedCards); - document.getElementById("getAllContentCardsBtn").addEventListener("click", getContentCardsFromServer); - document.getElementById("logContentCardAnalyticsBtn").addEventListener("click", logContentCardAnalytics); - document.getElementById("addAliasBtn").addEventListener("click", addAlias); - document.getElementById("wipeData").addEventListener("click", wipeData); - document.getElementById("enableSdk").addEventListener("click", enableSdk); - document.getElementById("disableSdk").addEventListener("click", disableSdk); - document.getElementById("requestFlushBtn").addEventListener("click", requestDataFlush); - document.getElementById("setLanguageBtn").addEventListener("click", setLanguage); - document.getElementById("getDeviceId").addEventListener("click", getDeviceId); - document.getElementById("requestPushPermission").addEventListener("click", requestPushPermission); - - var success = function(message) { - alert(message); - } + initialize: function() { + this.bindEvents(); + }, + // Bind Event Listeners + // + // Bind any events that are required on startup. Common events are: + // 'load', 'deviceready', 'offline', and 'online'. + bindEvents: function() { + document.addEventListener('deviceready', this.onDeviceReady, false); + }, + // deviceready Event Handler + // + // The scope of 'this' is the event. In order to call the 'receivedEvent' + // function, we must explicitly call 'app.receivedEvent(...);' + onDeviceReady: function() { + app.receivedEvent('deviceready'); + document.getElementById("getFeatureFlagBtn").addEventListener("click", getFeatureFlag); + document.getElementById("getAllFeatureFlagsBtn").addEventListener("click", getAllFeatureFlags); + document.getElementById("refreshFeatureFlagsBtn").addEventListener("click", refreshFeatureFlags); + document.getElementById("subscribeToFeatureFlagsBtn").addEventListener("click", subscribeToFeatureFlags); + document.getElementById("getFeatureFlagPropertyBtn").addEventListener("click", getFeatureFlagProperty); + document.getElementById("changeUserBtn").addEventListener("click", changeUser); + document.getElementById("logCustomEventBtn").addEventListener("click", logCustomEvent); + document.getElementById("logPurchaseBtn").addEventListener("click", logPurchase); + document.getElementById("setCustomUserAttributeBtn").addEventListener("click", setCustomUserAttribute); + document.getElementById("setUserPropertiesBtn").addEventListener("click", setUserProperties); + document.getElementById("launchNewsFeedBtn").addEventListener("click", launchNewsFeed); + document.getElementById("launchContentCardsBtn").addEventListener("click", launchContentCards); + document.getElementById("unsetCustomUserAttributeBtn").addEventListener("click", unsetCustomUserAttribute); + document.getElementById("setCustomUserAttributeArrayBtn").addEventListener("click", setCustomUserAttributeArray); + document.getElementById("incrementCustomUserAttributeBtn").addEventListener("click", incrementCustomUserAttribute); + document.getElementById("addToCustomUserAttributeArrayBtn").addEventListener("click", addToCustomUserAttributeArray); + document.getElementById("removeFromCustomUserAttributeArrayBtn").addEventListener("click", removeFromCustomUserAttributeArray); + document.getElementById("setAttributionDataBtn").addEventListener("click", setAttributionData); + document.getElementById("getNewsFeedUnreadCountBtn").addEventListener("click", getNewsFeedUnreadCount); + document.getElementById("getNewsFeedCardCountBtn").addEventListener("click", getNewsFeedCardCount); + document.getElementById("getCardCountForCategoriesBtn").addEventListener("click", getCardCountForCategories); + document.getElementById("getUnreadCardCountForCategoriesBtn").addEventListener("click", getUnreadCardCountForCategories); + document.getElementById("getAllNewsFeedCardsBtn").addEventListener("click", getAllNewsFeedCards); + document.getElementById("getAllContentCardsBtn").addEventListener("click", getContentCardsFromServer); + document.getElementById("logContentCardAnalyticsBtn").addEventListener("click", logContentCardAnalytics); + document.getElementById("addAliasBtn").addEventListener("click", addAlias); + document.getElementById("wipeData").addEventListener("click", wipeData); + document.getElementById("enableSdk").addEventListener("click", enableSdk); + document.getElementById("disableSdk").addEventListener("click", disableSdk); + document.getElementById("requestFlushBtn").addEventListener("click", requestDataFlush); + document.getElementById("setLanguageBtn").addEventListener("click", setLanguage); + document.getElementById("getDeviceId").addEventListener("click", getDeviceId); + document.getElementById("requestPushPermission").addEventListener("click", requestPushPermission); + + var success = function(message) { + alert(message); + } - var failure = function() { - alert("Error calling Hello Plugin"); - } -}, - // Update DOM on a Received Event -receivedEvent: function(id) { - var parentElement = document.getElementById(id); - var listeningElement = parentElement.querySelector('.listening'); - var receivedElement = parentElement.querySelector('.received'); + var failure = function() { + alert("Error calling Hello Plugin"); + } + }, + // Update DOM on a Received Event + receivedEvent: function(id) { + var parentElement = document.getElementById(id); + var listeningElement = parentElement.querySelector('.listening'); + var receivedElement = parentElement.querySelector('.received'); - listeningElement.setAttribute('style', 'display:none;'); - receivedElement.setAttribute('style', 'display:block;'); + listeningElement.setAttribute('style', 'display:none;'); + receivedElement.setAttribute('style', 'display:block;'); - console.log('Received Event: ' + id); -} + console.log('Received Event: ' + id); + } }; app.initialize(); -// Appboy methods +// Braze methods function changeUser() { - AppboyPlugin.changeUser(document.getElementById("changeUserInputId").value); - showTextBubble("Change user called"); + const userId = document.getElementById("changeUserInputId").value; + BrazePlugin.changeUser(userId); + showTextBubble(`User changed to ${userId}`); } function getFeatureFlag() { - AppboyPlugin.getFeatureFlag(document.getElementById("featureFlagInputId").value, customPluginSuccessJsonCallback("FeatureFlag: "), customPluginErrorCallback); + BrazePlugin.getFeatureFlag(document.getElementById("featureFlagInputId").value, customPluginSuccessJsonCallback("FeatureFlag: "), customPluginErrorCallback); } function getAllFeatureFlags() { - AppboyPlugin.getAllFeatureFlags(customPluginSuccessArrayCallback("GetAllFeatureFlags: "), customPluginErrorCallback); + BrazePlugin.getAllFeatureFlags(customPluginSuccessArrayCallback("GetAllFeatureFlags: "), customPluginErrorCallback); } function refreshFeatureFlags() { - AppboyPlugin.refreshFeatureFlags(); + BrazePlugin.refreshFeatureFlags(); showTextBubble("Refresh feature flags"); } function subscribeToFeatureFlags() { - AppboyPlugin.subscribeToFeatureFlagUpdates(featureFlagsUpdated); + BrazePlugin.subscribeToFeatureFlagUpdates(featureFlagsUpdated); showTextBubble("Subscribed to Feature Flags"); } +function getFeatureFlagProperty() { + const featureFlagId = document.getElementById("featureFlagInputId").value; + const propertyKey = document.getElementById("featureFlagPropertyKey").value; + const propertyType = document.getElementById("featureFlagPropertyType").value; + if (!featureFlagId) { + showTextBubble("Feature Flag ID not entered."); + return; + } + if (!propertyKey) { + showTextBubble("Property key not entered."); + return; + } + switch (propertyType) { + case 'boolean': + BrazePlugin.getFeatureFlagBooleanProperty(featureFlagId, propertyKey, customPluginSuccessCallback("Got boolean property: "), customPluginErrorCallback); + break; + case 'number': + BrazePlugin.getFeatureFlagNumberProperty(featureFlagId, propertyKey, customPluginSuccessCallback("Got number property: "), customPluginErrorCallback); + break; + case 'string': + BrazePlugin.getFeatureFlagStringProperty(featureFlagId, propertyKey, customPluginSuccessCallback("Got string property: "), customPluginErrorCallback); + break; + default: + showTextBubble("No property type selected."); + } +} + function logCustomEvent() { + const customEventID = document.getElementById("logCustomEventId").value; + BrazePlugin.logCustomEvent(customEventID); + showTextBubble(`Logged custom event ${customEventID}`); + + /* TODO: Add properties input for custom events and purchases */ var properties = {}; properties["One"] = "That's the Way of the World"; properties["Two"] = "After the Love Has Gone"; properties["Three"] = "Can't Hide Love"; - AppboyPlugin.logCustomEvent("cordovaCustomEventWithProperties", properties); - AppboyPlugin.logCustomEvent("cordovaCustomEventWithoutProperties"); - AppboyPlugin.logCustomEvent("cordovaCustomEventWithFloatProperties", { + BrazePlugin.logCustomEvent("cordovaCustomEventWithProperties", properties); + BrazePlugin.logCustomEvent("cordovaCustomEventWithoutProperties"); + BrazePlugin.logCustomEvent("cordovaCustomEventWithFloatProperties", { "Cart Value": 4.95, "Cart Item Name": "Spicy Chicken Bites 5 pack" }); - AppboyPlugin.logCustomEvent("cordovaCustomEventWithNestedProperties", { + BrazePlugin.logCustomEvent("cordovaCustomEventWithNestedProperties", { "array key": [1, "2", false], "object key": { "k1": "1", @@ -136,20 +170,28 @@ function logCustomEvent() { "key": [1, "2", true] } }); - showTextBubble("Logged custom event"); } function logPurchase() { + const productID = document.getElementById("productId").value || null; + const purchaseAmount = document.getElementById("purchaseAmount").value || null; + const purchaseCurrency = document.getElementById("purchaseCurrency").value || null; + const purchaseQuantity = document.getElementById("purchaseQuantity").value || null; + + BrazePlugin.logPurchase(productID, purchaseAmount, purchaseCurrency, purchaseQuantity); + showTextBubble(`Logged purchase: ${productID}`); + + /* TODO: Add properties input for custom events and purchases */ var properties = {}; properties["One"] = "Apple"; properties["Two"] = "Orange"; properties["Three"] = "Peach"; - AppboyPlugin.logPurchase("testPurchase", 10, "USD", 5, properties); - AppboyPlugin.logPurchase("testPurchaseWithDecimal", 13.37, "USD", 5, properties); - AppboyPlugin.logPurchase("testPurchaseWithNullCurrency", 10, null, 5, properties); - AppboyPlugin.logPurchase("testPurchaseWithNullQuantity", 10, "USD"); - AppboyPlugin.logPurchase("testPurchaseWithoutProperties", 1500, "JPY", 2); - AppboyPlugin.logPurchase("testPurchaseWithNestedProperties", 10, "USD", 5, { + BrazePlugin.logPurchase("testPurchase", 10, "USD", 5, properties); + BrazePlugin.logPurchase("testPurchaseWithDecimal", 13.37, "USD", 5, properties); + BrazePlugin.logPurchase("testPurchaseWithNullCurrency", 10, null, 5, properties); + BrazePlugin.logPurchase("testPurchaseWithNullQuantity", 10, "USD"); + BrazePlugin.logPurchase("testPurchaseWithoutProperties", 1500, "JPY", 2); + BrazePlugin.logPurchase("testPurchaseWithNestedProperties", 10, "USD", 5, { "array key": [1, "2", false], "object key": { "k1": "1", @@ -160,152 +202,154 @@ function logPurchase() { "key": [1, "2", true] } }); - showTextBubble("Logged purchase"); } -// Appboy User methods +// Braze User methods function setCustomUserAttribute() { - AppboyPlugin.setCustomUserAttribute("cordovaCustomAttributeKey", "cordovaCustomAttributeValue"); - AppboyPlugin.incrementCustomUserAttribute("cordovaIncrementCustomAttributeKey", 1); + BrazePlugin.setCustomUserAttribute("cordovaCustomAttributeKey", "cordovaCustomAttributeValue"); + BrazePlugin.incrementCustomUserAttribute("cordovaIncrementCustomAttributeKey", 1); showTextBubble("Set Custom User Attribute"); } function setCustomUserAttributeArray() { - AppboyPlugin.setCustomUserAttribute("cordovaAttributeArrayButton", ["a", "b"]); + BrazePlugin.setCustomUserAttribute("cordovaAttributeArrayButton", ["a", "b"]); showTextBubble("Set Custom User Attribute Array"); } function incrementCustomUserAttribute() { - AppboyPlugin.incrementCustomUserAttribute("cordovaIncrementCustomAttributeKey", 2); + BrazePlugin.incrementCustomUserAttribute("cordovaIncrementCustomAttributeKey", 2); showTextBubble("Incremented Custom User Attribute"); } function addToCustomUserAttributeArray() { - AppboyPlugin.addToCustomUserAttributeArray("cordovaAttributeArrayButton", "c"); + BrazePlugin.addToCustomUserAttributeArray("cordovaAttributeArrayButton", "c"); showTextBubble("Added To Custom User Attribute Array"); } function removeFromCustomUserAttributeArray() { - AppboyPlugin.removeFromCustomUserAttributeArray("cordovaAttributeArrayButton", "b"); + BrazePlugin.removeFromCustomUserAttributeArray("cordovaAttributeArrayButton", "b"); showTextBubble("Removed From Custom User Attribute Array"); } function unsetCustomUserAttribute() { - AppboyPlugin.unsetCustomUserAttribute("double"); + BrazePlugin.unsetCustomUserAttribute("double"); showTextBubble("Unset Custom User Attribute"); } function setUserProperties() { - AppboyPlugin.setFirstName("firstName"); - AppboyPlugin.setLastName("lastName"); - AppboyPlugin.setEmail("email@test.com"); - AppboyPlugin.setGender(AppboyPlugin.Genders.FEMALE); - AppboyPlugin.setCountry("USA"); - AppboyPlugin.setHomeCity("New York"); - AppboyPlugin.setPhoneNumber("1234567890"); - AppboyPlugin.setDateOfBirth(1987, 9, 21); - AppboyPlugin.setPushNotificationSubscriptionType(AppboyPlugin.NotificationSubscriptionTypes.OPTED_IN); - AppboyPlugin.setEmailNotificationSubscriptionType(AppboyPlugin.NotificationSubscriptionTypes.OPTED_IN); - AppboyPlugin.setCustomUserAttribute("string", "stringValue"); - AppboyPlugin.setCustomUserAttribute("double", 1.2); - AppboyPlugin.setCustomUserAttribute("int", 5); - AppboyPlugin.setCustomUserAttribute("bool", true); - AppboyPlugin.setCustomUserAttribute("date", new Date()); - AppboyPlugin.addToSubscriptionGroup("12345"); + BrazePlugin.setFirstName("firstName"); + BrazePlugin.setLastName("lastName"); + BrazePlugin.setEmail("email@test.com"); + BrazePlugin.setGender(BrazePlugin.Genders.FEMALE); + BrazePlugin.setCountry("USA"); + BrazePlugin.setHomeCity("New York"); + BrazePlugin.setPhoneNumber("1234567890"); + BrazePlugin.setDateOfBirth(1987, 9, 21); + BrazePlugin.setPushNotificationSubscriptionType(BrazePlugin.NotificationSubscriptionTypes.OPTED_IN); + BrazePlugin.setEmailNotificationSubscriptionType(BrazePlugin.NotificationSubscriptionTypes.OPTED_IN); + BrazePlugin.setCustomUserAttribute("string", "stringValue"); + BrazePlugin.setCustomUserAttribute("double", 1.2); + BrazePlugin.setCustomUserAttribute("int", 5); + BrazePlugin.setCustomUserAttribute("bool", true); + BrazePlugin.setCustomUserAttribute("date", new Date()); + BrazePlugin.addToSubscriptionGroup("12345"); showTextBubble("Set User Properties"); } function setAttributionData() { - AppboyPlugin.setUserAttributionData("networkval", "campaignval", "adgroupval", "creativeval"); + BrazePlugin.setUserAttributionData("networkval", "campaignval", "adgroupval", "creativeval"); showTextBubble("Set Attribution Data"); } function wipeData() { - AppboyPlugin.wipeData(); + BrazePlugin.wipeData(); showTextBubble("Wiped SDK Data"); } function enableSdk() { - AppboyPlugin.enableSdk(); + BrazePlugin.enableSdk(); showTextBubble("Enabling the Braze SDK"); } function disableSdk() { - AppboyPlugin.disableSdk(); + BrazePlugin.disableSdk(); showTextBubble("Disabling the Braze SDK"); } function requestDataFlush() { - AppboyPlugin.requestImmediateDataFlush(); + BrazePlugin.requestImmediateDataFlush(); showTextBubble("Requesting data flush"); } // Launch functions function launchNewsFeed() { - AppboyPlugin.launchNewsFeed(); + BrazePlugin.launchNewsFeed(); } function launchContentCards() { - AppboyPlugin.launchContentCards(); + BrazePlugin.launchContentCards(); } // News feed functions function getNewsFeedUnreadCount() { - AppboyPlugin.getNewsFeedUnreadCount(customPluginSuccessCallback("get Unread News Feed Count is : "), customPluginErrorCallback); + BrazePlugin.getNewsFeedUnreadCount(customPluginSuccessCallback("get Unread News Feed Count is : "), customPluginErrorCallback); } function getNewsFeedCardCount() { - AppboyPlugin.getNewsFeedCardCount(customPluginSuccessCallback("get News Feed Card Count is : "), customPluginErrorCallback); + BrazePlugin.getNewsFeedCardCount(customPluginSuccessCallback("get News Feed Card Count is : "), customPluginErrorCallback); } function getCardCountForCategories() { - AppboyPlugin.getCardCountForCategories(customPluginSuccessCallback("get Card Count For Categories is : "), customPluginErrorCallback, - [AppboyPlugin.CardCategories.ADVERTISING, AppboyPlugin.CardCategories.SOCIAL]); + BrazePlugin.getCardCountForCategories(customPluginSuccessCallback("get Card Count For Categories is : "), customPluginErrorCallback, + [BrazePlugin.CardCategories.ADVERTISING, BrazePlugin.CardCategories.SOCIAL]); } function getUnreadCardCountForCategories() { - AppboyPlugin.getUnreadCardCountForCategories(customPluginSuccessCallback("get Unread Card Count For Categories is : "), customPluginErrorCallback, - [AppboyPlugin.CardCategories.NEWS, AppboyPlugin.CardCategories.ANNOUNCEMENTS]); + BrazePlugin.getUnreadCardCountForCategories(customPluginSuccessCallback("get Unread Card Count For Categories is : "), customPluginErrorCallback, + [BrazePlugin.CardCategories.NEWS, BrazePlugin.CardCategories.ANNOUNCEMENTS]); } function getAllNewsFeedCards() { - AppboyPlugin.getNewsFeed(customPluginSuccessArrayCallback("test"), customPluginErrorCallback); + BrazePlugin.getNewsFeed(customPluginSuccessArrayCallback("test"), customPluginErrorCallback); } function getContentCardsFromServer() { - AppboyPlugin.getContentCardsFromServer(customPluginSuccessArrayCallback("test"), customPluginErrorCallback); + BrazePlugin.getContentCardsFromServer(customPluginSuccessArrayCallback("test"), customPluginErrorCallback); } function logContentCardAnalytics() { // Log all the analytics methods for the first returned card - AppboyPlugin.getContentCardsFromServer(function(cards) { + BrazePlugin.getContentCardsFromServer(function(cards) { if (cards.length < 1) { return; } var firstCardId = cards[0]["id"]; - AppboyPlugin.logContentCardClicked(firstCardId); - AppboyPlugin.logContentCardImpression(firstCardId); - AppboyPlugin.logContentCardDismissed(firstCardId); + BrazePlugin.logContentCardClicked(firstCardId); + BrazePlugin.logContentCardImpression(firstCardId); + BrazePlugin.logContentCardDismissed(firstCardId); }); } function addAlias() { - AppboyPlugin.addAlias("foo123", "bar456"); - showTextBubble("Add alias called"); + const aliasName = document.getElementById("aliasName").value; + const aliasLabel = document.getElementById("aliasLabel").value; + BrazePlugin.addAlias(aliasName, aliasLabel); + showTextBubble(`Add alias name ${aliasName} with label ${aliasLabel}`); } function setLanguage() { - AppboyPlugin.setLanguage("fr"); - showTextBubble("Set Language called"); + const languageCode = document.getElementById("languageCode").value; + BrazePlugin.setLanguage(languageCode); + showTextBubble(`Language set to ${languageCode}`); } function getDeviceId() { - AppboyPlugin.getDeviceId(customPluginSuccessCallback("DeviceID: "), customPluginErrorCallback); + BrazePlugin.getDeviceId(customPluginSuccessCallback("Device ID: "), customPluginErrorCallback); } function requestPushPermission() { - AppboyPlugin.requestPushPermission(); + BrazePlugin.requestPushPermission(); showTextBubble("requestPushPermission() called"); } @@ -325,21 +369,21 @@ function showTextBubble(bubbleMessage) { } /** -* Serves as the success callback for the Appboy Plugin. Displays a text bubble with a message when called. +* Serves as the success callback for the Braze Plugin. Displays a text bubble with a message when called. **/ function customPluginSuccessCallback(bubbleMessage) { return function(callbackResult) { showTextBubble(bubbleMessage + " " + callbackResult) }; } /** -* Serves as the success callback for the Appboy Plugin. Displays a text bubble with a message when called. +* Serves as the success callback for the Braze Plugin. Displays a text bubble with a message when called. **/ function customPluginSuccessJsonCallback(bubbleMessage) { return function(callbackResult) { showTextBubble(bubbleMessage + " JSON: " + JSON.stringify(callbackResult)) }; } /** -* Serves as the success callback for the Appboy Plugin. Displays a text bubble with a message when called. +* Serves as the success callback for the Braze Plugin. Displays a text bubble with a message when called. **/ function customPluginSuccessArrayCallback(bubbleMessage) { return function(callbackResult) { @@ -360,7 +404,7 @@ function featureFlagsUpdated(featureFlags) { } /** -* Serves as the error callback for the Appboy Plugin. Displays a text bubble with a message when called. +* Serves as the error callback for the Braze Plugin. Displays a text bubble with a message when called. **/ function customPluginErrorCallback(callbackResult) { console.log(callbackResult); diff --git a/src/android/BrazePlugin.kt b/src/android/BrazePlugin.kt index 5298ba8..c5557f0 100644 --- a/src/android/BrazePlugin.kt +++ b/src/android/BrazePlugin.kt @@ -4,9 +4,6 @@ import android.content.Context import android.content.Intent import android.os.Build import android.util.Log -import com.braze.enums.* -import com.braze.events.FeedUpdatedEvent -import com.braze.models.outgoing.AttributionData import com.braze.Braze import com.braze.BrazeUser import com.braze.configuration.BrazeConfig @@ -14,10 +11,12 @@ import com.braze.cordova.ContentCardUtils.getCardById import com.braze.cordova.ContentCardUtils.mapContentCards import com.braze.cordova.CordovaInAppMessageViewWrapper.CordovaInAppMessageViewWrapperFactory import com.braze.cordova.FeatureFlagUtils.mapFeatureFlags -import com.braze.enums.BrazeSdkMetadata +import com.braze.enums.* import com.braze.events.ContentCardsUpdatedEvent -import com.braze.events.IEventSubscriber import com.braze.events.FeatureFlagsUpdatedEvent +import com.braze.events.FeedUpdatedEvent +import com.braze.events.IEventSubscriber +import com.braze.models.outgoing.AttributionData import com.braze.models.outgoing.BrazeProperties import com.braze.support.BrazeLogger.Priority.* import com.braze.support.BrazeLogger.brazelog @@ -29,7 +28,7 @@ import com.braze.ui.inappmessage.BrazeInAppMessageManager import org.apache.cordova.CallbackContext import org.apache.cordova.CordovaPlugin import org.apache.cordova.CordovaPreferences -import org.apache.cordova.PluginResult; +import org.apache.cordova.PluginResult import org.json.JSONArray import org.json.JSONException import org.json.JSONObject @@ -297,15 +296,54 @@ open class BrazePlugin : CordovaPlugin() { return true } "subscribeToFeatureFlagUpdates" -> { - runOnBraze { - it.subscribeToFeatureFlagsUpdates() { event: FeatureFlagsUpdatedEvent -> + runOnBraze { + it.subscribeToFeatureFlagsUpdates { event: FeatureFlagsUpdatedEvent -> val result = PluginResult(PluginResult.Status.OK, mapFeatureFlags(event.featureFlags)) - result.setKeepCallback(true) + result.keepCallback = true callbackContext.sendPluginResult(result) } } return true } + "getFeatureFlagBooleanProperty" -> { + runOnBraze { + val flagId = args.getString(0) + val propKey = args.getString(1) + val result = it.getFeatureFlag(flagId).getBooleanProperty(propKey) + if (result == null) { + callbackContext.sendCordovaSuccessPluginResultAsNull() + } else { + callbackContext.sendPluginResult(PluginResult(PluginResult.Status.OK, result)) + } + } + return true + } + "getFeatureFlagStringProperty" -> { + runOnBraze { + val flagId = args.getString(0) + val propKey = args.getString(1) + val result = it.getFeatureFlag(flagId).getStringProperty(propKey) + if (result == null) { + callbackContext.sendCordovaSuccessPluginResultAsNull() + } else { + callbackContext.sendPluginResult(PluginResult(PluginResult.Status.OK, result)) + } + } + return true + } + "getFeatureFlagNumberProperty" -> { + runOnBraze { + val flagId = args.getString(0) + val propKey = args.getString(1) + val result = it.getFeatureFlag(flagId).getNumberProperty(propKey) + if (result == null) { + callbackContext.sendCordovaSuccessPluginResultAsNull() + } else { + callbackContext.sendPluginResult(PluginResult(PluginResult.Status.OK, result.toFloat())) + } + } + return true + } GET_NEWS_FEED_METHOD, GET_CARD_COUNT_FOR_CATEGORIES_METHOD, GET_UNREAD_CARD_COUNT_FOR_CATEGORIES_METHOD -> return handleNewsFeedGetters(action, args, callbackContext) @@ -368,8 +406,8 @@ open class BrazePlugin : CordovaPlugin() { brazelog { "Setting Cordova preferences: ${cordovaPreferences.all}" } // Set the log level - if (cordovaPreferences.contains(APPBOY_LOG_LEVEL_PREFERENCE)) { - logLevel = cordovaPreferences.getInteger(APPBOY_LOG_LEVEL_PREFERENCE, Log.INFO) + if (cordovaPreferences.contains(BRAZE_LOG_LEVEL_PREFERENCE)) { + logLevel = cordovaPreferences.getInteger(BRAZE_LOG_LEVEL_PREFERENCE, Log.INFO) } // Disable auto starting sessions @@ -384,8 +422,8 @@ open class BrazePlugin : CordovaPlugin() { // Set the flavor configBuilder.setSdkFlavor(SdkFlavor.CORDOVA) .setSdkMetadata(EnumSet.of(BrazeSdkMetadata.CORDOVA)) - if (cordovaPreferences.contains(APPBOY_API_KEY_PREFERENCE)) { - configBuilder.setApiKey(cordovaPreferences.getString(APPBOY_API_KEY_PREFERENCE, null)) + if (cordovaPreferences.contains(BRAZE_API_KEY_PREFERENCE)) { + configBuilder.setApiKey(cordovaPreferences.getString(BRAZE_API_KEY_PREFERENCE, null)) } if (cordovaPreferences.contains(SMALL_NOTIFICATION_ICON_PREFERENCE)) { configBuilder.setSmallNotificationIcon(cordovaPreferences.getString(SMALL_NOTIFICATION_ICON_PREFERENCE, null)) @@ -559,19 +597,19 @@ open class BrazePlugin : CordovaPlugin() { companion object { // Preference keys found in the config.xml - private const val APPBOY_API_KEY_PREFERENCE = "com.appboy.api_key" - private const val AUTOMATIC_FIREBASE_PUSH_REGISTRATION_ENABLED_PREFERENCE = "com.appboy.firebase_cloud_messaging_registration_enabled" - private const val FCM_SENDER_ID_PREFERENCE = "com.appboy.android_fcm_sender_id" - private const val APPBOY_LOG_LEVEL_PREFERENCE = "com.appboy.android_log_level" - private const val SMALL_NOTIFICATION_ICON_PREFERENCE = "com.appboy.android_small_notification_icon" - private const val LARGE_NOTIFICATION_ICON_PREFERENCE = "com.appboy.android_large_notification_icon" - private const val DEFAULT_NOTIFICATION_ACCENT_COLOR_PREFERENCE = "com.appboy.android_notification_accent_color" - private const val DEFAULT_SESSION_TIMEOUT_PREFERENCE = "com.appboy.android_default_session_timeout" - private const val SET_HANDLE_PUSH_DEEP_LINKS_AUTOMATICALLY_PREFERENCE = "com.appboy.android_handle_push_deep_links_automatically" - private const val CUSTOM_API_ENDPOINT_PREFERENCE = "com.appboy.android_api_endpoint" - private const val ENABLE_LOCATION_PREFERENCE = "com.appboy.enable_location_collection" - private const val ENABLE_GEOFENCES_PREFERENCE = "com.appboy.geofences_enabled" - private const val DISABLE_AUTO_START_SESSIONS_PREFERENCE = "com.appboy.android_disable_auto_session_tracking" + private const val BRAZE_API_KEY_PREFERENCE = "com.braze.api_key" + private const val AUTOMATIC_FIREBASE_PUSH_REGISTRATION_ENABLED_PREFERENCE = "com.braze.firebase_cloud_messaging_registration_enabled" + private const val FCM_SENDER_ID_PREFERENCE = "com.braze.android_fcm_sender_id" + private const val BRAZE_LOG_LEVEL_PREFERENCE = "com.braze.android_log_level" + private const val SMALL_NOTIFICATION_ICON_PREFERENCE = "com.braze.android_small_notification_icon" + private const val LARGE_NOTIFICATION_ICON_PREFERENCE = "com.braze.android_large_notification_icon" + private const val DEFAULT_NOTIFICATION_ACCENT_COLOR_PREFERENCE = "com.braze.android_notification_accent_color" + private const val DEFAULT_SESSION_TIMEOUT_PREFERENCE = "com.braze.android_default_session_timeout" + private const val SET_HANDLE_PUSH_DEEP_LINKS_AUTOMATICALLY_PREFERENCE = "com.braze.android_handle_push_deep_links_automatically" + private const val CUSTOM_API_ENDPOINT_PREFERENCE = "com.braze.android_api_endpoint" + private const val ENABLE_LOCATION_PREFERENCE = "com.braze.enable_location_collection" + private const val ENABLE_GEOFENCES_PREFERENCE = "com.braze.geofences_enabled" + private const val DISABLE_AUTO_START_SESSIONS_PREFERENCE = "com.braze.android_disable_auto_session_tracking" /** * When applied, restricts the SDK from taking @@ -651,5 +689,9 @@ open class BrazePlugin : CordovaPlugin() { // Parse the string as an integer. return preferenceValue?.toInt() ?: -1 } + + private fun CallbackContext.sendCordovaSuccessPluginResultAsNull() { + this.sendPluginResult(PluginResult(PluginResult.Status.OK, null as String?)) + } } } diff --git a/src/android/build-extras.gradle b/src/android/build-extras.gradle index 81cdc61..03e9f7a 100644 --- a/src/android/build-extras.gradle +++ b/src/android/build-extras.gradle @@ -1,11 +1,10 @@ repositories { google() mavenCentral() - maven { url 'https://appboy.github.io/appboy-android-sdk/sdk' } } dependencies { - implementation 'com.braze:android-sdk-ui:24.2.0' + implementation 'com.braze:android-sdk-ui:25.0.0' implementation 'com.google.firebase:firebase-messaging:23.0.0' } diff --git a/src/ios/AppDelegate+Braze.m b/src/ios/AppDelegate+Braze.m index 03d422e..d7e7bf4 100644 --- a/src/ios/AppDelegate+Braze.m +++ b/src/ios/AppDelegate+Braze.m @@ -5,7 +5,7 @@ @import BrazeKit; @import UserNotifications; -static NSString *const PluginName = @"AppboyPlugin"; +static NSString *const PluginName = @"BrazePlugin"; @implementation AppDelegate (BrazeNotifications) + (void)swizzleHostAppDelegate { @@ -138,7 +138,7 @@ - (void)userNotificationCenter:(UNUserNotificationCenter *)center willPresentNotification:(UNNotification *)notification withCompletionHandler:(void (^)(UNNotificationPresentationOptions options))completionHandler { BrazePlugin *pluginInstance = [self.viewController getCommandInstance:PluginName]; - NSString *enableForegroundNotifications = pluginInstance.commandDelegate.settings[@"com.appboy.display_foreground_push_notifications"]; + NSString *enableForegroundNotifications = pluginInstance.commandDelegate.settings[@"com.braze.display_foreground_push_notifications"]; if ([enableForegroundNotifications isEqualToString:@"YES"]) { completionHandler(UNNotificationPresentationOptionAlert); } diff --git a/src/ios/BrazePlugin.h b/src/ios/BrazePlugin.h index aa76d59..203ad2f 100644 --- a/src/ios/BrazePlugin.h +++ b/src/ios/BrazePlugin.h @@ -66,5 +66,8 @@ - (void)getAllFeatureFlags:(CDVInvokedUrlCommand *)command; - (void)refreshFeatureFlags:(CDVInvokedUrlCommand *)command; - (void)subscribeToFeatureFlagUpdates:(CDVInvokedUrlCommand *)command; +- (void)getFeatureFlagBooleanProperty:(CDVInvokedUrlCommand *)command; +- (void)getFeatureFlagStringProperty:(CDVInvokedUrlCommand *)command; +- (void)getFeatureFlagNumberProperty:(CDVInvokedUrlCommand *)command; @end diff --git a/src/ios/BrazePlugin.m b/src/ios/BrazePlugin.m index daaa0d7..d1beafd 100644 --- a/src/ios/BrazePlugin.m +++ b/src/ios/BrazePlugin.m @@ -22,15 +22,15 @@ @implementation BrazePlugin - (void)pluginInitialize { NSDictionary *settings = self.commandDelegate.settings; - self.APIKey = settings[@"com.appboy.api_key"]; - self.disableAutomaticPushRegistration = settings[@"com.appboy.ios_disable_automatic_push_registration"]; - self.disableAutomaticPushHandling = settings[@"com.appboy.ios_disable_automatic_push_handling"]; - self.apiEndpoint = settings[@"com.appboy.ios_api_endpoint"]; - self.enableIDFACollection = settings[@"com.appboy.ios_enable_idfa_automatic_collection"]; - self.enableLocationCollection = settings[@"com.appboy.enable_location_collection"]; - self.enableGeofences = settings[@"com.appboy.geofences_enabled"]; - self.disableUNAuthorizationOptionProvisional = settings[@"com.appboy.ios_disable_un_authorization_option_provisional"]; - self.sessionTimeout = settings[@"com.appboy.ios_session_timeout"]; + self.APIKey = settings[@"com.braze.api_key"]; + self.disableAutomaticPushRegistration = settings[@"com.braze.ios_disable_automatic_push_registration"]; + self.disableAutomaticPushHandling = settings[@"com.braze.ios_disable_automatic_push_handling"]; + self.apiEndpoint = settings[@"com.braze.ios_api_endpoint"]; + self.enableIDFACollection = settings[@"com.braze.ios_enable_idfa_automatic_collection"]; + self.enableLocationCollection = settings[@"com.braze.enable_location_collection"]; + self.enableGeofences = settings[@"com.braze.geofences_enabled"]; + self.disableUNAuthorizationOptionProvisional = settings[@"com.braze.ios_disable_un_authorization_option_provisional"]; + self.sessionTimeout = settings[@"com.braze.ios_session_timeout"]; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(didFinishLaunchingListener:) name:UIApplicationDidFinishLaunchingNotification object:nil]; @@ -514,7 +514,7 @@ - (void)getContentCardsFromCache:(CDVInvokedUrlCommand *)command { NSMutableArray *mappedCards = [NSMutableArray arrayWithCapacity:[cards count]]; [cards enumerateObjectsUsingBlock:^(id card, NSUInteger idx, BOOL *stop) { - [mappedCards addObject:[BrazePlugin RCTFormatContentCard:card]]; + [mappedCards addObject:[BrazePlugin formattedContentCard:card]]; }]; [self sendCordovaSuccessPluginResultWithArray:mappedCards andCommand:command]; @@ -532,7 +532,7 @@ - (nullable BRZContentCardRaw *)getContentCardById:(NSString *)idString { return nil; } -+ (NSDictionary *)RCTFormatContentCard:(BRZContentCardRaw *)card { ++ (NSDictionary *)formattedContentCard:(BRZContentCardRaw *)card { NSMutableDictionary *formattedContentCardData = [NSMutableDictionary dictionary]; formattedContentCardData[@"id"] = card.identifier; @@ -597,7 +597,15 @@ - (void)getFeatureFlag:(CDVInvokedUrlCommand *)command { NSString *featureFlagId = [command argumentAtIndex:0 withDefault:nil]; BRZFeatureFlag *featureFlag = [self.braze.featureFlags featureFlagWithId:featureFlagId]; - [self sendCordovaSuccessPluginResultWithDictionary:[BrazePlugin formattedFeatureFlag:featureFlag] andCommand:command]; + NSError* error = nil; + id flagJSON = [NSJSONSerialization JSONObjectWithData:[featureFlag json] + options:NSJSONReadingMutableContainers + error:&error]; + if (error || flagJSON == nil) { + [self sendCordovaErrorPluginResultWithString:error.debugDescription andCommand:command]; + } else { + [self sendCordovaSuccessPluginResultWithDictionary:flagJSON andCommand:command]; + } } - (void)getAllFeatureFlags:(CDVInvokedUrlCommand *)command { @@ -626,19 +634,57 @@ - (void)subscribeToFeatureFlagUpdates:(CDVInvokedUrlCommand *)command { }]]; } -+ (NSDictionary *)formattedFeatureFlag:(BRZFeatureFlag *)featureFlag { - NSMutableDictionary *formattedFlag = [NSMutableDictionary dictionary]; - formattedFlag[@"id"] = featureFlag.identifier; - formattedFlag[@"enabled"] = @(featureFlag.enabled); - formattedFlag[@"properties"] = featureFlag.properties; - - return formattedFlag; +- (void)getFeatureFlagBooleanProperty:(CDVInvokedUrlCommand *)command { + NSString *featureFlagId = [command argumentAtIndex:0 withDefault:nil]; + NSString *propertyKey = [command argumentAtIndex:1 withDefault:nil]; + + BRZFeatureFlag *featureFlag = [self.braze.featureFlags featureFlagWithId:featureFlagId]; + NSNumber *boolProperty = [featureFlag boolPropertyForKey:propertyKey]; + if (boolProperty) { + [self sendCordovaSuccessPluginResultWithBool:boolProperty andCommand:command]; + } else { + [self sendCordovaSuccessPluginResultAsNull:command]; + } +} + +- (void)getFeatureFlagStringProperty:(CDVInvokedUrlCommand *)command { + NSString *featureFlagId = [command argumentAtIndex:0 withDefault:nil]; + NSString *propertyKey = [command argumentAtIndex:1 withDefault:nil]; + + BRZFeatureFlag *featureFlag = [self.braze.featureFlags featureFlagWithId:featureFlagId]; + NSString *stringProperty = [featureFlag stringPropertyForKey:propertyKey]; + if (stringProperty) { + [self sendCordovaSuccessPluginResultWithString:stringProperty andCommand:command]; + } else { + [self sendCordovaSuccessPluginResultAsNull:command]; + } +} + +- (void)getFeatureFlagNumberProperty:(CDVInvokedUrlCommand *)command { + NSString *featureFlagId = [command argumentAtIndex:0 withDefault:nil]; + NSString *propertyKey = [command argumentAtIndex:1 withDefault:nil]; + + BRZFeatureFlag *featureFlag = [self.braze.featureFlags featureFlagWithId:featureFlagId]; + NSNumber *numberProperty = [featureFlag numberPropertyForKey:propertyKey]; + if (numberProperty) { + [self sendCordovaSuccessPluginResultWithDouble:[numberProperty doubleValue] andCommand:command]; + } else { + [self sendCordovaSuccessPluginResultAsNull:command]; + } } + (NSArray *)formattedFeatureFlagsMap:(NSArray *)featureFlags { NSMutableArray *mappedFlags = [NSMutableArray array]; for (BRZFeatureFlag *flag in featureFlags) { - [mappedFlags addObject:[BrazePlugin formattedFeatureFlag:flag]]; + NSError* error = nil; + id flagJSON = [NSJSONSerialization JSONObjectWithData:[flag json] + options:NSJSONReadingMutableContainers + error:&error]; + if (!error) { + [mappedFlags addObject:flagJSON]; + } else { + NSLog(@"Failed to serialize Feature Flag with error: %@", error); + } } return mappedFlags; @@ -663,6 +709,18 @@ - (void)sendCordovaSuccessPluginResultWithInt:(NSUInteger)resultMessage andComma [self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId]; } +- (void)sendCordovaSuccessPluginResultWithDouble:(double)resultMessage andCommand:(CDVInvokedUrlCommand *)command { + CDVPluginResult *pluginResult = nil; + pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsDouble:resultMessage]; + [self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId]; +} + +- (void)sendCordovaSuccessPluginResultWithBool:(BOOL)resultMessage andCommand:(CDVInvokedUrlCommand *)command { + CDVPluginResult *pluginResult = nil; + pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsBool:resultMessage]; + [self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId]; +} + - (void)sendCordovaSuccessPluginResultWithArray:(NSArray *)resultMessage andCommand:(CDVInvokedUrlCommand *)command { CDVPluginResult *pluginResult = nil; pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsArray:resultMessage]; @@ -675,4 +733,10 @@ - (void)sendCordovaSuccessPluginResultWithDictionary:(NSDictionary *)resultMessa [self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId]; } +- (void)sendCordovaSuccessPluginResultAsNull:(CDVInvokedUrlCommand *)command { + CDVPluginResult *pluginResult = nil; + pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsString:(NSString *)[NSNull null]]; + [self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId]; +} + @end diff --git a/www/AppboyPlugin.js b/www/BrazePlugin.js similarity index 59% rename from www/AppboyPlugin.js rename to www/BrazePlugin.js index c3adceb..89275a9 100644 --- a/www/AppboyPlugin.js +++ b/www/BrazePlugin.js @@ -1,9 +1,9 @@ -var AppboyPlugin = function () { +var BrazePlugin = function () { } // Braze methods /** - * When a user first uses Appboy on a device they are considered "anonymous". Use this method to identify a user + * When a user first uses Braze on a device they are considered "anonymous". Use this method to identify a user * with a unique ID, which enables the following: * * - If the same user is identified on another device, their user profile, usage history and event history will @@ -16,7 +16,7 @@ var AppboyPlugin = function () { * existing user ID), the current session for the previous user (anonymous or not) is automatically ended and * a new session is started. Similarly, following a call to changeUser, any events which fire are guaranteed to * be for the new user -- if an in-flight server request completes for the old user after the user switch no - * events will fire, so you do not need to worry about filtering out events from Appboy for old users. + * events will fire, so you do not need to worry about filtering out events from Braze for old users. * * Additionally, if you identify a user which has never been identified on another device, the entire history of * that user as an "anonymous" user on this device will be preserved and associated with the newly identified @@ -35,8 +35,8 @@ var AppboyPlugin = function () { * * @param {string} userId - A unique identifier for this user. */ -AppboyPlugin.prototype.changeUser = function (userId) { - cordova.exec(null, null, "AppboyPlugin", "changeUser", [userId]); +BrazePlugin.prototype.changeUser = function (userId) { + cordova.exec(null, null, "BrazePlugin", "changeUser", [userId]); } /** @@ -46,8 +46,8 @@ AppboyPlugin.prototype.changeUser = function (userId) { * * @param {string} registrationId - The registration ID / push token. */ -AppboyPlugin.prototype.registerAppboyPushMessages = function (registrationID) { - cordova.exec(null, null, "AppboyPlugin", "registerAppboyPushMessages", [registrationID]); +BrazePlugin.prototype.registerAppboyPushMessages = function (registrationID) { + cordova.exec(null, null, "BrazePlugin", "registerAppboyPushMessages", [registrationID]); } /** @@ -57,8 +57,8 @@ AppboyPlugin.prototype.registerAppboyPushMessages = function (registrationID) { * * @param {string} pushToken - The registration ID / push token. */ -AppboyPlugin.prototype.setRegisteredPushToken = function (pushToken) { - cordova.exec(null, null, "AppboyPlugin", "setRegisteredPushToken", [pushToken]); +BrazePlugin.prototype.setRegisteredPushToken = function (pushToken) { + cordova.exec(null, null, "BrazePlugin", "setRegisteredPushToken", [pushToken]); } /** @@ -66,8 +66,8 @@ AppboyPlugin.prototype.setRegisteredPushToken = function (pushToken) { * * Requests the push permission prompt to be shown to the user. */ -AppboyPlugin.prototype.requestPushPermission = function () { - cordova.exec(null, null, "AppboyPlugin", "requestPushPermission"); +BrazePlugin.prototype.requestPushPermission = function () { + cordova.exec(null, null, "BrazePlugin", "requestPushPermission"); } /** @@ -80,8 +80,8 @@ AppboyPlugin.prototype.requestPushPermission = function () { * characters in length, cannot begin with a $, and can only contain alphanumeric characters and punctuation. * Values can be numeric, boolean, or strings 255 characters or shorter. */ -AppboyPlugin.prototype.logCustomEvent = function (eventName, eventProperties) { - cordova.exec(null, null, "AppboyPlugin", "logCustomEvent", [eventName, eventProperties]); +BrazePlugin.prototype.logCustomEvent = function (eventName, eventProperties) { + cordova.exec(null, null, "BrazePlugin", "logCustomEvent", [eventName, eventProperties]); } /** @@ -108,15 +108,15 @@ AppboyPlugin.prototype.logCustomEvent = function (eventName, eventProperties) { * characters in length, cannot begin with a $, and can only contain alphanumeric characters and punctuation. * Values can be numeric, boolean, or strings 255 characters or shorter. */ -AppboyPlugin.prototype.logPurchase = function (productId, price, currencyCode, quantity, purchaseProperties) { - cordova.exec(null, null, "AppboyPlugin", "logPurchase", [productId, price, currencyCode, quantity, purchaseProperties]); +BrazePlugin.prototype.logPurchase = function (productId, price, currencyCode, quantity, purchaseProperties) { + cordova.exec(null, null, "BrazePlugin", "logPurchase", [productId, price, currencyCode, quantity, purchaseProperties]); } /** * Sets the attribution information for the user. For in apps that have an install tracking integration. */ -AppboyPlugin.prototype.setUserAttributionData = function (network, campaign, adgroup, creative) { - cordova.exec(null, null, "AppboyPlugin", "setUserAttributionData", [network, campaign, adgroup, creative]); +BrazePlugin.prototype.setUserAttributionData = function (network, campaign, adgroup, creative) { + cordova.exec(null, null, "BrazePlugin", "setUserAttributionData", [network, campaign, adgroup, creative]); } /** @@ -128,21 +128,21 @@ AppboyPlugin.prototype.setUserAttributionData = function (network, campaign, adg * 255 characters in length, cannot begin with a $, and can only contain alphanumeric characters and punctuation. * Passing a null value will remove this custom attribute from the user. */ -AppboyPlugin.prototype.setCustomUserAttribute = function (key, value) { +BrazePlugin.prototype.setCustomUserAttribute = function (key, value) { var valueType = typeof(value); if (value instanceof Date) { - cordova.exec(null, null, "AppboyPlugin", "setDateCustomUserAttribute", [key, Math.floor(value.getTime() / 1000)]); + cordova.exec(null, null, "BrazePlugin", "setDateCustomUserAttribute", [key, Math.floor(value.getTime() / 1000)]); } else if (value instanceof Array) { - cordova.exec(null, null, "AppboyPlugin", "setCustomUserAttributeArray", [key, value]); + cordova.exec(null, null, "BrazePlugin", "setCustomUserAttributeArray", [key, value]); } else if (valueType === "boolean") { - cordova.exec(null, null, "AppboyPlugin", "setBoolCustomUserAttribute", [key, value]); + cordova.exec(null, null, "BrazePlugin", "setBoolCustomUserAttribute", [key, value]); } else if (valueType === "string") { - cordova.exec(null, null, "AppboyPlugin", "setStringCustomUserAttribute", [key, value]); + cordova.exec(null, null, "BrazePlugin", "setStringCustomUserAttribute", [key, value]); } else if (valueType === "number") { if (parseInt(value) === parseFloat(value)) { - cordova.exec(null, null, "AppboyPlugin", "setIntCustomUserAttribute", [key, value]); + cordova.exec(null, null, "BrazePlugin", "setIntCustomUserAttribute", [key, value]); } else { - cordova.exec(null, null, "AppboyPlugin", "setDoubleCustomUserAttribute", [key, value]); + cordova.exec(null, null, "BrazePlugin", "setDoubleCustomUserAttribute", [key, value]); } } } @@ -156,56 +156,56 @@ AppboyPlugin.prototype.setCustomUserAttribute = function (key, value) { * a $, and can only contain alphanumeric characters and punctuation. * @param {integer} - May be negative to decrement. */ -AppboyPlugin.prototype.incrementCustomUserAttribute = function (key, value) { - cordova.exec(null, null, "AppboyPlugin", "incrementCustomUserAttribute", [key, value]); +BrazePlugin.prototype.incrementCustomUserAttribute = function (key, value) { + cordova.exec(null, null, "BrazePlugin", "incrementCustomUserAttribute", [key, value]); } /** * Sets the first name of the user. * @param {string} firstName - Limited to 255 characters in length. */ -AppboyPlugin.prototype.setFirstName = function (firstName) { - cordova.exec(null, null, "AppboyPlugin", "setFirstName", [firstName]); +BrazePlugin.prototype.setFirstName = function (firstName) { + cordova.exec(null, null, "BrazePlugin", "setFirstName", [firstName]); } /** * Sets the last name of the user. * @param {string} lastName - Limited to 255 characters in length. */ -AppboyPlugin.prototype.setLastName = function (lastName) { - cordova.exec(null, null, "AppboyPlugin", "setLastName", [lastName]); +BrazePlugin.prototype.setLastName = function (lastName) { + cordova.exec(null, null, "BrazePlugin", "setLastName", [lastName]); } /** * Sets the email address of the user. * @param {string} email - Must pass RFC-5322 email address validation. */ -AppboyPlugin.prototype.setEmail = function (email) { - cordova.exec(null, null, "AppboyPlugin", "setEmail", [email]); +BrazePlugin.prototype.setEmail = function (email) { + cordova.exec(null, null, "BrazePlugin", "setEmail", [email]); } /** * Sets the gender of the user. * @param {ab.User.Genders} gender - Generally 'm' or 'f'. */ -AppboyPlugin.prototype.setGender = function (gender) { - cordova.exec(null, null, "AppboyPlugin", "setGender", [gender]); +BrazePlugin.prototype.setGender = function (gender) { + cordova.exec(null, null, "BrazePlugin", "setGender", [gender]); } /** * Sets the country for the user. * @param {string} country - Limited to 255 characters in length. */ -AppboyPlugin.prototype.setCountry = function (country) { - cordova.exec(null, null, "AppboyPlugin", "setCountry", [country]); +BrazePlugin.prototype.setCountry = function (country) { + cordova.exec(null, null, "BrazePlugin", "setCountry", [country]); } /** * Sets the home city for the user. * @param {string} homeCity - Limited to 255 characters in length. */ -AppboyPlugin.prototype.setHomeCity = function (homeCity) { - cordova.exec(null, null, "AppboyPlugin", "setHomeCity", [homeCity]); +BrazePlugin.prototype.setHomeCity = function (homeCity) { + cordova.exec(null, null, "BrazePlugin", "setHomeCity", [homeCity]); } /** @@ -213,8 +213,8 @@ AppboyPlugin.prototype.setHomeCity = function (homeCity) { * @param {string} phoneNumber - A phone number is considered valid if it is no more than 255 characters in length and * contains only numbers, whitespace, and the following special characters +.-() */ -AppboyPlugin.prototype.setPhoneNumber = function (phoneNumber) { - cordova.exec(null, null, "AppboyPlugin", "setPhoneNumber", [phoneNumber]); +BrazePlugin.prototype.setPhoneNumber = function (phoneNumber) { + cordova.exec(null, null, "BrazePlugin", "setPhoneNumber", [phoneNumber]); } /** @@ -223,8 +223,8 @@ AppboyPlugin.prototype.setPhoneNumber = function (phoneNumber) { * @param {integer} month - 1-12 * @param {integer} day */ -AppboyPlugin.prototype.setDateOfBirth = function (year, month, day) { - cordova.exec(null, null, "AppboyPlugin", "setDateOfBirth", [year, month, day]); +BrazePlugin.prototype.setDateOfBirth = function (year, month, day) { + cordova.exec(null, null, "BrazePlugin", "setDateOfBirth", [year, month, day]); } /** @@ -232,8 +232,8 @@ AppboyPlugin.prototype.setDateOfBirth = function (year, month, day) { * @param {NotificationSubscriptionTypes} notificationSubscriptionType - Notification setting (explicitly * opted-in, subscribed, or unsubscribed). */ -AppboyPlugin.prototype.setPushNotificationSubscriptionType = function (notificationSubscriptionType) { - cordova.exec(null, null, "AppboyPlugin", "setPushNotificationSubscriptionType", [notificationSubscriptionType]); +BrazePlugin.prototype.setPushNotificationSubscriptionType = function (notificationSubscriptionType) { + cordova.exec(null, null, "BrazePlugin", "setPushNotificationSubscriptionType", [notificationSubscriptionType]); } /** @@ -241,8 +241,8 @@ AppboyPlugin.prototype.setPushNotificationSubscriptionType = function (notificat * @param {NotificationSubscriptionTypes} notificationSubscriptionType - Notification setting (explicitly * opted-in, subscribed, or unsubscribed). */ -AppboyPlugin.prototype.setEmailNotificationSubscriptionType = function (notificationSubscriptionType) { - cordova.exec(null, null, "AppboyPlugin", "setEmailNotificationSubscriptionType", [notificationSubscriptionType]); +BrazePlugin.prototype.setEmailNotificationSubscriptionType = function (notificationSubscriptionType) { + cordova.exec(null, null, "BrazePlugin", "setEmailNotificationSubscriptionType", [notificationSubscriptionType]); } /** @@ -252,8 +252,8 @@ AppboyPlugin.prototype.setEmailNotificationSubscriptionType = function (notifica * @param {string} value - The string to be added to the array. Strings are limited to 255 characters in length, cannot * begin with a $, and can only contain alphanumeric characters and punctuation. */ -AppboyPlugin.prototype.addToCustomUserAttributeArray = function (key, value) { - cordova.exec(null, null, "AppboyPlugin", "addToCustomAttributeArray", [key, value]); +BrazePlugin.prototype.addToCustomUserAttributeArray = function (key, value) { + cordova.exec(null, null, "BrazePlugin", "addToCustomAttributeArray", [key, value]); } /** @@ -263,8 +263,8 @@ AppboyPlugin.prototype.addToCustomUserAttributeArray = function (key, value) { * @param {string} value - The string to be removed from the array. Strings are limited to 255 characters in length, * cannot beging with a $, and can only contain alphanumeric characters and punctuation. */ -AppboyPlugin.prototype.removeFromCustomUserAttributeArray = function (key, value) { - cordova.exec(null, null, "AppboyPlugin", "removeFromCustomAttributeArray", [key, value]); +BrazePlugin.prototype.removeFromCustomUserAttributeArray = function (key, value) { + cordova.exec(null, null, "BrazePlugin", "removeFromCustomAttributeArray", [key, value]); } /** @@ -272,8 +272,8 @@ AppboyPlugin.prototype.removeFromCustomUserAttributeArray = function (key, value * @param {string} key - The identifier of the custom attribute. Limited to 255 characters in length, cannot begin with * a $, and can only contain alphanumeric characters and punctuation. */ -AppboyPlugin.prototype.unsetCustomUserAttribute = function (key) { - cordova.exec(null, null, "AppboyPlugin", "unsetCustomUserAttribute", [key]); +BrazePlugin.prototype.unsetCustomUserAttribute = function (key) { + cordova.exec(null, null, "BrazePlugin", "unsetCustomUserAttribute", [key]); } /** @@ -281,23 +281,23 @@ AppboyPlugin.prototype.unsetCustomUserAttribute = function (key) { * @param {string} alias - An identifier for this user. * @param {string} label - A label for the alias. e.g. the source of the alias, like "internal_id" */ -AppboyPlugin.prototype.addAlias = function (alias, label) { - cordova.exec(null, null, "AppboyPlugin", "addAlias", [alias, label]); +BrazePlugin.prototype.addAlias = function (alias, label) { + cordova.exec(null, null, "BrazePlugin", "addAlias", [alias, label]); } // Other /** * Launches the News Feed UI element. */ -AppboyPlugin.prototype.launchNewsFeed = function () { - cordova.exec(null, null, "AppboyPlugin", "launchNewsFeed", []); +BrazePlugin.prototype.launchNewsFeed = function () { + cordova.exec(null, null, "BrazePlugin", "launchNewsFeed", []); } /** * Returns array of serialized card items */ -AppboyPlugin.prototype.getNewsFeed = function (successCallback, errorCallback) { - cordova.exec(successCallback, errorCallback, "AppboyPlugin", "getNewsFeed", ['all']); +BrazePlugin.prototype.getNewsFeed = function (successCallback, errorCallback) { + cordova.exec(successCallback, errorCallback, "BrazePlugin", "getNewsFeed", ['all']); } // News Feed methods @@ -305,135 +305,135 @@ AppboyPlugin.prototype.getNewsFeed = function (successCallback, errorCallback) { /** * Gets the number of unread News Feed Cards. The result is returned as an integer argument to the successCallback function. The card count uses the cards present in the cache. News Feed cards are not refreshed as a result of this call. */ -AppboyPlugin.prototype.getNewsFeedUnreadCount = function (successCallback, errorCallback) { - cordova.exec(successCallback, errorCallback, "AppboyPlugin", "getUnreadCardCountForCategories", ['all']); +BrazePlugin.prototype.getNewsFeedUnreadCount = function (successCallback, errorCallback) { + cordova.exec(successCallback, errorCallback, "BrazePlugin", "getUnreadCardCountForCategories", ['all']); } /** * Gets the number of News Feed Cards. The result is returned as an integer argument to the successCallback function. The card count uses the cards present in the cache. News Feed cards are not refreshed as a result of this call. **/ -AppboyPlugin.prototype.getNewsFeedCardCount = function (successCallback, errorCallback) { - cordova.exec(successCallback, errorCallback, "AppboyPlugin", "getCardCountForCategories", ['all']); +BrazePlugin.prototype.getNewsFeedCardCount = function (successCallback, errorCallback) { + cordova.exec(successCallback, errorCallback, "BrazePlugin", "getCardCountForCategories", ['all']); } /** * Gets the number of News Feed Cards for a category. The result is returned as an integer argument to the successCallback function. The card count uses the cards present in the cache. News Feed cards are not refreshed as a result of this call. **/ -AppboyPlugin.prototype.getCardCountForCategories = function (successCallback, errorCallback, cardCategories) { - cordova.exec(successCallback, errorCallback, "AppboyPlugin", "getCardCountForCategories", cardCategories); +BrazePlugin.prototype.getCardCountForCategories = function (successCallback, errorCallback, cardCategories) { + cordova.exec(successCallback, errorCallback, "BrazePlugin", "getCardCountForCategories", cardCategories); } /** * Gets the number of unread News Feed Cards for a category. The result is returned as an integer argument to the successCallback function. The card count uses the cards present in the cache. News Feed cards are not refreshed as a result of this call. */ -AppboyPlugin.prototype.getUnreadCardCountForCategories = function (successCallback, errorCallback, cardCategories) { - cordova.exec(successCallback, errorCallback, "AppboyPlugin", "getUnreadCardCountForCategories", cardCategories); +BrazePlugin.prototype.getUnreadCardCountForCategories = function (successCallback, errorCallback, cardCategories) { + cordova.exec(successCallback, errorCallback, "BrazePlugin", "getUnreadCardCountForCategories", cardCategories); } /** * Wipes Data on the Braze SDK. On iOS, the SDK will be disabled for the rest of the app run. */ -AppboyPlugin.prototype.wipeData = function () { - cordova.exec(null, null, "AppboyPlugin", "wipeData"); +BrazePlugin.prototype.wipeData = function () { + cordova.exec(null, null, "BrazePlugin", "wipeData"); } /** * Enables the Braze SDK after a previous call to disableSDK(). * On iOS, the SDK will be enabled only after a subsequent call to startWithApiKey(). */ -AppboyPlugin.prototype.enableSdk = function () { - cordova.exec(null, null, "AppboyPlugin", "enableSdk"); +BrazePlugin.prototype.enableSdk = function () { + cordova.exec(null, null, "BrazePlugin", "enableSdk"); } /** * Disables the Braze SDK immediately. */ -AppboyPlugin.prototype.disableSdk = function () { - cordova.exec(null, null, "AppboyPlugin", "disableSdk"); +BrazePlugin.prototype.disableSdk = function () { + cordova.exec(null, null, "BrazePlugin", "disableSdk"); } /** * Requests that the Braze SDK immediately flush any pending data. */ -AppboyPlugin.prototype.requestImmediateDataFlush = function () { - cordova.exec(null, null, "AppboyPlugin", "requestImmediateDataFlush"); +BrazePlugin.prototype.requestImmediateDataFlush = function () { + cordova.exec(null, null, "BrazePlugin", "requestImmediateDataFlush"); } /** * Requests the latest Content Cards from the Braze SDK server. */ -AppboyPlugin.prototype.requestContentCardsRefresh = function () { - cordova.exec(null, null, "AppboyPlugin", "requestContentCardsRefresh"); +BrazePlugin.prototype.requestContentCardsRefresh = function () { + cordova.exec(null, null, "BrazePlugin", "requestContentCardsRefresh"); } /** * Retrieves Content Cards from the Braze SDK. This will return the latest list of cards from the server. */ -AppboyPlugin.prototype.getContentCardsFromServer = function (successCallback, errorCallback) { - cordova.exec(successCallback, errorCallback, "AppboyPlugin", "getContentCardsFromServer"); +BrazePlugin.prototype.getContentCardsFromServer = function (successCallback, errorCallback) { + cordova.exec(successCallback, errorCallback, "BrazePlugin", "getContentCardsFromServer"); } /** * Retrieves Content Cards from the Braze SDK. This will return the latest list of cards from the cache. */ -AppboyPlugin.prototype.getContentCardsFromCache = function (successCallback, errorCallback) { - cordova.exec(successCallback, errorCallback, "AppboyPlugin", "getContentCardsFromCache"); +BrazePlugin.prototype.getContentCardsFromCache = function (successCallback, errorCallback) { + cordova.exec(successCallback, errorCallback, "BrazePlugin", "getContentCardsFromCache"); } /** * Launches a default Content Cards UI element. */ -AppboyPlugin.prototype.launchContentCards = function () { - cordova.exec(null, null, "AppboyPlugin", "launchContentCards"); +BrazePlugin.prototype.launchContentCards = function () { + cordova.exec(null, null, "BrazePlugin", "launchContentCards"); } /** * Logs a click for the given Content Card id. */ -AppboyPlugin.prototype.logContentCardClicked = function (cardId) { - cordova.exec(null, null, "AppboyPlugin", "logContentCardClicked", [cardId]); +BrazePlugin.prototype.logContentCardClicked = function (cardId) { + cordova.exec(null, null, "BrazePlugin", "logContentCardClicked", [cardId]); } /** * Logs an impression for the given Content Card id. */ -AppboyPlugin.prototype.logContentCardImpression = function (cardId) { - cordova.exec(null, null, "AppboyPlugin", "logContentCardImpression", [cardId]); +BrazePlugin.prototype.logContentCardImpression = function (cardId) { + cordova.exec(null, null, "BrazePlugin", "logContentCardImpression", [cardId]); } /** * Logs a dismissal for the given Content Card id. */ -AppboyPlugin.prototype.logContentCardDismissed = function (cardId) { - cordova.exec(null, null, "AppboyPlugin", "logContentCardDismissed", [cardId]); +BrazePlugin.prototype.logContentCardDismissed = function (cardId) { + cordova.exec(null, null, "BrazePlugin", "logContentCardDismissed", [cardId]); } /** * Sets the language for a user. Language Strings should be valid ISO 639-1 language codes. See loc.gov/standards/iso639-2/php/code_list.php. */ -AppboyPlugin.prototype.setLanguage = function (language) { - cordova.exec(null, null, "AppboyPlugin", "setLanguage", [language]); +BrazePlugin.prototype.setLanguage = function (language) { + cordova.exec(null, null, "BrazePlugin", "setLanguage", [language]); } /** * Adds user to given subscription group. */ -AppboyPlugin.prototype.addToSubscriptionGroup = function (groupId) { - cordova.exec(null, null, "AppboyPlugin", "addToSubscriptionGroup", [groupId]); +BrazePlugin.prototype.addToSubscriptionGroup = function (groupId) { + cordova.exec(null, null, "BrazePlugin", "addToSubscriptionGroup", [groupId]); } /** * Removes user from given subscription group. */ -AppboyPlugin.prototype.removeFromSubscriptionGroup = function (groupId) { - cordova.exec(null, null, "AppboyPlugin", "removeFromSubscriptionGroup", [groupId]); +BrazePlugin.prototype.removeFromSubscriptionGroup = function (groupId) { + cordova.exec(null, null, "BrazePlugin", "removeFromSubscriptionGroup", [groupId]); } /** * @return An app specific ID that is stored on the device. */ -AppboyPlugin.prototype.getDeviceId = function (successCallback, errorCallback) { - cordova.exec(successCallback, errorCallback, "AppboyPlugin", "getDeviceId"); +BrazePlugin.prototype.getDeviceId = function (successCallback, errorCallback) { + cordova.exec(successCallback, errorCallback, "BrazePlugin", "getDeviceId"); } /** @@ -444,8 +444,8 @@ AppboyPlugin.prototype.getDeviceId = function (successCallback, errorCallback) { * @return [FeatureFlag] of the requested ID. If the Feature Flag does not exist, a [FeatureFlag] * will be returned with enabled set to `false` and empty properties. */ -AppboyPlugin.prototype.getFeatureFlag = function (id, successCallback, errorCallback) { - cordova.exec(successCallback, errorCallback, "AppboyPlugin", "getFeatureFlag", [id]); +BrazePlugin.prototype.getFeatureFlag = function (id, successCallback, errorCallback) { + cordova.exec(successCallback, errorCallback, "BrazePlugin", "getFeatureFlag", [id]); } /** @@ -455,38 +455,71 @@ AppboyPlugin.prototype.getFeatureFlag = function (id, successCallback, errorCall * fresh list of Feature Flags from Braze. If the SDK is disabled or the * cached list of feature flags cannot be retrieved, returns empty list. */ -AppboyPlugin.prototype.getAllFeatureFlags = function (successCallback, errorCallback) { - cordova.exec(successCallback, errorCallback, "AppboyPlugin", "getAllFeatureFlags"); +BrazePlugin.prototype.getAllFeatureFlags = function (successCallback, errorCallback) { + cordova.exec(successCallback, errorCallback, "BrazePlugin", "getAllFeatureFlags"); } /** * Requests a refresh of Feature Flags from the Braze server. */ -AppboyPlugin.prototype.refreshFeatureFlags = function (successCallback, errorCallback) { - cordova.exec(successCallback, errorCallback, "AppboyPlugin", "refreshFeatureFlags"); +BrazePlugin.prototype.refreshFeatureFlags = function (successCallback, errorCallback) { + cordova.exec(successCallback, errorCallback, "BrazePlugin", "refreshFeatureFlags"); } /** * Subscribes to Feature Flags events. The subscriber callback will be called when Feature Flags are updated. */ -AppboyPlugin.prototype.subscribeToFeatureFlagUpdates = function (successCallback) { - cordova.exec(successCallback, null, "AppboyPlugin", "subscribeToFeatureFlagUpdates"); +BrazePlugin.prototype.subscribeToFeatureFlagUpdates = function (flagId, propertyKey, successCallback, errorCallback) { + cordova.exec(successCallback, errorCallback, "BrazePlugin", "subscribeToFeatureFlagUpdates", [flagId, propertyKey]); +} + +/** + * Requests a boolean property for a given Feature Flag ID and a property key. + * @param {string} flagId - The identifier for the Feature Flag. + * @param {string} propertyKey - The key for the boolean property. + * + * @return The boolean property requested. This should return null if there is no such property. + */ +BrazePlugin.prototype.getFeatureFlagBooleanProperty = function (flagId, propertyKey, successCallback, errorCallback) { + cordova.exec(successCallback, errorCallback, "BrazePlugin", "getFeatureFlagBooleanProperty", [flagId, propertyKey]); +} + +/** + * Requests a string property for a given Feature Flag ID and a property key. + * @param {string} flagId - The identifier for the Feature Flag. + * @param {string} propertyKey - The key for the string property. + * + * @return The string property requested. This should return null if there is no such property. + */ +BrazePlugin.prototype.getFeatureFlagStringProperty = function (flagId, propertyKey, successCallback, errorCallback) { + cordova.exec(successCallback, errorCallback, "BrazePlugin", "getFeatureFlagStringProperty", [flagId, propertyKey]); +} + +/** + * Requests a number property for a given Feature Flag ID and a property key. + * @param {string} flagId - The identifier for the Feature Flag. + * @param {string} propertyKey - The key for the number property. + * + * @return The number property requested. This should return null if there is no such property. + */ +BrazePlugin.prototype.getFeatureFlagNumberProperty = function (flagId, propertyKey, successCallback, errorCallback) { + cordova.exec(successCallback, errorCallback, "BrazePlugin", "getFeatureFlagNumberProperty", [flagId, propertyKey]); } /** * @return Starts SDK session tracking if previously disabled. Only used for Android. */ -AppboyPlugin.prototype.startSessionTracking = function () { - cordova.exec(null, null, "AppboyPlugin", "startSessionTracking"); +BrazePlugin.prototype.startSessionTracking = function () { + cordova.exec(null, null, "BrazePlugin", "startSessionTracking"); } -AppboyPlugin.prototype['NotificationSubscriptionTypes'] = { +BrazePlugin.prototype['NotificationSubscriptionTypes'] = { "OPTED_IN": 'opted_in', "SUBSCRIBED": 'subscribed', "UNSUBSCRIBED": 'unsubscribed' }; -AppboyPlugin.prototype['Genders'] = { +BrazePlugin.prototype['Genders'] = { "FEMALE": 'f', "MALE": 'm', "NOT_APPLICABLE": 'n', @@ -495,7 +528,7 @@ AppboyPlugin.prototype['Genders'] = { "UNKNOWN": 'u' }; -AppboyPlugin.prototype['CardCategories'] = { +BrazePlugin.prototype['CardCategories'] = { "ADVERTISING": 'advertising', "ANNOUNCEMENTS": 'announcements', "NEWS": 'news', @@ -504,10 +537,13 @@ AppboyPlugin.prototype['CardCategories'] = { "ALL" : 'all' }; -AppboyPlugin.prototype['ContentCardTypes'] = { +BrazePlugin.prototype['ContentCardTypes'] = { 'CLASSIC': 'Classic', 'BANNER': 'Banner', 'CAPTIONED': 'Captioned' }; +var AppboyPlugin = BrazePlugin; + +module.exports = new BrazePlugin(); module.exports = new AppboyPlugin();