adjust-icon

React Native SDK integration guide

The Adjust React Native SDK enables you to measure attribution, events, and much more in your React Native app. Follow the steps in this guide to set up your app to work with the Adjust SDK. You can also check out the example apps on GitHub.

1. Add the SDK to your project

To use the Adjust SDK in your React Native app, you need to add it to your project. Follow these steps to add it:

  1. Download the React Native library using one of the following options.
  1. Install the CocoaPods dependencies for your iOS app by running the following command on your terminal:
Terminal window
$ cd ios && pod install

2. Integrate the SDK

To integrate the SDK with your project, you must import Adjust’s SDK configuration to your main app Javascript file.

Add the following line at the beginning of your app’s .js file:

import { Adjust, AdjustEvent, AdjustConfig } from "react-native-adjust";

3. Initialize the Adjust SDK

Make sure you initialize the Adjust SDK as soon as possible in your React Native app. To do this, initialize your config object with your app token and the environment you want to run your application in. Add the following lines of code to your app’s .js file:

constructor(props) {
super(props);
const adjustConfig = new AdjustConfig("{YourAppToken}", AdjustConfig.EnvironmentSandbox);
Adjust.create(adjustConfig);
}
componentWillUnmount() {
Adjust.componentWillUnmount();
}

Pass the AdjustConfig arguments:

  • Replace {YourAppToken} with your token. See App settings for instructions on how to find your token.
  • Choose your Environment:
    • Use AdjustConfig.EnvironmentSandbox if you are testing your app and want to send test data. You need to enable sandbox mode in the dashboard to see test data.
    • Use AdjustConfig.EnvironmentProduction when you have finished testing and are ready to release your app.

4. Set up Android devices

Add permissions

The Adjust SDK requires certain permissions to access information. Add them to your AndroidManifest.xml file if they’re not already present:

AndroidManifest.xml
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>

The Adjust SDK includes the com.google.android.gms.AD_ID permission by default in version 4.32.0 and above. You can remove it by adding a remove directive if need to make your app COPPA-compliant or if you don’t target the Google Play Store.

AndroidManifest.xml
<uses-permission android:name="com.google.android.gms.permission.AD_ID"/>

Add Google Play Services

Apps that target the Google Play Store must use the Google Advertising ID (gps_adid) to identify devices. To do this, Add the following dependency to the dependencies section of your build.gradle file.

build.gradle
implementation 'com.google.android.gms:play-services-ads-identifier:18.0.1'

Set up Proguard

If you are using Proguard, add the following rules to your Proguard file.

proguard.pro
-keep class com.adjust.sdk.** { *; }
-keep class com.google.android.gms.common.ConnectionResult {
int SUCCESS;
}
-keep class com.google.android.gms.ads.identifier.AdvertisingIdClient {
com.google.android.gms.ads.identifier.AdvertisingIdClient$Info getAdvertisingIdInfo(android.content.Context);
}
-keep class com.google.android.gms.ads.identifier.AdvertisingIdClient$Info {
java.lang.String getId();
boolean isLimitAdTrackingEnabled();
}
-keep public class com.android.installreferrer.** { *; }

Set up install referrer

The install referrer is an attribution mechanism you can use to attribute an app install to a source. It consists of two parts:

  • A set of APIs from these app stores that allow developers to retrieve referral content in their apps.
  • A referrer parameter that app stores, such as Google Play and Huawei App Gallery, accept in their app page URLs on their store websites. Here is how the referrer parameter is populated:
    • When a user clicks on an Adjust link, the Adjust server passes a unique identifier called reftag. This identifier is assigned to the click and into the referrer parameter. To know more about reftag, visit Reftag.
    • When you run Google Ads campaigns, Google passes a unique identifier called gclid into the referrer parameter. You must have Auto-tagging turned on in your Google Ads account.

Google Play Referrer API

To support the Google Play Referrer API:

  1. Add the following line in the dependencies block of your top-level build.gradle file:
build.gradle
dependencies {
//...
implementation 'com.android.installreferrer:installreferrer:2.2'
//...
}
  1. The installreferrer library is part of Google Maven repository. You need to add Google Maven repository to your app’s top-level build.gradle file to build your app:
build.gradle
allprojects {
repositories {
maven {
url "https://maven.google.com"
}
}
}
  1. If you are using Proguard, make sure you have added the following setting in your Proguard file:
proguard.pro
-keep public class com.android.installreferrer.** { *; }

Huawei Referrer API

As of v4.22.0, the Adjust SDK supports install measurement on Huawei devices using Huawei App Gallery v10.4 and later. You don’t need to make any changes to start using the Huawei Referrer API.

Meta referrer integration

The Adjust SDK supports the Meta Install Referrer in v4.37.0 and above. To enable this feature:

  1. Find your Meta app ID in your App Dashboard. See Meta’s App Dashboard documentation for more information.

  2. Pass your App ID as a string argument to the AdjustConfig.setFbAppId method.

    const adjustConfig = new AdjustConfig(
    "{YourAppToken}",
    AdjustConfig.EnvironmentSandbox,
    );
    //...
    adjustConfig.setFbAppId("<FB_APP_ID_STRING>");
    //...
    Adjust.create(adjustConfig);

5. Add iOS frameworks

The Adjust SDK is able to get extra information when you include certain iOS frameworks in your app. These frameworks enable certain SDK features, but they’re not mandatory for the SDK to work normally. You can add the frameworks and then mark them as optional in Project Settings —> Build Phases —> Link Binary With Libraries.

6. Add the Adjust SDK signature

You can use the Adjust SDK signature to sign all communications sent by the Adjust SDK. This enables Adjust’s servers to detect and reject any install activity that isn’t legitimate.

To get started with the Adjust SDK signature, contact your Technical Account Manager or support@adjust.com.

7. Test your integration

The Adjust SDK provides tools for testing and troubleshooting issues with your integration. To test your setup:

  • Set your environment to AdjustConfig.EnvironmentSandbox.
  • Add a sandbox filter to your Adjust dashboard results.
  • Set your log level to AdjustConfig.LogLevelVerbose.

Test Google Play Services integration

To test that the Adjust SDK can receive a device’s Google Advertising ID, set the log level to AdjustConfig.LogLevelVerbose and the environment to AdjustConfig.EnvironmentSandbox. Start your app and record a session or an event. The SDK logs the gps_adid parameter if it has read the advertising ID.

If you’re having issues retrieving the Google Advertising ID, open an issue on the SDK GitHub repository or contact support@adjust.com.