Pular para o conteúdo principal

Introduction

The Nemu React Native SDK (@usenemu-account/react-native-sdk) lets you integrate Nemu’s attribution and Smart Links system directly into your React Native app. With this SDK you can:
  • Capture install source — know which campaign, source, or medium the user came from (UTMs)
  • Handle direct deep links — when the user clicks a Smart Link and the app is already installed
  • Handle deferred deep links — when the user clicks a Smart Link, installs the app from the store, and opens it for the first time
  • Identify users — associate an ID from your system with the device to cross-reference attribution data
  • Query session history — retrieve UTMs from the user’s latest interaction
The SDK works automatically: once initialized, it intercepts deep links, detects whether this is the first app open, and performs attribution with Nemu’s backend, without requiring manual configuration for each event.

Prerequisites

Private package: @usenemu-account/react-native-sdk is a restricted-access npm package. To install it, you need an npm token provided by the Nemu support team. See the installation section below.

Installation

1. npm token setup

The @usenemu-account/react-native-sdk package is private and published in the npm registry with restricted access. Before installing it, you need to set up authentication.

Get your token

Contact Nemu support to receive your npm access token:

Configure the .npmrc file

In your project root (same directory as package.json), create or edit the .npmrc file:
Replace YOUR_NPM_TOKEN_HERE with the token provided by support.
Security: add .npmrc to your .gitignore so the token is not committed to the repository:
For CI/CD environments, set the token as an environment variable:

2. Package installation

With the token configured, install the SDK:

3. Required dependencies (peer dependencies)

The SDK requires the following libraries as peer dependencies. Install them if they are not already in your project:

Native configuration

iOS

1. Install Pods

After installing JavaScript dependencies, run CocoaPods:
For iOS to route Smart Links directly to the app (without opening the browser), you need to configure Associated Domains. In Xcode:
  1. Open the .xcworkspace project
  2. Select the app target
  3. Go to Signing & Capabilities
  4. Click + Capability and add Associated Domains
  5. Add the domain in this format:
The exact domain will be provided by the Nemu team along with your credentials.

3. Configure URI Scheme (required)

In the Info.plist file, add your app URI scheme:
Replace yourapp with the scheme defined in the Nemu dashboard for your Smart Link.

Android

For Smart Links to open the app directly, add intent filters to your main Activity. In android/app/src/main/AndroidManifest.xml, inside the main <activity> tag: App Links (Android Universal Links):
URI Scheme:
Replace your-domain.nemu.com.br and yourapp with values matching your project.

2. Internet permission (usually already present)

Verify that AndroidManifest.xml includes internet permission:
In most React Native projects this permission is already included by default.

Initialization

SDK initialization must be done only once, in your app root component (usually App.tsx), inside a useEffect.

Configuration parameters

Full initialization example

Using environment variables

To avoid exposing credentials directly in code, use react-native-config or a similar package:
With the corresponding .env:

User identification

After user login in your app, associate their ID with the device. This allows Nemu to correlate attribution data with your user system.

Register user

The SDK stores the ID locally and sends the association to the backend automatically.

Clear user on logout

Note: clearUserId() only removes the local association. Attribution history in the backend is preserved.

The SDK automatically handles two deep link types: They occur when the app is already installed and the user clicks a Smart Link. The operating system opens the app directly (via Universal Link / App Link or URI scheme). The flow is transparent:
  1. User clicks the Smart Link
  2. App opens with the URL
  3. SDK processes the URL and records the session
  4. Listeners registered with onDeepLink are notified with the data
They occur when the app is not installed. The user clicks the Smart Link, is redirected to the store, installs the app, and opens it for the first time. The SDK automatically detects this scenario on first open and returns attribution and deep link data through onDeepLink with isDeferred: true. Register a callback to receive deep link data as soon as it is available:
Automatic replay: if a deep link was already processed before the listener was registered, the callback is triggered immediately with the latest data. This prevents the app from losing the initial deep link.

Imperative query (getDeepLinkData)

If you prefer querying data imperatively instead of using the listener:

DeepLinkData structure


Attribution

Last session history (last touch)

Query UTMs from the user’s most recent interaction. It answers: “what were the UTMs from the last visit?”

Manual UTM history insertion (setSessionHistory)

Use setSessionHistory when you need to record UTMs manually in custom flows (for example, backend-defined campaigns, internal onboarding, or business rules that do not depend on deep links).
Important behavior:
  • utm_source is required; invalid calls are safely ignored
  • The method reuses the SDK’s internal session/history flow (trackEvent)
  • There is deduplication to avoid excessive history creation in repeated calls
  • Execution is asynchronous and resilient (internal failures should not break the app)
When to use: if the source already came from a Smart Link/deep link with valid UTMs, prefer the automatic flow. Use setSessionHistory to complement scenarios not covered by the link.

Example: attaching UTMs to a purchase


WebView integration

When the app embeds web content via WebView and the page needs to consume attribution data (for example, the UTMs returned by getLastSessionHistory), the SDK only runs on the native (React Native) side. For the web page to access this data, you need to create a bidirectional bridge between React Native and the WebView. The most reliable approach combines two mechanisms:
  • Pre-injection: data is exposed as a global variable in the WebView before the content loads
  • On-demand bridge: the web page can request a fresh version of the history at any time
Why not use URL query params? It is the simplest approach, but it has size limits, exposes data in the URL, and does not allow refreshing values without reloading the page. Use it only when data is small and static.

React Native implementation

Consuming on the web side

Inside the page loaded in the WebView, data is available right at load time and can be refreshed on demand:

Important considerations

  • Wait for SDK init before mounting the WebView. Calling getLastSessionHistory() before NemuTracking.init() causes the Promise to be rejected.
  • JSON sanitization: when injecting data into the WebView, always use JSON.stringify. Never interpolate strings directly to avoid XSS if any field comes from an external source.
  • injectedJavaScriptBeforeContentLoaded: requires react-native-webview >= 11. In older versions, use injectedJavaScript (runs after DOM load — a race condition with page scripts may occur).
  • Environment detection: if the same web page also runs outside the WebView (in a browser), treat window.ReactNativeWebView as optional to avoid errors:

Advanced usage

Debug mode

Enable debug mode to view detailed logs of all SDK operations in the console:
Logs will appear prefixed with [NemuSDK] and include information about:
  • Deep link processing
  • Initialization flow
  • Errors and network failures
Important: disable debug mode in production. Logs may contain sensitive information.

Base URL override

In development or staging environments, you can point the SDK to a different API:
baseUrl is only used when isDebugMode is true. In production mode, the SDK always uses the default URL.

Troubleshooting

npm authentication error during installation

Error:
Solution:
  • Check whether the .npmrc file exists in the project root
  • Confirm the token is correct and has not expired
  • Contact Nemu support to validate or renew the token

Error “NemuTracking.init() must be called before using any other method”

Cause: an SDK method was called before initialization. Solution: ensure NemuTracking.init() is called in the root component useEffect before any other SDK method.

pod install fails on iOS

Error:
Solution:
  1. Verify that react-native-keychain is installed as a JavaScript dependency
  2. Run:

Checks:
  • Is Associated Domain configured correctly in Xcode? (format: applinks:your-domain)
  • Is the apple-app-site-association file published and accessible on the domain? (configured by the Nemu team)
  • Is the URI scheme declared in Info.plist?

Checks:
  • Are the intent filters correct in AndroidManifest.xml?
  • Is automatic domain verification enabled (android:autoVerify="true")?
  • Is the assetlinks.json file published on the domain? (configured by the Nemu team)

No attribution data returned

Checks:
  • Are apiKey and trackingId correct?
  • Is the Smart Link configured and active in the Nemu dashboard?
  • Test with isDebugMode: true and check [NemuSDK] logs in the console