Search specific term/phrase surrounded by double quotes. e.g. “deep linking”
Exclude records that contain a specific term prefixed with a minus. e.g. Android -Firebase

React Native Advanced Features

Do more with the Branch React Native SDK by leveraging advanced features for specific use cases.

Overview

The Branch React Native SDK exposes a set of methods specifically made for React Native apps, which you can call using JavaScript.

If you need to access a feature that lives in the Branch iOS SDK or Branch Android SDK, you can call those native SDKs directly in the relevant language.

iOS SDK Full Reference

Android SDK Full Reference

Expo Framework

Please note that Branch does not currently support applications that use Expo.

Prerequisites

Before you implement the features on this page, you first need to:

  1. Create a Branch Dashboard.
  2. Integrate the Branch React Native SDK into your mobile app.
  3. Validate your integration.
  4. Import Branch by adding the following import statement to any React Native source file that uses the SDK:
    import branch from 'react-native-branch'
    

Defer Initialization for Plugin Runtime

It's possible you might run into race conditions which cause your app to not receive Branch params on cold starts.

If this happens, you may need to defer loading the native iOS or Android layer.

To do this, add the following code to your branch.json file:

{
  "deferInitForPluginRuntime": true
}

Set Initialization Metadata

Some third-party Data Integration Partners require setting certain identifiers before initializing Branch.

To do this:

  1. Make sure you have added deferInitForPluginRuntime to your branch.json file as shown above.
  2. Use the setRequestMetadata() method to set your identifiers:
import branch from 'react-native-branch'

// Call `setRequestMetadata` before `subscribe`
branch.setRequestMetadata('$analytics_visitor_id', '000001')

branch.subscribe(( error, params ) => {
  // ...
})

See our iOS and Android documentation for more.

Set Branch API URL

It is possible to set a custom base URL for all calls to the Branch API.

To do this, add the following code to your branch.json file:

{
  "apiUrl": "https://protected-api.branch.io"
}

NativeLink™ Deferred Deep Linking

Use iOS pasteboard to enable deferred deep linking via Branch NativeLink™, which enables 100% matching on iOS through Installs.

🚧

Prerequisite

Minimum SDK Version: v5.0.4

To use this feature you must:

or

Implementation Options

Basic Example

To enable this feature, call the RNBranch.branch checkPasteboardOnInstall method in the AppDelegate file. Call this method prior to Branch initialization.

Example With iOS 15.X Check

If you only want to enable this feature on iOS 15.X, include an iOS version check prior to calling the RNBranch.branch checkPasteboardOnInstall method. Both the version check and the method call happen inside the AppDelegate file, before Branch initialization.

Example With Pasteboard Visibility Check

You can also check whether the pasteboard toast will show or not by using the RNBranch.branch willShowPasteboardToast method. This call happens inside the AppDelegate file, before Branch initialization.

Event Tracking

By default, the Branch React Native SDK tracks clicks, opens, installs, reinstalls and impressions automatically (out-of-the-box).

You can also use the BranchEvent class to track special user actions or application-specific events. For example, you can track when a user adds an item to a shopping cart or searches for a keyword.

In short, a BranchEvent instance corresponds to an in-app event that you want to log with Branch.

You can use a BranchUniversalObject (BUO) instance to populate the contentItems field of the BranchEvent. This is how you associate BUO data with a specific event.

Learn more about tracking events and the logEvent() method in our respective guides.

Push Notifications

To track Branch Deep Links in your push notifications, use the Branch React Native SDK openURL() method:

import branch from 'react-native-branch'

let data = {
  "aps": {
    "alert": "Push notification with a Branch deep link",
    "badge": "1"
  },
  "branch": "https://example.app.link/u3fzDwyyjF"
}

branch.openURL(data["branch"],{newActivity: true})

The JSON object you pass to openURL() can take any form, but it must include a field called "branch" at the top level, which points to a Branch Link.

Add this method to the callback function of the push notification handler (iOS and Android).

User Data

Google DMA Compliance

In response to the European Union's enactment of the Digital Markets Act (DMA), the Branch React Native SDK includes the setDMAParamsForEEA() method to help you pass consent information from your user to Google.

The setDMAParamsForEEA() method takes 3 parameters:

Parameter NameTypeDescriptionWhen trueWhen false
eeaRegionBooleanWhether European regulations, including the DMA, apply to this user and conversion.User is included in European Union regulations. For example, if the user is located within the EEA, they are within the scope of DMA.User is considered excluded from European Union regulations.
adPersonalizationConsentBooleanWhether end user has granted or denied ads personalization consent.User has granted consent for ads personalization.User has denied consent for ads personalization.
adUserDataUsageConsentBooleanWhether end user has granted or denied consent for 3P transmission of user level data for ads.User has granted consent for 3P transmission of user-level data for ads.User has denied consent for 3P transmission of user-level data for ads.

Default Behavior

When parameters are successfully set using setDMAParamsForEEA(), they will be sent along with every future request to the following Branch endpoints:

  • /v1/install
  • /v1/open
  • /v2/event

🚧

Omitted by Default

Please note that the 3 consent parameters related to setDMAParamsForEEA() are all omitted by default.

Failure to include user consent signals may result in attribution or campaign performance degradation. For additional information, please reach out to your Google AM.

Making a successful setDMAParamsForEEA() call requires that all 3 parameters be set.