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
Prerequisites
| Requirement | Minimum version |
|---|---|
| React Native | >= 0.70.0 |
| React | >= 17.0.0 |
| Node.js | >= 16 LTS |
| npm or Yarn | Version compatible with Node 16+ |
| iOS | CocoaPods support |
| Android | API 21+ (Android 5.0) |
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:- Email: suporte@nemu.com.br
- Website: nemu.com.br
Configure the .npmrc file
In your project root (same directory as package.json), create or edit the .npmrc file:
YOUR_NPM_TOKEN_HERE with the token provided by support.
Security: add.npmrcto your.gitignoreso 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:| Dependency | Minimum version | Purpose |
|---|---|---|
@react-native-async-storage/async-storage | >= 1.17.0 | Local storage for session and attribution data |
react-native-keychain | >= 8.0.0 | Secure device identifier storage |
react-native-device-info | >= 10.0.0 | Retrieves device information |
Native configuration
iOS
1. Install Pods
After installing JavaScript dependencies, run CocoaPods:2. Configure Universal Links (required for direct deep links)
For iOS to route Smart Links directly to the app (without opening the browser), you need to configure Associated Domains. In Xcode:- Open the
.xcworkspaceproject - Select the app target
- Go to Signing & Capabilities
- Click + Capability and add Associated Domains
- 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 theInfo.plist file, add your app URI scheme:
yourapp with the scheme defined in the Nemu dashboard for your Smart Link.
Android
1. Configure Deep Links in AndroidManifest.xml
For Smart Links to open the app directly, add intent filters to your mainActivity.
In android/app/src/main/AndroidManifest.xml, inside the main <activity> tag:
App Links (Android Universal Links):
your-domain.nemu.com.br and yourapp with values matching your project.
2. Internet permission (usually already present)
Verify thatAndroidManifest.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 (usuallyApp.tsx), inside a useEffect.
Configuration parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
apiKey | string | Yes | API key obtained from the Nemu dashboard |
uriScheme | string | Yes | App URI scheme (ex: "yourapp"). Must match the value configured in Smart Link |
trackingId | string | Yes | Tracking ID associated with the app in the Nemu dashboard |
isDebugMode | boolean | No | Enables detailed console logs. Default: false |
baseUrl | string | No | Overrides the API base URL |
Full initialization example
Using environment variables
To avoid exposing credentials directly in code, usereact-native-config or a similar package:
.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
Clear user on logout
Note: clearUserId() only removes the local association. Attribution history in the backend is preserved.
Deep Links
The SDK automatically handles two deep link types:Direct deep links
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:- User clicks the Smart Link
- App opens with the URL
- SDK processes the URL and records the session
- Listeners registered with
onDeepLinkare notified with the data
Deferred deep links
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 throughonDeepLink with isDeferred: true.
Reactive listener (onDeepLink)
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).
| Parameter | Type | Required | Description |
|---|---|---|---|
utm_source | string | Yes | Campaign source |
utm_medium | string | null | No | Media/channel |
utm_campaign | string | null | No | Campaign name |
utm_content | string | null | No | Creative content |
utm_term | string | null | No | Additional term |
utm_sourceis 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 bygetLastSessionHistory), 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.
Recommended strategy
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
initbefore mounting the WebView. CallinggetLastSessionHistory()beforeNemuTracking.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: requiresreact-native-webview>= 11. In older versions, useinjectedJavaScript(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.ReactNativeWebViewas optional to avoid errors:
Advanced usage
Debug mode
Enable debug mode to view detailed logs of all SDK operations in the console:[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:baseUrlis only used whenisDebugModeistrue. In production mode, the SDK always uses the default URL.
Troubleshooting
npm authentication error during installation
Error:- Check whether the
.npmrcfile 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: ensureNemuTracking.init() is called in the root component useEffect before any other SDK method.
pod install fails on iOS
Error:
- Verify that
react-native-keychainis installed as a JavaScript dependency - Run:
Deep links do not work on iOS
Checks:- Is Associated Domain configured correctly in Xcode? (format:
applinks:your-domain) - Is the
apple-app-site-associationfile published and accessible on the domain? (configured by the Nemu team) - Is the URI scheme declared in
Info.plist?
Deep links do not work on Android
Checks:- Are the intent filters correct in
AndroidManifest.xml? - Is automatic domain verification enabled (
android:autoVerify="true")? - Is the
assetlinks.jsonfile published on the domain? (configured by the Nemu team)
No attribution data returned
Checks:- Are
apiKeyandtrackingIdcorrect? - Is the Smart Link configured and active in the Nemu dashboard?
- Test with
isDebugMode: trueand check[NemuSDK]logs in the console