Skip to content

Commit

Permalink
Release Cordova SDK version 9.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
hokstuff committed May 1, 2024
1 parent 75db370 commit 71710c2
Show file tree
Hide file tree
Showing 11 changed files with 752 additions and 144 deletions.
23 changes: 23 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,28 @@
⚠️ In version 2.33.0, we changed the iOS bridge from AppboyKit, which is written in Objective-C, to the new [Swift SDK](https://github.com/braze-inc/braze-swift-sdk). If you are upgrading from a version below 2.33.0 to a version above 2.33.0, please read [the instructions](https://github.com/braze-inc/braze-cordova-sdk/blob/master/CHANGELOG.md#2330) to ensure a smooth transition and backward compatibility.

## 9.0.0

##### Breaking
- Updated the native iOS bridge [from Braze Swift SDK 7.7.0 to 9.0.0](https://github.com/braze-inc/braze-swift-sdk/compare/7.7.0...9.0.0#diff-06572a96a58dc510037d5efa622f9bec8519bc1beab13c9f251e97e657a9d4ed).

##### Added
- Added support to modify the allow list for Braze tracking properties via the following JavaScript properties and methods:
- `TrackingProperty` string enum
- `TrackingPropertyAllowList` object interface
- `updateTrackingPropertyAllowList` method
- For details, refer to the [Braze iOS Privacy Manifest](https://www.braze.com/docs/developer_guide/platform_integration_guides/swift/privacy_manifest/) documentation.
- Added the `setAdTrackingEnabled` method to set `adTrackingEnabled` flag on iOS and both the `adTrackingEnabled` flag and the Google Advertising ID on Android.
- Added `BrazePlugin.subscribeToInAppMessage()` which allows you to listen for new in-app messages from the JavaScript plugin and choose whether or not to use the default Braze UI to display in-app messages.
- Added support for logging analytics and functionality for in-app messages.
- `BrazePlugin.logInAppMessageImpression(message)`
- `BrazePlugin.logInAppMessageClicked(message)`
- `BrazePlugin.loginAppMessageButtonClicked(message, buttonId)`
- `BrazePlugin.hideCurrentInAppMessage()`
- Added support for manually performing the action of an in-app message when using a custom UI.
- `BrazePlugin.performInAppMessageAction(message)`
- `BrazePlugin.performInAppMessageButtonAction(message, buttonId)`
- Updated the native Android bridge [from Braze Android SDK 30.1.1 to 30.3.0](https://github.com/braze-inc/braze-android-sdk/compare/v30.1.1...v30.3.0#diff-06572a96a58dc510037d5efa622f9bec8519bc1beab13c9f251e97e657a9d4ed).

## 8.1.0

##### Added
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "braze-cordova-sdk",
"version": "8.1.0",
"version": "9.0.0",
"main": "www/BrazePlugin.js"
}
}
8 changes: 4 additions & 4 deletions plugin.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<plugin xmlns="http://apache.org/cordova/ns/plugins/1.0"
id="cordova-plugin-braze" version="8.1.0">
id="cordova-plugin-braze" version="9.0.0">
<name>Braze</name>
<description>Braze Cordova SDK</description>
<license>MIT</license>
Expand Down Expand Up @@ -54,9 +54,9 @@
<source url="https://cdn.cocoapods.org/"/>
</config>
<pods use-frameworks="true">
<pod name="BrazeKit" spec="~> 7.7.0" />
<pod name="BrazeUI" spec="~> 7.7.0" />
<pod name="BrazeLocation" spec="~> 7.7.0" />
<pod name="BrazeKit" spec="~> 9.0.0" />
<pod name="BrazeUI" spec="~> 9.0.0" />
<pod name="BrazeLocation" spec="~> 9.0.0" />
</pods>
</podspec>
</platform>
Expand Down
7 changes: 3 additions & 4 deletions sample-project/config.xml
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@
<preference name="com.braze.geofences_enabled" value="false" />
<preference name="com.braze.android_disable_auto_session_tracking" value ="false" />
<preference name="com.braze.sdk_authentication_enabled" value="true" />
<preference name="com.braze.trigger_action_minimum_time_interval_seconds" value="30" />
<preference name="com.braze.is_session_start_based_timeout_enabled" value="false" />
<preference name="com.braze.default_notification_channel_name" value="Braze Push" />
<preference name="com.braze.default_notification_channel_description" value="Braze related push" />
Expand All @@ -56,7 +55,7 @@
<preference name="com.braze.is_push_deep_link_back_stack_activity_enabled" value="true" />
<preference name="com.braze.push_deep_link_back_stack_activity_class_name" value="java.lang.BackStackActivityClass" />
<preference name="com.braze.should_opt_in_when_push_authorized" value="true" />
<preference name="com.braze.trigger_action_minimum_time_interval_seconds" value="str_30" />
<preference name="com.braze.trigger_action_minimum_time_interval_seconds" value="str_1" />

<edit-config
file="app/src/main/AndroidManifest.xml"
Expand All @@ -78,9 +77,9 @@
<preference name="com.braze.ios_session_timeout" value="5" />
<preference name="com.braze.sdk_authentication_enabled" value="YES" />
<preference name="com.braze.display_foreground_push_notifications" value="YES" />
<preference name="deployment-target" value="11.0" />
<preference name="deployment-target" value="12.0" />
<preference name="com.braze.ios_disable_un_authorization_option_provisional" value="NO" />
<preference name="com.braze.trigger_action_minimum_time_interval_seconds" value="30" />
<preference name="com.braze.trigger_action_minimum_time_interval_seconds" value="1" />
<preference name="com.braze.ios_push_app_group" value="group.com.braze.hellocordova.PushStories" />
<preference name="com.braze.ios_forward_universal_links" value="YES" />
<preference name="com.braze.ios_log_level" value="2" />
Expand Down
5 changes: 5 additions & 0 deletions sample-project/www/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,9 @@ <h1>Apache Cordova</h1>
<button id="getAllContentCardsBtn">Log all Content Cards</button>
<button id="logContentCardAnalyticsBtn">Log Content Cards Analytics for first Card</button>
<br>
<button id="subscribeToInAppMessageBtn">Subscribe to In-App Messages</button>
<button id="hideCurrentInAppMessageBtn">Hide Current In-App Message</button>
<br>
<input type="text" id="aliasName" autocorrect="off" autocapitalize="off" placeholder="Alias Name" />
<input type="text" id="aliasLabel" autocorrect="off" autocapitalize="off" placeholder="Alias Label" />
<button id="addAliasBtn">Add Alias</button>
Expand All @@ -99,6 +102,8 @@ <h1>Apache Cordova</h1>
<button id="disableSdk">Disables the SDK</button>
<button id="getDeviceId">Gets the Device ID</button>
<button id="requestPushPermission">Request Push Permission (Android Only)</button>
<button id="updateTrackingPropertiesBtn">Update Tracking Properties (iOS Only)</button>
<button id="enableAdTrackingBtn">Enable Ad Tracking</button>
<br>
<input type="text" id="featureFlagInputId" autocorrect="off" autocapitalize="off" placeholder="Feature Flag ID" />
<button id="getFeatureFlagBtn">Get Feature Flag</button>
Expand Down
45 changes: 45 additions & 0 deletions sample-project/www/js/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,10 @@ var app = {
document.getElementById("setLastKnownLocationBtn").addEventListener("click", setLastKnownLocation);
document.getElementById("getDeviceId").addEventListener("click", getDeviceId);
document.getElementById("requestPushPermission").addEventListener("click", requestPushPermission);
document.getElementById("updateTrackingPropertiesBtn").addEventListener("click", updateTrackingProperties);
document.getElementById("enableAdTrackingBtn").addEventListener("click", enableAdTracking);
document.getElementById("subscribeToInAppMessageBtn").addEventListener("click", subscribeToInAppMessage);
document.getElementById("hideCurrentInAppMessageBtn").addEventListener("click", hideCurrentInAppMessage);
BrazePlugin.subscribeToSdkAuthenticationFailures(customPluginSuccessCallback(), customPluginErrorCallback);
},
// Update DOM on a Received Event
Expand All @@ -84,6 +88,15 @@ var app = {
receivedElement.setAttribute('style', 'display:block;');

console.log('Received Event: ' + id);
},
// In-App Message Received Event
inAppMessageReceived: function(message) {
console.log('Received in-app message and logging analytics: ' + message);

// Log In-App Message Events
BrazePlugin.logInAppMessageClicked(message);
BrazePlugin.logInAppMessageImpression(message);
BrazePlugin.logInAppMessageButtonClicked(message, 0);
}
};

Expand Down Expand Up @@ -418,6 +431,15 @@ function logContentCardAnalytics() {
});
}

function subscribeToInAppMessage() {
BrazePlugin.subscribeToInAppMessage(true);
showTextBubble("Subscribed to In-App Messages");
}

function hideCurrentInAppMessage() {
BrazePlugin.hideCurrentInAppMessage();
}

function addAlias() {
const aliasName = document.getElementById("aliasName").value;
const aliasLabel = document.getElementById("aliasLabel").value;
Expand Down Expand Up @@ -452,6 +474,29 @@ function requestPushPermission() {
showTextBubble("requestPushPermission() called");
}

async function updateTrackingProperties() {
const allowList = {
adding: [
BrazePlugin.TrackingProperty.FIRST_NAME,
BrazePlugin.TrackingProperty.LAST_NAME,
],
removing: [BrazePlugin.TrackingProperty.DEVICE_DATA],
addingCustomEvents: ['custom-event1', 'custom-event2'],
removingCustomAttributes: ['attr-1']
};
BrazePlugin.updateTrackingPropertyAllowList(allowList);
console.log(
`Update tracking allow list with: ${JSON.stringify(allowList)}`,
);
showTextBubble(`Updated tracking allow list: ${JSON.stringify(allowList)}`);
}

function enableAdTracking() {
const testAdvertisingID = '123';
BrazePlugin.setAdTrackingEnabled(true, testAdvertisingID);
showTextBubble(`Ad tracking enabled with ID: ${testAdvertisingID}`);
}

// Other helper functions
function showTextBubble(bubbleMessage) {
// Get the snackbar DIV
Expand Down
147 changes: 146 additions & 1 deletion src/android/BrazePlugin.kt
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,30 @@ import com.braze.cordova.ContentCardUtils.mapContentCards
import com.braze.cordova.CordovaInAppMessageViewWrapper.CordovaInAppMessageViewWrapperFactory
import com.braze.cordova.FeatureFlagUtils.mapFeatureFlags
import com.braze.enums.*
import com.braze.enums.inappmessage.ClickAction
import com.braze.events.ContentCardsUpdatedEvent
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.models.inappmessage.IInAppMessage
import com.braze.models.inappmessage.IInAppMessageImmersive
import com.braze.models.inappmessage.InAppMessageBase
import com.braze.models.inappmessage.InAppMessageImmersiveBase
import com.braze.models.inappmessage.MessageButton
import com.braze.support.BrazeLogger.Priority.*
import com.braze.support.BrazeLogger.brazelog
import com.braze.support.BrazeLogger.logLevel
import com.braze.support.requestPushPermissionPrompt
import com.braze.support.toBundle
import com.braze.ui.BrazeDeeplinkHandler
import com.braze.ui.actions.NewsfeedAction
import com.braze.ui.activities.BrazeFeedActivity
import com.braze.ui.activities.ContentCardsActivity
import com.braze.ui.inappmessage.BrazeInAppMessageManager
import com.braze.ui.inappmessage.InAppMessageOperation
import com.braze.ui.inappmessage.listeners.DefaultInAppMessageManagerListener
import org.apache.cordova.CallbackContext
import org.apache.cordova.CordovaPlugin
import org.apache.cordova.CordovaPreferences
Expand All @@ -42,6 +53,7 @@ open class BrazePlugin : CordovaPlugin() {
private var pluginInitializationFinished = false
private var disableAutoStartSessions = false
private val feedSubscriberMap: MutableMap<String, IEventSubscriber<FeedUpdatedEvent>> = ConcurrentHashMap()
private var inAppMessageDisplayOperation: InAppMessageOperation = InAppMessageOperation.DISPLAY_NOW

override fun pluginInitialize() {
applicationContext = cordova.activity.applicationContext
Expand Down Expand Up @@ -145,6 +157,13 @@ open class BrazePlugin : CordovaPlugin() {
cordova.activity.requestPushPermissionPrompt()
return true
}
"updateTrackingPropertyAllowList" -> {
// iOS Only
}
"setAdTrackingEnabled" -> {
runOnBraze { it.setGoogleAdvertisingId(args.getString(1), args.getBoolean(0)) }
return true
}
"setUserAttributionData" -> {
runOnUser {
it.setAttributionData(
Expand Down Expand Up @@ -312,6 +331,110 @@ open class BrazePlugin : CordovaPlugin() {
cordova.activity.startActivity(intent)
return true
}
"subscribeToInAppMessage" -> {
runOnBraze {
val useBrazeUI = args.getBoolean(0)
inAppMessageDisplayOperation = if (useBrazeUI) {
InAppMessageOperation.DISPLAY_NOW
} else {
InAppMessageOperation.DISPLAY_LATER
}
setDefaultInAppMessageListener()
}
}
"hideCurrentInAppMessage" -> {
BrazeInAppMessageManager.getInstance().hideCurrentlyDisplayingInAppMessage(true)
}
"logInAppMessageImpression" -> {
runOnBraze {
val inAppMessageString = args.getString(0)
brazelog { "logInAppMessageImpression called with value $inAppMessageString" }
it.deserializeInAppMessageString(inAppMessageString)?.logImpression()
}
return true
}
"logInAppMessageClicked" -> {
runOnBraze {
val inAppMessageString = args.getString(0)
brazelog { "logInAppMessageClicked called with value $inAppMessageString" }
it.deserializeInAppMessageString(inAppMessageString)?.logClick()
}
return true
}
"logInAppMessageButtonClicked" -> {
runOnBraze { braze ->
val inAppMessageString = args.getString(0)
val buttonId = args.getInt(1)
brazelog { "logInAppMessageButtonClicked called with value $inAppMessageString, and button: $buttonId" }
val inAppMessage = braze.deserializeInAppMessageString(inAppMessageString)
if (inAppMessage is IInAppMessageImmersive) {
inAppMessage.messageButtons
.firstOrNull { it.id == buttonId }
?.let { inAppMessage.logButtonClick(it) }
}
}
return true
}
"performInAppMessageAction" -> {
val inAppMessageString = args.getString(0)
val buttonId = args.getInt(1)
runOnBraze { braze ->
brazelog { "performInAppMessageAction called with value $inAppMessageString, and button: $buttonId" }
braze.deserializeInAppMessageString(inAppMessageString)?.let { inAppMessage ->
val activity = cordova.activity
if (activity == null || inAppMessage !is InAppMessageBase) return@runOnBraze

var button: MessageButton? = null
if (buttonId >= 0 && inAppMessage is InAppMessageImmersiveBase) {
button = inAppMessage.messageButtons.firstOrNull { it.id == buttonId }
}
val clickAction = if (buttonId < 0) {
inAppMessage.clickAction
} else {
button?.clickAction
}
val clickUri = if (buttonId < 0) {
inAppMessage.uri
} else {
button?.uri
}
val openUriInWebView = if (buttonId < 0) {
inAppMessage.openUriInWebView
} else {
button?.openUriInWebview ?: false
}
brazelog { "got action: $clickUri, $openUriInWebView, $clickAction" }
when (clickAction) {
ClickAction.NEWS_FEED -> {
val newsfeedAction = NewsfeedAction(
inAppMessage.extras.toBundle(),
Channel.INAPP_MESSAGE
)
BrazeDeeplinkHandler.getInstance()
.gotoNewsFeed(activity, newsfeedAction)
}

ClickAction.URI -> {
if (clickUri != null) {
val uriAction =
BrazeDeeplinkHandler.getInstance().createUriActionFromUri(
clickUri, inAppMessage.extras.toBundle(),
openUriInWebView, Channel.INAPP_MESSAGE
)
brazelog { "Performing gotoUri $clickUri $openUriInWebView" }
BrazeDeeplinkHandler.getInstance()
.gotoUri(applicationContext, uriAction)
}
}

else -> {
brazelog { "Unhandled action $clickAction" }
}
}
}
}
return true
}
"getFeatureFlag" -> {
runOnBraze {
val result = it.getFeatureFlag(args.getString(0))
Expand Down Expand Up @@ -557,7 +680,7 @@ open class BrazePlugin : CordovaPlugin() {
if (notificationChannelDescription.isNotBlank()) {
configBuilder.setDefaultNotificationChannelDescription(notificationChannelDescription)
} else {
brazelog (W) { "Invalid default notification channel description. Default notification description not set." }
brazelog (W) { "Invalid default notification channel description. Default notification description not set." }
}
}

Expand Down Expand Up @@ -812,6 +935,28 @@ open class BrazePlugin : CordovaPlugin() {
return true
}

private fun setDefaultInAppMessageListener() {
BrazeInAppMessageManager.getInstance().setCustomInAppMessageManagerListener(
object : DefaultInAppMessageManagerListener() {
override fun beforeInAppMessageDisplayed(inAppMessage: IInAppMessage): InAppMessageOperation {
super.beforeInAppMessageDisplayed(inAppMessage)

// Convert in-app message to string
val inAppMessageString = inAppMessage.forJsonPut().toString()
brazelog { "In-app message received: $inAppMessageString" }

// Send in-app message string back to JavaScript in an `inAppMessageReceived` event
val jsStatement = "app.inAppMessageReceived('$inAppMessageString');"
cordova.activity.runOnUiThread {
webView.engine.evaluateJavascript(jsStatement, null)
}

return inAppMessageDisplayOperation
}
}
)
}

companion object {
// Preference keys found in the config.xml
private const val BRAZE_API_KEY_PREFERENCE = "com.braze.api_key"
Expand Down
2 changes: 1 addition & 1 deletion src/android/build-extras.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ repositories {
}

dependencies {
implementation 'com.braze:android-sdk-ui:30.1.1'
implementation 'com.braze:android-sdk-ui:30.3.0'
implementation 'com.google.firebase:firebase-messaging:23.0.0'
}

Expand Down
Loading

0 comments on commit 71710c2

Please sign in to comment.