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 Branch Plugin


Branch(link takes you to an external page) empowers you to increase mobile revenue with enterprise-grade links built to acquire, engage, and measure customers across all devices, channels, and platforms. An industry-leading mobile measurement and deep linking platform, trusted by top ranking apps to increase efficiency and revenue.


Getting started

getting-started page anchor
  1. From the Segment web app, click Catalog.
  2. Search for "Branch Metrics" in the Catalog, select it, and choose which of your sources to connect the destination to.
  3. On Branch side you will need to sign up for a free Branch account(link takes you to an external page) and follow the steps on their Dashboard to complete set up.
  4. Copy your Branch Key from the Settings page of your Branch dashboard(link takes you to an external page).
  5. Paste the Branch Key in the destination settings and click Save.

You need to install the @segment/analytics-react-native-plugin-branch and the react-native-branch dependencies to use the Branch plugin.

Using NPM:

npm install --save @segment/analytics-react-native-plugin-branch react-native-branch

Using Yarn:

yarn add @segment/analytics-react-native-plugin-branch react-native-branch

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

See the Branch React Native SDK(link takes you to an external page) docs for more information about this dependency.


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 an BranchPlugin instance:

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

If you're not familiar with the Segment Spec, take a moment to understand what the Identify method does. An example call looks like this:

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

When you call .identify('userId'), Segment uses Branch's setIdentity(userId) method to send the userId that was passed in.


If you're not familiar with the Segment Spec, take a moment to understand what the Track method does. An example call looks like this:

1
const { track } = useAnalytics();
2
3
track('View Product', {
4
productId: 123,
5
productName: 'Striped trousers',
6
});

When you call track, Segment translates it automatically and sends the event to Branch's logEvent() endpoint.


If you're not familiar with the Segment Spec, take a look to understand what the Screen method does. An example call looks like this:

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

Segment sends Screen Events to Branch's logEvent() endpoint.