Analytics Kotlin Braze Plugin
Braze, formerly Appboy, is an engagement platform that empowers growth by helping marketing teams to build customer loyalty through mobile, omni-channel customer experiences.
Braze's destination plugin code is open source and available on GitHub. You can view it on GitHub in the @braze-inc/braze-segment-kotlin repository.
This destination plugin is maintained by Braze. For any issues with the destination plugin code, reach out to Braze's support.
- From the Segment web app, click Catalog.
- Search for Braze in the Catalog, select it, and choose which of your sources to connect the destination to.
- In the Destination Settings, add the API Key, found in the Braze Dashboard in App Settings > Manage App Group.
- Set up a new App Group REST API Key in the Braze Dashboard in App Settings > Developer Console > API Settings. For more information, see Creating and Managing REST API Keys in the Braze documentation.
- Select the
users.trackendpoint in the User Data section.
Warning
The Braze (Classic) destination is in maintenance mode except for mobile device mode implementations.
To install the Segment-Braze integration, add the following line to your app's build.gradle file, replacing <latest_version> with the latest version number.
implementation 'com.braze:braze-segment-kotlin:<latest_version>'
Or the following for Kotlin DSL:
implementation('com.braze:braze-segment-kotlin:<latest_version>')
Also add the following lines to the build.gradle file:
1repositories {2maven { url "https://appboy.github.io/appboy-android-sdk/sdk" }3}
Open the file where you set up and configure the Analytics-Kotlin library, which is usually MainApplication.kt Add this plugin to the list of imports.
import com.segment.analytics.kotlin.destinations.braze.BrazeDestination
In your Analytics-Kotlin library setup, call analytics.add(plugin = ...) to add an instance of the plugin to the Analytics timeline.
1analytics = Analytics("<YOUR WRITE KEY>", applicationContext) {2this.collectDeviceId = true3this.trackApplicationLifecycleEvents = true4this.trackDeepLinks = true5this.flushAt = 36this.flushInterval = 07}8analytics.add(plugin = BrazeDestination(applicationContext))
Your events will begin to flow to Braze in device-mode.
Tip
Add Segment's open-source Middleware tool to optimize your integration. This tool limits Data Point use by debouncing duplicate identify() calls from Segment. For more information, see the project's README.
If you're not familiar with the Segment Specs, take a look to understand what the Identify method does. An example call would look like:
1analytics.identify("user-123", buildJsonObject {2put("username", "MisterWhiskers")3put("email", "hello@test.com")4put("plan", "premium")5});
When you identify a user, Segment passes that user's information to Braze with userId as Braze's External User ID.
If you're using a device-mode connection, Braze's SDK assigns a device_id and a backend identifier, braze_id, to every user. This allows Braze to capture anonymous activity from the device by matching on those identifiers instead of userId. This applies to device-mode connections.
Tip
To lower Data Point use, limit the events you send to Braze to those that are relevant for campaigns and segmentation to the Braze destination. For more information, see Schema Controls.
If you're not familiar with the Segment Specs, take a look to understand what the Track method does. An example call looks like:
1analytics.track("View Product", buildJsonObject {2put("productId", 123)3put("productName" "Striped trousers")4});
When you track an event, Segment sends that event to Braze as a custom event.
Success!
Braze requires that you include a userId or braze_id for all calls made in cloud-mode. Segment sends a braze_id if userId is missing. When you use a device-mode connection, Braze automatically tracks anonymous activity using the braze_id if a userId is missing.
When you track an event with the name Order Completed using the e-commerce tracking API, Segment sends the products you've listed to Braze as purchases.
When you pass ecommerce events, the name of the event becomes the productId in Braze. An example of a purchase event looks like:
1analytics.track("Purchased Item", buildJsonObject {2put("revenue", "50")3put("currency", "USD")4});
The example above would have "Purchased Item" as its productId and includes two required properties that you must pass in:
revenuecurrency
Braze supports currency codes as specified in their Purchase Object Specification. Be aware that any currency reported other than USD displays in the Braze UI in USD based on the exchange rate on the date it was reported.
You can add more product details in the form of key-value pairs to the properties object. The following reserved keys are not passed to Braze if included in your Track call's properties object:
timeproduct_idquantityevent_nameprice