Branch.io Setup In Ios And Android

 When Firebase dynamic linking is deprecated or unavailable, Branch.io is an excellent alternative for implementing deep linking and attribution in your mobile applications. Branch.io provides a robust and scalable solution for linking, tracking, and analyzing user behavior across platforms.

Why Use Branch.io?

Branch.io offers several features that make it a great alternative to Firebase Dynamic Links:

  1. Deep Linking:

    • Links users to specific content within your app, even if the app is not installed.
    • Supports deferred deep linking (redirecting users to specific content after installing the app).
  2. Attribution and Analytics:

    • Provides accurate attribution for installs, clicks, and in-app events.
    • Tracks user engagement and conversion metrics across campaigns.
  3. Cross-Platform Support:

    • Works seamlessly on Android, iOS, and web platforms.
  4. Customizable Links:

    • Generate branded links with custom domains.
  5. Ease of Integration:

    • SDKs for multiple platforms, including React Native, Swift, Kotlin, and JavaScript.

How to Integrate Branch.io into a React Native App

1. Create a Branch.io Account

  1. Sign up at Branch.io.
  2. Create a new app in the Branch dashboard.
  3. Add your app details (e.g., package name for Android, bundle ID for iOS).

2. Install the Branch React Native SDK

Install the official Branch SDK for React Native:

npm install react-native-branch

yarn add react-native-branch

3. Create Your account on branch.io dashboard by company webmail like asma@panacealogics.com



1. Configure Branch for Android

Manifest File Configuration

Add the following configuration inside the <application> tag in your AndroidManifest.xml:

<!-- Branch App Links - Live App --> <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 `android:host` with your live app.link domain --> <data android:scheme="https" android:host="yourproject.app.link" /> <!-- REPLACE `android:host` with your alternate domain --> <data android:scheme="https" android:host="yourproject-alternate.app.link" /> </intent-filter> <!-- Branch App Links - Test App --> <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="open" /> <!-- REPLACE `android:host` with your alternate domain --> <data android:scheme="https" android:host="yourproject-alternate.app.link" /> </intent-filter> <!-- Branch Metadata --> <meta-data android:name="io.branch.sdk.BranchKey" android:value="your-live-branch-key" /> <meta-data android:name="io.branch.sdk.BranchKey.test" android:value="your-test-branch-key" /> <!-- Branch Receiver --> <receiver android:name="io.branch.referral.InstallListener" android:exported="true"> <intent-filter> <action android:name="com.android.vending.INSTALL_REFERRER" /> </intent-filter> </receiver>

MainActivity Configuration

Add the following in your MainActivity.java or MainActivity.kt:

Import Required Package:

import io.branch.rnbranch.RNBranchModule;

Override Methods:

@Override protected void onStart() { super.onStart(); RNBranchModule.initSession(getIntent().getData(), this); // Initialize Branch session } @Override protected void onNewIntent(Intent intent) { super.onNewIntent(intent); setIntent(intent); RNBranchModule.onNewIntent(intent); // Handle deep linking }

 

MainApplication Configuration

In your MainApplication.java file:

Import Branch:

import io.branch.referral.Branch;

Modify the onCreate Method:

@Override public void onCreate() { super.onCreate(); SoLoader.init(this, /* native exopackage */ false); // Branch Initialization Branch.enableLogging(); // Optional: Enable logging for debugging Branch.getAutoInstance(this); // Initialize Branch }

2. Configure Branch for iOS

Podfile Configuration

In your ios/Podfile, add the Branch pod:


pod 'react-native-branch', path: '../node_modules/react-native-branch'

Run the following command to install pods:


cd ios && pod install

AppDelegate.mm Configuration

In your AppDelegate.mm file:

Import Branch:


#import <RNBranch/RNBranch.h>

Modify the didFinishLaunchingWithOptions Method:


- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { // Initialize Branch NSLog(@"Initializing Branch.io with launch options: %@", launchOptions); [RNBranch initSessionWithLaunchOptions:launchOptions isReferrable:YES]; return YES; }

Info.plist Configuration

Add the following keys to your Info.plist:

<key>branch_key</key> <dict> <key>live</key> <string>your-live-branch-key</string> <key>test</key> <string>your-test-branch-key</string> </dict> <key>branch_universal_link_domains</key> <array> <string>yourproject.app.link</string> <string>yourproject-alternate.app.link</string> </array>
Finally, u have to add a domain in your project from xcode
go to xcode press on sigining & Capabilities
press on + Capability
Search For Associated Domains add your domain from your dashboard of branch
further blog I share the code for u which cases u can deal with it ....



Comments

Popular posts from this blog

Complete Guide to Testing React Native Applications with React Native Testing Library

Ios Push Notification Using Aws Sns

Firebase Setup For Ios And Android In React Native