# Migrating from Branch to Airbridge in React Native

## **1. Remove Branch Integration**

#### **1.1 Remove Package**

Uninstall the Branch dependency:

```bash
npm uninstall react-native-branch
```

***

#### **1.2 iOS Changes**

**a) Remove Associated Domains**

1. Navigate to:\
   **Xcode → Target → Signing & Capabilities → Associated Domains**
2. Remove all `applinks:` entries like:

   ```
   applinks:your-subdomain-1.app.link
   applinks:your-subdomain-2-alternate.app.link
   ```

**b) Remove Info.plist Configurations**

Delete the following keys from `Info.plist`:

* `branch_universal_link_domains`
* `branch_key`

**c) Remove Branch Code from AppDelegate**

Remove these from `AppDelegate.swift`:

```swift
import RNBranch

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
    RNBranch.initSession(launchOptions: launchOptions)
    return true
}

func application(_ app: UIApplication, open url: URL, options: [UIApplicationOpenURLOptionsKey : Any] = [:]) -> Bool {
    RNBranch.application(app, open:url, options:options)
    return true
}

func application(_ application: UIApplication, continue userActivity: NSUserActivity, restorationHandler: @escaping ([Any]?) -> Void) -> Bool {
    RNBranch.continue(userActivity)
    return true
}
```

***

#### **1.3 Android Changes**

**a) Remove Branch Config from `AndroidManifest.xml`**

Remove the following from `<application>`:

```xml
<!-- Branch SDK Key -->
<meta-data android:name="io.branch.sdk.BranchKey" android:value="key_live_XXX" />

<!-- Branch Universal Link Domains -->
<intent-filter android:autoVerify="true">
    <action android:name="android.intent.action.VIEW" />
    <category android:name="android.intent.category.DEFAULT" />
    <category android:name="android.intent.category.BROWSABLE" />
    <data android:scheme="https" android:host="example.app.link" />
    <data android:scheme="https" android:host="example-alternate.app.link" />
</intent-filter>
```

**b) Remove Branch from MainActivity.kt**

```kotlin
import io.branch.rnbranch.*
import android.content.Intent

override fun onStart() {
    super.onStart()
    RNBranchModule.initSession(getIntent().getData(), this)
}

override fun onNewIntent(intent: Intent?) {
    super.onNewIntent(intent)
    setIntent(intent)
    RNBranchModule.reInitSession(this)
}
```

**c) Remove Branch from MainApplication.kt**

```kotlin
import io.branch.rnbranch.*

override fun onCreate() {
    super.onCreate()
    RNBranchModule.getAutoInstance(this)
    // Remove Branch logging code if added
}
```

**d) Remove Branch Subscription Code**

From your root component:

```javascript
import branch from 'react-native-branch';

useEffect(() => {
    const unsubscribe = branch.subscribe(({ error, params }) => {
        if (error) return;
        // Branch deep link logic
    });
    return () => unsubscribe();
}, []);
```

***

## **2. Add AirBridge Integration**

In the code below, replace the placeholder variables **YOUR\_APP\_NAME** and **YOUR\_APP\_SDK\_TOKEN** with your actual values.

#### Integration credentials

If you already have an **AirBridge** account, keep your credentials ready.\
If you don’t have them yet, no problem — we’ll handle the setup for you.\
Once you configure your referral tracking campaign and enable Mobile Apps, we’ll email you the required integration credentials, including:

* `YOUR_APP_SDK_TOKEN`
* `YOUR_APP_NAME`

> If you don’t receive the email, please contact ReferralHero Support at <support@referralhero.com>

#### **2.1 Install Airbridge SDK**

* **Using NPM**

  ```bash
  npm install airbridge-react-native-sdk
  ```
* **Using yarn**

  ```bash
  yarn add airbridge-react-native-sdk
  ```

***

#### **2.2 Android Setup**

**a) Add Intent Filters in `AndroidManifest.xml`**

Add under your `<activity>`:

**Scheme Deep Link:**

```xml
<intent-filter>
    <action android:name="android.intent.action.VIEW" />
    <category android:name="android.intent.category.DEFAULT" />
    <category android:name="android.intent.category.BROWSABLE" />
    <!-- Replace YOUR_SCHEME with your actual app scheme -->
    <data android:scheme="YOUR_SCHEME" />
</intent-filter>
```

**App Links:**

```xml
<intent-filter android:autoVerify="true">
    <action android:name="android.intent.action.VIEW" />
    <category android:name="android.intent.category.DEFAULT" />
    <category android:name="android.intent.category.BROWSABLE" />
    <!-- Replace YOUR_APP_NAME with your actual app name -->
    <data android:scheme="https" android:host="YOUR_APP_NAME.abr.ge" />
</intent-filter>

<intent-filter android:autoVerify="true">
    <action android:name="android.intent.action.VIEW" />
    <category android:name="android.intent.category.DEFAULT" />
    <category android:name="android.intent.category.BROWSABLE" />
    <!-- Replace YOUR_APP_NAME with your actual app name -->
    <data android:scheme="https" android:host="YOUR_APP_NAME.airbridge.io" />
</intent-filter>
```

**b) Initialize SDK in `MainApplication.kt`**

<pre class="language-kotlin"><code class="lang-kotlin">import co.ab180.airbridge.reactnative.AirbridgeReactNative

override fun onCreate() {
    super.onCreate()
<strong>    // Replace YOUR_APP_NAME and YOUR_APP_SDK_TOKEN with your actual values
</strong>    AirbridgeReactNative.initializeSDK(this, "YOUR_APP_NAME", "YOUR_APP_SDK_TOKEN")
}
</code></pre>

**c) Track Deep Links in `MainActivity.kt`**

```kotlin
import android.content.Intent
import android.os.Bundle
import co.ab180.airbridge.reactnative.AirbridgeReactNative

override fun onResume() {
    super.onResume()
    AirbridgeReactNative.trackDeeplink(intent)
}

override fun onNewIntent(intent: Intent?) {
    super.onNewIntent(intent)
    setIntent(intent)
}
```

***

#### **2.3 iOS Setup**

**a) Associated Domains**

To configure:

1. Open your project in **Xcode**.
2. Navigate to **Target → Signing & Capabilities**.
3. Add a new **Associated Domains** entry.
4. Add an entry in the following format:

   ```
   applinks:YOUR_APP_NAME.airbridge.io
   ```

**b) Initialize SDK in AppDelegate file**

```swift
import AirbridgeReactNative

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
    // Replace YOUR_APP_NAME and YOUR_APP_SDK_TOKEN with your actual values
    AirbridgeReactNative.initializeSDK(name: "YOUR_APP_NAME", token:"YOUR_APP_SDK_TOKEN")
    return true
}
```

**c) Handle Deep Links**

```swift
// Scheme deeplink
func application(_ app: UIApplication, open url: URL, options: [UIApplication.OpenURLOptionsKey : Any] = [:]) -> Bool {
    AirbridgeReactNative.trackDeeplink(url: url)
    return true
}

// Universal links
func application(_ application: UIApplication, continue userActivity: NSUserActivity, restorationHandler: @escaping ([UIUserActivityRestoring]?) -> Void) -> Bool {
    AirbridgeReactNative.trackDeeplink(userActivity: userActivity)
    return true
}
```

***

#### **2.4 React Native Deep Link Handling**

Place this code in the root file of your project. Fetch the required parameters and store them for later use in the Signup API. The two key parameters are:

* **visitor\_id**: The unique ID of the referred visitor who clicked the referral link. This must be included in the Signup API to track and attribute the referral upon signup.
* **referrer**: The identifier of the original referrer. This is optional, as `visitor_id` alone is sufficient for tracking the referral.

```javascript
import { Airbridge } from 'airbridge-react-native-sdk';

Airbridge.setOnDeeplinkReceived((url) => {
    // Parse URL params for visitor_id and referrer.
      const parsed = queryString.parseUrl(url);
      const visitorId = parsed.query.visitor_id;
      const referrer = parsed.query.referrer;
      
    // Save in AsyncStorage for later usage during signup
});
```

***

### ✅ Migration Complete

You’ve successfully removed Branch and integrated Airbridge.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://berylsystems.gitbook.io/referral-hero-documentation/integrations/mobile-sdks/react-native/migrating-from-branch-to-airbridge-in-react-native.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
