Skip to content

React Native Analytics

This article covers how to set up and track basic analytics in your React Native app.

Before you start, read our Analytics Overview article to learn more about Braze analytics and what is already tracked by default. We also recommend familiarizing yourself with our event naming conventions.

Session tracking

The Braze SDK reports session data used by the Braze dashboard to calculate user engagement and other analytics integral to understanding your users. based on the following session semantics, our SDK generates “start session” and “close session” data points that account for session length and session counts viewable within the Braze dashboard.

To set a user ID or start a session, use the changeUser method, which takes a user ID parameter.

1
Braze.changeUser("user_id");

Logging custom events

You can record custom events in Braze to learn more about your app’s usage patterns and to segment your users by their actions in the dashboard.

1
Braze.logCustomEvent("react_native_custom_event");

You can add metadata about the event by passing a properties object with your custom event.

1
2
3
4
5
Braze.logCustomEvent("custom_event_with_properties", {
    key1: "value1",
    key2: ["value2", "value3"],
    key3: false,
});

Logging custom attributes

Braze provides methods for assigning attributes to users. You’ll be able to filter and segment your users according to these attributes on the dashboard.

Default user attributes

To assign user attributes automatically collected by Braze, you can use setter methods that come with the SDK.

1
Braze.setFirstName("Name");

The following attributes are supported:

  • First Name
  • Last Name
  • Gender
  • Date of Birth
  • Home City
  • Country
  • Phone Number
  • Language
  • Email

All string values such as first name, last name, country, and home city are limited to 255 characters.

Custom user attributes

In addition to our predefined user attribute methods, Braze also provides custom attributes to track data from your applications.

1
2
3
Braze.setCustomUserAttribute("attribute_key", "attribute_value", function(){
    // optional onResult callback
});

Unsetting a custom attribute

1
2
3
Braze.unsetCustomUserAttribute("attribute_key", function(){
    // optional onResult callback
});

Custom Attribute Arrays

1
2
3
4
5
6
7
8
// Adds a string to a custom atttribute string array, or creates that array if one doesn't exist.
Braze.addToCustomUserAttributeArray("my-attribute-array", "new or existing value", optionalCallback);

// Removes a string from a custom attribute string array.


Braze.removeFromCustomUserAttributeArray("my-attribute-array", "existing value", optionalCallback);

Logging purchases

Record in-app purchases so that you can track your revenue over time and across revenue sources, as well as segment your users by their lifetime value.

Braze supports purchases in multiple currencies. Purchases that you report in a currency other than USD will be shown in the dashboard in USD based on the exchange rate at the date they were reported.

1
Braze.logPurchase(productId, price, currencyCode, quantity, properties);

For example:

1
2
3
Braze.logPurchase("product_id", 9.99, "USD", 1, {
    key1: "value"
});

Log purchases at the order level

If you want to log purchases at the order level instead of the product level, you can use order name or order category as the product_id. Refer to our purchase object specification to learn more.

Reserved keys

The following keys are reserved and cannot be used as purchase properties:

  • time
  • product_id
  • quantity
  • event_name
  • price
  • currency
HOW HELPFUL WAS THIS PAGE?
New Stuff!