React Native SDK
The React Native SDK is in beta. Its API may change between 0.x releases, so pin an exact version (@linksense-net/react-native@0.3.0) in production and test before upgrading.
Overview
@linksense-net/react-native is an Expo Module over the native iOS and Android SDKs (0.3.0). It gives you:
- Deferred deep linking — the link a user tapped before installing your app, returned on first launch.
- App-open reporting — every Universal Link / App Link that opens your app shows in your LinkSense analytics, with no AppDelegate or MainActivity code.
- Paste-to-attribute on iOS, with no system paste prompt.
- Link CRUD — create, read, update and delete dynamic links from the device.
Prerequisites
- Expo SDK 53 or later, or bare React Native 0.79+ with Expo Modules installed (see Bare React Native)
- A development build or EAS Build. Expo Go cannot load the native code.
- iOS 16+ and Android API 24+
- An SDK key from your LinkSense project (open your project's SDK Keys tab)
- Your iOS app (Team ID) and Android app (SHA-256 fingerprint) added to the project, so LinkSense can serve the
.well-knownfiles (see iOS and Android deep linking)
Installation
npx expo install @linksense-net/react-native expo-build-propertiesThen rebuild your development client (npx expo run:ios / run:android, or a new EAS build).
App Config
Add your link domain for Universal Links and App Links, and raise the iOS deployment target to 16. Replace your-project with your project subdomain, and use the bundle ID and package name registered in LinkSense.
{ "expo": { "ios": { "bundleIdentifier": "com.example.app", "associatedDomains": ["applinks:your-project.linksense.net"] }, "android": { "package": "com.example.app", "intentFilters": [ { "action": "VIEW", "autoVerify": true, "data": [{ "scheme": "https", "host": "your-project.linksense.net" }], "category": ["BROWSABLE", "DEFAULT"] } ] }, "plugins": [ ["expo-build-properties", { "ios": { "deploymentTarget": "16.0" } }] ] }}The module hooks Universal Link and App Link delivery itself, so there is no AppDelegate or MainActivity code and no config plugin to add.
Bare React Native
app.json and expo-build-properties only apply to Expo-managed projects. In a bare React Native app, install Expo Modules first, then the package and its pods:
npx install-expo-modules@latestnpm install @linksense-net/react-nativecd ios && pod install- iOS deployment target — set
platform :ios, '16.0'inios/Podfile(and the app target in Xcode);pod installfails on anything lower. - Associated Domains — in Xcode, add the capability with
applinks:your-project.linksense.net. - App Links — add the intent filter below to your main activity in
android/app/src/main/AndroidManifest.xml, and make sureminSdkVersionis at least 24.
<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="your-project.linksense.net" /></intent-filter>As with Expo, there is no AppDelegate or MainActivity code to write.
Configuration
import { useEffect } from 'react';import { Stack, useRouter } from 'expo-router';import LinkSense from '@linksense-net/react-native'; export default function RootLayout() { const router = useRouter(); useEffect(() => { (async () => { // Once, as early as possible. await LinkSense.configure({ sdkKey: process.env.EXPO_PUBLIC_LINKSENSE_SDK_KEY! }); // First launch: the link that led to this install, or null. Later launches: null. const deepLink = await LinkSense.start(); if (deepLink) { router.push(new URL(deepLink).pathname); } })(); }, [router]); return <Stack />;}Configuration fields:
| Field | Type | Required | Description |
|---|---|---|---|
sdkKey | string | Required | Your project SDK key (format: ls_sdk_<8 hex>_<32 hex>). Generate one in your project's SDK Keys tab. It is publishable, so an EXPO_PUBLIC_ variable is fine. |
enableClipboard | boolean | Optional | iOS only. Read the clipboard once on first launch for attribution (shows the iOS paste prompt). Default false; see Paste-to-Attribute for a prompt-free alternative. |
enableInstallReferrer | boolean | Optional | Android only. Read the Google Play Install Referrer for high-confidence attribution. Default true. |
enableFingerprint | boolean | Optional | Android only. Send the probabilistic fingerprint used when no Install Referrer click is available. Default true. |
Handling Deferred Deep Links
start() reports the install on first launch and resolves with the matched link, or null for an organic install. On later launches it resolves null without reporting again. Repeated calls return the same promise. It does not reject on a network failure — an install that couldn't be reported resolves null and is retried on a later launch.
On Android the Play Install Referrer gives an exact match when the app came from Google Play. Otherwise, and on iOS, LinkSense matches the install to the click by device fingerprint within the attribution window.
Universal Links & App Links
The module observes every link that opens your app and reports it to LinkSense, so opens show in your analytics. It only observes: keep routing links with Expo Router or expo-linking as usual. A link that cold-launches the app before configure runs is held and reported once you configure. To also receive the URL LinkSense resolved:
const unsubscribe = LinkSense.onDeepLink(url => { // Analytics or logging. Keep routing in Expo Router / expo-linking.});Paste-to-Attribute (iOS)
On iOS 16+ reading the clipboard shows a system prompt. If your onboarding has a "paste your invite link" field, pass the text and LinkSense attributes the install with no prompt:
// From your own "paste your invite link" field. No iOS paste prompt.const deepLink = await LinkSense.submitPastedLink(text); // always null on Android (Install Referrer covers it)Link CRUD
createLink(options), getLink(id), updateLink(id, options) and deleteLink(id) return promises; the first three resolve to a LinkSenseLink. Options and the link model use the same field names as the native SDKs: name, slug (create only), desktopUrl, iosFallbackUrl, androidFallbackUrl, ogTitle, ogDescription, ogImageUrl, tags, iosClipboardEnabled and metadata.
import LinkSense, { CLEAR } from '@linksense-net/react-native'; const link = await LinkSense.createLink({ name: 'Invite from Maria', tags: ['invite'], metadata: { inviterId: 'u_123' },});share(link.fullUrl); await LinkSense.updateLink(link.id, { ogTitle: 'Join Maria on Acme', desktopUrl: CLEAR });await LinkSense.deleteLink(link.id);In updateLink, leave a field undefined to keep it, pass a value to set it, or pass CLEAR to null it server-side. name, tags and iosClipboardEnabled cannot be cleared.
Error Handling
Methods reject with a LinkSenseError carrying a code. Errors from the link CRUD methods also carry the HTTP status, retryAfterSeconds (when the server sent Retry-After), fieldErrors for validation errors, and accessDenied (serverMessage, upgradeRequired, plan, currentUsage, limit) for ACCESS_DENIED. Link calls go to the same LinkSense host as the native SDK build.
import LinkSense, { LinkSenseError } from '@linksense-net/react-native'; try { await LinkSense.createLink({ name: 'Invite', slug: 'maria' });} catch (error) { if (error instanceof LinkSenseError) { switch (error.code) { case 'SLUG_EXISTS': // pick another slug break; case 'ACCESS_DENIED': if (error.accessDenied?.upgradeRequired) showUpgrade(error.accessDenied.plan); break; case 'INVALID_INPUT': console.warn(error.fieldErrors); // { slug: 'slug cannot use reserved words' } break; case 'RATE_LIMITED': console.warn(`retry after ${error.retryAfterSeconds}s`); break; } }}Codes: INVALID_SDK_KEY (thrown by configure), NOT_CONFIGURED, NETWORK, DECODE_FAILURE, UNAUTHORIZED (the key was rejected), NOT_FOUND, SLUG_EXISTS, INVALID_INPUT, FORBIDDEN_FIELD, FORBIDDEN_CROSS_SCOPE, ACCESS_DENIED (your plan blocked the call, or the key isn't allowed on this platform), RATE_LIMITED, and UNKNOWN. Any other server code comes through verbatim, or as HTTP_<status> when the response had no code.