Skip to contentSkip to navigationSkip to topbar
On this page
Looking for more inspiration?Visit the
(information)
You're in the right place! Segment documentation is now part of Twilio Docs. The content you are used to is still here—just in a new home with a refreshed look.

Analytics React Native 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(link takes you to an external page).


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.
    • Select the users.track endpoint in the User Data section.

You need to install the @segment/analytics-react-native-plugin-braze and the react-native-appboy-sdk dependency.

Using NPM:

npm install --save @segment/analytics-react-native-plugin-braze @braze/react-native-sdk

Using Yarn:

yarn add @segment/analytics-react-native-plugin-braze @braze/react-native-sdk

Run pod install after the installation to autolink the Braze SDK.

See Braze React SDK(link takes you to an external page) for more details of this dependency.


Using the Plugin in your App

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

Follow the instructions for adding plugins(link takes you to an external page) on the main Analytics client:

In your code where you initialize the analytics client, call the .add(plugin) method with a BrazePlugin instance:

1
import { createClient } from '@segment/analytics-react-native';
2
3
import { BrazePlugin } from '@segment/analytics-react-native-plugin-braze';
4
5
const segmentClient = createClient({
6
writeKey: 'SEGMENT_KEY'
7
});
8
9
segmentClient.add({ plugin: new BrazePlugin() });

If you're not familiar with the Segment Specs, take a look to understand what the Page method does. An example call would look like:

1
const { screen } = useAnalytics();
2
3
screen('ScreenName', {
4
productSlug: 'example-product-123',
5
});

Segment sends Page calls to Braze as custom events if you have enabled either Track All Pages or Track Only Named Pages in the Segment Settings.


(information)

Tip

Add Segment's Enrichment Plugin 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.

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
const { identify } = useAnalytics();
2
3
identify('user-123', {
4
username: 'MisterWhiskers',
5
email: 'hello@test.com',
6
plan: 'premium',
7
});

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.

Capture the braze_id of anonymous users

capture-the-braze_id-of-anonymous-users page anchor

Pass one of the many identifiers that may exist on an anonymous user profile to the Braze's User by Identifier REST endpoint(link takes you to an external page) to capture and export the braze_id. These identifiers include:

  • email address
  • phone number
  • device_id

Choose an identifier that is available on the user profile at that point in the user lifecycle.

For example, if you pass device_id to the User by Identifier endpoint:

1
{
2
"device_id": "{{device_id}}",
3
"fields_to_export": ["braze_id"]
4
}

The endpoint returns:

1
{
2
"users": [
3
{
4
"braze_id": "{{braze_id}}"
5
}
6
],
7
"message": "success"
8
}
(information)

Tip

If you decide to use the braze_id, consider contacting Segment Success Engineering(link takes you to an external page) or a Solutions Architect to verify your Braze implementation.

Segment's special traits recognized as Braze's standard user profile fields (in parentheses) are:

Segment EventBraze Event
firstNamefirst_name
lastNamelast_name
birthdaydob
avatarimage_url
address.cityhome_city
address.countrycountry
gendergender

Except for Braze's reserved user profile fields(link takes you to an external page), Segment sends all other traits to Braze as custom attributes. You can send an array of strings as trait values but not nested objects.


(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
const { track } = useAnalytics();
2
3
track('View Product', {
4
productId: 123,
5
productName: 'Striped trousers',
6
});

When you track an event, Segment sends that event to Braze as a custom event. If you're sending Track events in Cloud Mode, Braze requires that you include a userId or braze_id. 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. Segment removes the following custom properties reserved by Braze when sending data in Cloud mode:

  • time
  • quantity
  • event_name
  • price
  • currency

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
const { track } = useAnalytics();
2
3
track('Purchased Item', {
4
revenue: 200,
5
currenct: 'USD',
6
});

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). 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

If you're not familiar with the Segment Specs, take a look to understand what the Group method does. An example call would look like:

1
const { group } = useAnalytics();
2
3
group('some-company', {
4
name: 'Segment',
5
});

When you call group, Segment sends a custom attribute to Braze with the name ab_segment_group_<groupId>, where <groupId> is the group's ID in the method's parameters. For example, if the group's ID is 1234, then the custom attribute name is ab_segment_group_1234. The value of the custom attribute is true.