AlgorithmX
Integrations3 min read

Install and Start React Native

Install AlgorithmX and configure native startup once per platform, then connect JavaScript without repeating credentials.

Use this page for React Native apps managing their own native projects. Expo users should review the iOS FCM limitation before choosing their push route. Use SDK 1.1.1 or later for the current Firebase adapter on both platforms.

This page connects the SDK to your app's startup. Android and iOS start it early; JavaScript then connects to that same instance. You only need native code here for startup and push delivery. Your customer and screen logic stays in JavaScript.

Have your API base URL and partner ID ready before starting. Replace both example values in the native snippets with the values for the environment you are testing.

1. Install

bash
npm install @algorithmxcloud/react-native-sdk@^1.1.1

Android brings its underlying SDK from Maven Central automatically. On iOS, add this dependency inside your app's target in ios/Podfile:

ruby
target 'YourApp' do
  pod 'AlgorithmXSDK', :git => 'https://github.com/algorithmx-cloud/algorithmx-ios-sdk.git', :tag => '1.1.0'
  # Keep the rest of your existing React Native pods.
end

Then run pod install in ios and rebuild both native apps. The React Native bridge autolinks. The extra iOS dependency line is currently needed because the native SDK is distributed from Git; the bridge's podspec cannot supply that Git source itself.

Check: both apps build before adding the rest of the integration.

2. Start Android before JavaScript

Android can receive a message while no screen is open. Starting the SDK in MainApplication makes it available for that delivery as well as for an ordinary app launch.

Add one initialization call in MainApplication.onCreate, after super.onCreate():

kotlin
import algorithmx.engage.rn.AlgorithmXReactNative

override fun onCreate() {
    super.onCreate()
    AlgorithmXReactNative.initialize(this, "https://api.example.com", "your-partner-id")
    // Keep your existing startup code, including loadReactNative(this).
}

If you need a custom notification icon, add AlgorithmX.setSmallIcon(R.drawable.ic_stat_notification) using algorithmx.engage.core.AlgorithmX. This is optional.

3. Start iOS before JavaScript

The same idea applies on iOS: prepare the SDK before React Native loads your screens, so an early push has somewhere to go.

In AppDelegate.application(_:didFinishLaunchingWithOptions:), before React Native starts:

swift
import AlgorithmXReactNativeSDK

AlgorithmXReactNative.initialize(
    apiBaseUrl: "https://api.example.com",
    partnerId: "your-partner-id"
)

With an existing Notification Service Extension, the optional appGroup: parameter shares configuration with it. It is not required for the basic integration.

Do not replace the SDK's native event listeners with your own native deep-link or custom-action handlers. The React Native bridge owns them and delivers those actions to JavaScript.

Checkpoint: both native entry points now contain your environment configuration. There is no need to repeat those values in every screen. Next, connect the JavaScript layer to them.

4. Connect JavaScript

Register your campaign listeners together at app startup, then call:

ts
import AlgorithmX from '@algorithmxcloud/react-native-sdk';

async function startAlgorithmX() {
  await AlgorithmX.init();
  AlgorithmX.setLoggingEnabled(__DEV__);
}

startAlgorithmX().catch((error) => console.warn('AlgorithmX startup failed', error));

init() reuses native configuration. It rejects with E_INIT if native startup has not run. You no longer repeat the URL and partner ID in JavaScript. The older init(url, partnerId) form remains supported; if native startup already ran, its values must match.

Handle initialization errors in your startup code. A resolved initialization confirms the bridge is connected, not that requests reached your backend.

After init() succeeds, identify a test customer and send one event using the shared JavaScript guide. Check for that event in AlgorithmX. This separates a working bridge from working network delivery.

Next: connect your push route