Skip to content

Commit

Permalink
Release Cordova SDK version 10.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
jerielng committed Aug 26, 2024
1 parent 1f77ef0 commit 65601c0
Show file tree
Hide file tree
Showing 13 changed files with 405 additions and 55 deletions.
22 changes: 22 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,27 @@
⚠️ 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.

## 10.0.0

##### Breaking
- ⚠️ This version now requires Cordova Android 13.0.0. ⚠️
- Refer to the [Cordova release announcement](https://cordova.apache.org/announcements/2024/05/23/cordova-android-13.0.0.html) for a full list of project dependency requirements.
- Updated the native Android bridge [from Braze Android SDK 30.3.0 to 32.1.0](https://github.com/braze-inc/braze-android-sdk/compare/v30.3.0...v32.1.0#diff-06572a96a58dc510037d5efa622f9bec8519bc1beab13c9f251e97e657a9d4ed).
- Updated the native iOS bridge [from Braze Swift SDK 9.2.0 to 10.1.0](https://github.com/braze-inc/braze-swift-sdk/compare/9.2.0...10.1.0#diff-06572a96a58dc510037d5efa622f9bec8519bc1beab13c9f251e97e657a9d4ed).

##### Fixed
- Fixed the native-to-JavaScript translation of in-app message strings, where nested escape characters were previously being removed.
- Fixed the `subscribeToInAppMessage` method on iOS to respect the `useBrazeUI` setting.
- Updated the Android implementation to match iOS by using the `DISCARD` option instead of `DISPLAY_LATER` if the default Braze UI is not used.
- Fixed the `getContentCardsFromServer` method to trigger an error callback on iOS when cards have failed to refresh.

##### Added
- Added the `getUserId()` method to get the ID of the current user. This method will return `null` if the current user is anonymous.
- Added support for new Feature Flag property types and APIs for accessing them:
- `getFeatureFlagTimestampProperty(id, key)` for accessing Int Unix UTC millisecond timestamps as `number`s.
- `getFeatureFlagImageProperty(id, key)` for accessing image URLs as `string`s.
- `getFeatureFlagJSONProperty(id, key)` for accessing JSON objects as `object` types.
- Added `setLocationCustomAttribute(key, latitude, longitude)` to set a location custom attribute.

## 9.2.0

##### Added
Expand Down
9 changes: 8 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,14 @@ Effective marketing automation is an essential part of successfully scaling and

See our [Technical Documentation for Android](https://www.braze.com/docs/developer_guide/platform_integration_guides/cordova/initial_sdk_setup/android/) and [Technical Documentation for iOS](https://www.braze.com/docs/developer_guide/platform_integration_guides/cordova/initial_sdk_setup/ios/) for instructions on integrating Braze into your Cordova app.

# Running the sample application
## Minimum version requirements

| Braze Plugin | Cordova Android | Cordova iOS |
| ------------ | --------------- | ----------- |
| 10.0.0+ | >= 13.0.0 | >= 5.0.0 |
| 2.31.0+ | >= 12.0.0 | >= 5.0.0 |

## Running the sample application

```
cordova plugin remove cordova-plugin-braze
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "braze-cordova-sdk",
"version": "9.2.0",
"version": "10.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="9.2.0">
id="cordova-plugin-braze" version="10.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="~> 9.2.0" />
<pod name="BrazeUI" spec="~> 9.2.0" />
<pod name="BrazeLocation" spec="~> 9.2.0" />
<pod name="BrazeKit" spec="~> 10.1.0" />
<pod name="BrazeUI" spec="~> 10.1.0" />
<pod name="BrazeLocation" spec="~> 10.1.0" />
</pods>
</podspec>
</platform>
Expand Down
8 changes: 4 additions & 4 deletions sample-project/config.xml
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,10 @@
<allow-intent href="market:*" />
<preference name="GradlePluginKotlinEnabled" value="true" />
<preference name="GradlePluginKotlinCodeStyle" value="official" />
<preference name="GradlePluginKotlinVersion" value="1.7.0" />
<preference name="android-targetSdkVersion" value="33" />
<preference name="android-compileSdkVersion" value="33" />
<preference name="GradleVersion" value="7.3.3" />
<preference name="GradlePluginKotlinVersion" value="1.9.24" />
<preference name="android-targetSdkVersion" value="35" />
<preference name="android-compileSdkVersion" value="35" />
<preference name="GradleVersion" value="8.7" />
<preference name="AndroidXEnabled" value="true" />
<preference name="com.braze.api_key" value="ec67377e-c490-4959-8c58-c045a254a65a" />
<preference name="com.braze.android_api_endpoint" value="sondheim.braze.com" />
Expand Down
2 changes: 1 addition & 1 deletion sample-project/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
},
"devDependencies": {
"braze-cordova-sdk": "file:../local",
"cordova-android": "^11.0.0",
"cordova-android": "^13.0.0",
"cordova-ios": "^6.2.0"
}
}
5 changes: 5 additions & 0 deletions sample-project/www/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ <h1>Apache Cordova</h1>
<input type="text" id="changeUserInputId" autocorrect="off" autocapitalize="off" placeholder="External ID" />
<input type="text" id="sdkAuthSignature" autocorrect="off" autocapitalize="off" placeholder="SDK Auth Signature" />
<button id="changeUserBtn">Change User</button>
<button id="getUserIdBtn">Get User ID</button>
<button id="setSdkAuthBtn">Set SDK Auth Signature</button>
<br>
<input type="text" id="logCustomEventId" autocorrect="off" autocapitalize="off" placeholder="Event Name" />
Expand Down Expand Up @@ -97,6 +98,7 @@ <h1>Apache Cordova</h1>
<input type="text" id="horizontalAccuracy" autocorrect="off" autocapitalize="off" placeholder="Horizontal Accuracy" />
<input type="text" id="verticalAccuracy" autocorrect="off" autocapitalize="off" placeholder="Vertical Accuracy (optional)" />
<button id="setLastKnownLocationBtn">Set Last Known Location</button>
<button id="setLocationCustomAttributeBtn">Set Location Custom Attribute</button>
<button id="wipeData">Clears all SDK data</button>
<button id="enableSdk">Enables the SDK</button>
<button id="disableSdk">Disables the SDK</button>
Expand All @@ -116,6 +118,9 @@ <h1>Apache Cordova</h1>
<option value="boolean">Boolean</option>
<option value="number">Number</option>
<option value="string">String</option>
<option value="timestamp">Timestamp</option>
<option value="jsonobject">JSON Object</option>
<option value="image">Image</option>
</select>
<button id="getFeatureFlagPropertyBtn">Get Feature Flag Property</button>
</div>
Expand Down
29 changes: 29 additions & 0 deletions sample-project/www/js/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ var app = {
document.getElementById("getFeatureFlagPropertyBtn").addEventListener("click", getFeatureFlagProperty);
document.getElementById("logFeatureFlagImpressionBtn").addEventListener("click", logFeatureFlagImpression);
document.getElementById("changeUserBtn").addEventListener("click", changeUser);
document.getElementById("getUserIdBtn").addEventListener("click", getUserId);
document.getElementById("setSdkAuthBtn").addEventListener("click", setSdkAuthenticationSignature);
document.getElementById("logCustomEventBtn").addEventListener("click", logCustomEvent);
document.getElementById("logPurchaseBtn").addEventListener("click", logPurchase);
Expand Down Expand Up @@ -70,6 +71,7 @@ var app = {
document.getElementById("requestFlushBtn").addEventListener("click", requestDataFlush);
document.getElementById("setLanguageBtn").addEventListener("click", setLanguage);
document.getElementById("setLastKnownLocationBtn").addEventListener("click", setLastKnownLocation);
document.getElementById("setLocationCustomAttributeBtn").addEventListener("click", setLocationCustomAttribute);
document.getElementById("getDeviceId").addEventListener("click", getDeviceId);
document.getElementById("requestPushPermission").addEventListener("click", requestPushPermission);
document.getElementById("updateTrackingPropertiesBtn").addEventListener("click", updateTrackingProperties);
Expand Down Expand Up @@ -118,6 +120,16 @@ function changeUser() {
showTextBubble(`User changed to ${userId} with auth signature ${sdkAuthSignature}`);
}

async function getUserId() {
BrazePlugin.getUserId(customPluginSuccessCallback("User ID: "), customPluginErrorCallback);
const userId = await BrazePlugin.getUserId();
if (!userId) {
showTextBubble("User ID not found.");
} else {
showTextBubble(`User ID: ${userId}`);
}
}

function setSdkAuthenticationSignature() {
const sdkAuthSignature = document.getElementById("sdkAuthSignature").value;
if (!sdkAuthSignature) {
Expand Down Expand Up @@ -187,6 +199,18 @@ async function getFeatureFlagProperty() {
const stringProperty = await BrazePlugin.getFeatureFlagStringProperty(featureFlagId, propertyKey);
showTextBubble(`Got string property: ${stringProperty}`);
break;
case 'timestamp':
const timestampProperty = await BrazePlugin.getFeatureFlagTimestampProperty(featureFlagId, propertyKey);
showTextBubble(`Got timestamp property: ${timestampProperty}`);
break;
case 'jsonobject':
const jsonProperty = await BrazePlugin.getFeatureFlagJSONProperty(featureFlagId, propertyKey);
showTextBubble(`Got JSON property: ${JSON.stringify(jsonProperty)}`);
break;
case 'image':
const imageProperty = await BrazePlugin.getFeatureFlagImageProperty(featureFlagId, propertyKey);
showTextBubble(`Got image property: ${imageProperty}`);
break;
default:
showTextBubble("No property type selected.");
}
Expand Down Expand Up @@ -465,6 +489,11 @@ function setLastKnownLocation() {
}
}

function setLocationCustomAttribute() {
BrazePlugin.setLocationCustomAttribute("work", 40.7128, 74.006);
showTextBubble("Location custom attribute set.");
}

function getDeviceId() {
BrazePlugin.getDeviceId(customPluginSuccessCallback("Device ID: "), customPluginErrorCallback);
}
Expand Down
83 changes: 81 additions & 2 deletions src/android/BrazePlugin.kt
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,16 @@ open class BrazePlugin : CordovaPlugin() {
runOnBraze { it.changeUser(userId, sdkAuthToken) }
return true
}
"getUserId" -> {
runOnUser {
if (it.userId.isNullOrBlank()) {
callbackContext.sendCordovaSuccessPluginResultAsNull()
} else {
callbackContext.success(it.userId)
}
}
return true
}
"logCustomEvent" -> {
var properties: BrazeProperties? = null
if (args[1] !== JSONObject.NULL) {
Expand Down Expand Up @@ -293,6 +303,22 @@ open class BrazePlugin : CordovaPlugin() {
}
return true
}
"setLocationCustomAttribute" -> {
runOnUser {
val newArgs = parseJSONArraytoDoubleArray(args)
val key = args.getString(0)
val latitude = newArgs[1]
val longitude = newArgs[2]

if (latitude == null || longitude == null) {
brazelog (I) { "Invalid location information with the latitude: $latitude, longitude: $longitude" }
} else {
it.setLocationCustomAttribute(key, latitude, longitude)
brazelog (I) { "Location custom attribute set with key: $key, latitude: $latitude, longitude: $longitude"}
}
}
return true
}
"setPushNotificationSubscriptionType" -> {
runOnUser { currentUser ->
NotificationSubscriptionType.fromValue(args.getString(0))?.let {
Expand Down Expand Up @@ -337,7 +363,7 @@ open class BrazePlugin : CordovaPlugin() {
inAppMessageDisplayOperation = if (useBrazeUI) {
InAppMessageOperation.DISPLAY_NOW
} else {
InAppMessageOperation.DISPLAY_LATER
InAppMessageOperation.DISCARD
}
setDefaultInAppMessageListener()
}
Expand Down Expand Up @@ -507,6 +533,45 @@ open class BrazePlugin : CordovaPlugin() {
}
return true
}
"getFeatureFlagTimestampProperty" -> {
runOnBraze {
val flagId = args.getString(0)
val propKey = args.getString(1)
val result = it.getFeatureFlag(flagId)?.getTimestampProperty(propKey)
if (result == null) {
callbackContext.sendCordovaSuccessPluginResultAsNull()
} else {
callbackContext.sendPluginResult(PluginResult(PluginResult.Status.OK, result.toFloat()))
}
}
return true
}
"getFeatureFlagJSONProperty" -> {
runOnBraze {
val flagId = args.getString(0)
val propKey = args.getString(1)
val result = it.getFeatureFlag(flagId)?.getJSONProperty(propKey)
if (result == null) {
callbackContext.sendCordovaSuccessPluginResultAsNull()
} else {
callbackContext.sendPluginResult(PluginResult(PluginResult.Status.OK, result))
}
}
return true
}
"getFeatureFlagImageProperty" -> {
runOnBraze {
val flagId = args.getString(0)
val propKey = args.getString(1)
val result = it.getFeatureFlag(flagId)?.getImageProperty(propKey)
if (result == null) {
callbackContext.sendCordovaSuccessPluginResultAsNull()
} else {
callbackContext.sendPluginResult(PluginResult(PluginResult.Status.OK, result))
}
}
return true
}
"logFeatureFlagImpression" -> {
runOnBraze {
Braze.getInstance(applicationContext).logFeatureFlagImpression(args.getString(0))
Expand Down Expand Up @@ -942,7 +1007,7 @@ open class BrazePlugin : CordovaPlugin() {
super.beforeInAppMessageDisplayed(inAppMessage)

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

// Send in-app message string back to JavaScript in an `inAppMessageReceived` event
Expand Down Expand Up @@ -1026,6 +1091,20 @@ open class BrazePlugin : CordovaPlugin() {
return categories
}

/**
* Map a Kotlin string to a JavaScript-representable version.
* Escape characters are lost in translation, so we need to manually insert them back in.
*/
fun escapeStringForJavaScript(input: String): String {
return input
.replace("\\", "\\\\")
.replace("\"", "\\\"")
.replace("\'", "\\\'")
.replace("\n", "\\n")
.replace("\r", "\\r")
.replace("\t", "\\t")
}

/**
* This takes the JSONArray of Any and returns an Array<String?>.
*
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.3.0'
implementation 'com.braze:android-sdk-ui:32.1.0'
implementation 'com.google.firebase:firebase-messaging:23.0.0'
}

Expand Down
3 changes: 3 additions & 0 deletions src/ios/BrazePlugin.h
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,9 @@
- (void)getFeatureFlagBooleanProperty:(CDVInvokedUrlCommand *)command;
- (void)getFeatureFlagStringProperty:(CDVInvokedUrlCommand *)command;
- (void)getFeatureFlagNumberProperty:(CDVInvokedUrlCommand *)command;
- (void)getFeatureFlagTimestampProperty:(CDVInvokedUrlCommand *)command;
- (void)getFeatureFlagJSONProperty:(CDVInvokedUrlCommand *)command;
- (void)getFeatureFlagImageProperty:(CDVInvokedUrlCommand *)command;
- (void)logFeatureFlagImpression:(CDVInvokedUrlCommand *)command;

@end
Loading

0 comments on commit 65601c0

Please sign in to comment.