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 below 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
ReactAppboy.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
ReactAppboy.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
reactAppboy.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.

Standard User Attributes

To assign use attributes, you can use setter methods that come with the SDK.

1
ReactAppboy.setFirstName("Name");

The following attributes are supported:

  • First Name
  • Last Name
  • Gender
  • Date of Birth
  • Home City
  • Country
  • Phone Number
  • Language
  • Email
  • Avatar Image URL for Braze User Profiles
  • Twitter Data
  • Facebook Data

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

Custom User Attributes

Beyond the attributes above, Braze also allows you to define custom attributes for your users. Supported data types for values include Date, Array, boolean, string, number, and float. String values have a maximum length of 255 characters.

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

Unsetting a Custom Attribute

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

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
ReactAppboy.logPurchase(productId, price, currencyCode, quantity, properties);

For example:

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

Reserved Keys

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

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