Skip to contentSkip to navigationSkip to topbar
Page toolsOn this page
Looking for more inspiration?Visit the

Analytics Kotlin Braze Plugin


Braze(link takes you to an external page), 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(link takes you to an external page) repository.

This destination plugin is maintained by Braze. For any issues with the destination plugin code, reach out to Braze's support.


Getting started

getting-started page anchor
  1. From the Segment web app, click Catalog.
  2. Search for Braze in the Catalog, select it, and choose which of your sources to connect the destination to.
  3. In the Destination Settings, add the API Key, found in the Braze Dashboard in App Settings > Manage App Group.
  4. 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(link takes you to an external page) in the Braze documentation.
  5. Select the users.track endpoint in the User Data section.
(warning)

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:

1
repositories {
2
maven { url "https://appboy.github.io/appboy-android-sdk/sdk" }
3
}

Using the plugin in your app

using-the-plugin-in-your-app page anchor

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.

1
analytics = Analytics("<YOUR WRITE KEY>", applicationContext) {
2
this.collectDeviceId = true
3
this.trackApplicationLifecycleEvents = true
4
this.trackDeepLinks = true
5
this.flushAt = 3
6
this.flushInterval = 0
7
}
8
analytics.add(plugin = BrazeDestination(applicationContext))

Your events will begin to flow to Braze in device-mode.


(information)

Tip

Add Segment's open-source Middleware(link takes you to an external page) tool to optimize your integration. This tool limits Data Point(link takes you to an external page) use by debouncing duplicate identify() calls from Segment. For more information, see the project's README(link takes you to an external page).

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:

1
analytics.identify("user-123", buildJsonObject {
2
put("username", "MisterWhiskers")
3
put("email", "hello@test.com")
4
put("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.


(information)

Tip

To lower Data Point(link takes you to an external page) 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:

1
analytics.track("View Product", buildJsonObject {
2
put("productId", 123)
3
put("productName" "Striped trousers")
4
});

When you track an event, Segment sends that event to Braze as a custom event.

(success)

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.

Order Completed

order-completed page anchor

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:

1
analytics.track("Purchased Item", buildJsonObject {
2
put("revenue", "50")
3
put("currency", "USD")
4
});

The example above would have "Purchased Item" as its productId and includes two required properties that you must pass in:

  • revenue
  • currency

Braze supports currency codes as specified in their Purchase Object Specification(link takes you to an external page). 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(link takes you to an external page).

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:

  • time
  • product_id
  • quantity
  • event_name
  • price