Analytics React Native Branch Plugin
Branch 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
- From the Segment web app, click Catalog.
- Search for “Branch Metrics” in the Catalog, select it, and choose which of your sources to connect the destination to.
- On Branch side you will need to sign up for a free Branch account and follow the steps on their Dashboard to complete set up.
- Copy your
Branch Key
from the Settings page of your Branch dashboard. - Paste the Branch Key in the destination settings and click Save.
Installation
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 docs for more information about this dependency.
Usage
Follow the instructions for adding plugins on the main Analytics client.
In your code where you initialize the analytics client, call the .add(plugin)
method with an BranchPlugin
instance:
import { createClient } from '@segment/analytics-react-native';
import { BranchPlugin } from '@segment/analytics-react-native-plugin-branch';
const segmentClient = createClient({
writeKey: 'SEGMENT_KEY'
});
segmentClient.add({ plugin: new BranchPlugin() });
Identify
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:
const { identify } = useAnalytics();
identify('user-123', {
username: 'MisterWhiskers',
email: 'hello@test.com',
plan: 'premium',
});
When you call .identify('userId')
, Segment uses Branch’s setIdentity(userId)
method to send the userId
that was passed in.
Track
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:
const { track } = useAnalytics();
track('View Product', {
productId: 123,
productName: 'Striped trousers',
});
When you call track
, Segment translates it automatically and sends the event to Branch’s logEvent()
endpoint.
Screen
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:
const { screen } = useAnalytics();
screen('ScreenName', {
productSlug: 'example-product-123',
});
Segment sends Screen Events to Branch’s logEvent()
endpoint.
This page was last modified: 28 Aug 2023
Need support?
Questions? Problems? Need more info? Contact Segment Support for assistance!