SDK usage
Initialize provider in root of your app
import { DetourProvider, type Config } from "@swmansion/react-native-detour";
const config: Config = {
API_KEY: "<REPLACE_WITH_YOUR_API_KEY>",
appID: "<REPLACE_WITH_APP_ID_FROM_PLATFORM>",
shouldUseClipboard: true,
};
export default function RootLayout() {
return (
<DetourProvider config={config}>
<RootNavigator />
</DetourProvider>
);
}
Keep your API_KEY and appID in .env
Use values from context - Example with Expo Router
SDK exposes useDetourContext() hook that returns object containing information about deferred link and processing status. Our recommendation is to use the hook before you application renders navigation container.
The SDK only looks for a deferred link during the application's first launch after installation. Subsequent launches should be handled by Universal Links for iOS and App Links for Android.
import { useDetourContext } from "@swmansion/react-native-detour";
import * as SplashScreen from "expo-splash-screen";
import { Redirect, Stack } from "expo-router";
SplashScreen.preventAutoHideAsync();
export function RootNavigator() {
const { deferredLinkProcessed, deferredLink, route } = useDetourContext();
useEffect(() => {
if (deferredLinkProcessed) {
SplashScreen.hide();
}
}, [deferredLinkProcessed]);
if (!deferredLinkProcessed) {
return null;
}
if (route) {
return <Redirect href={route} />;
}
return <Stack />;
}
Implementation & lifecycle details (important for integrators)
-
On first app launch after install:
-
provider checks AsyncStorage / persisted flag to determine "first entrance".
-
provider sets an in-memory flag (so remounts in the same process won't trigger extra runs).
-
provider will either:
-
use clickId (if Android install referrer is present) → deterministic match
-
or build ProbabilisticFingerprint → probabilistic match
-
-
-
The hook (useDetourContext) exposes the final state. Wait for deferredLinkProcessed before you attempt to route the user.
-
The SDK aims to make matching fast but you should treat matching as an async step and show a splash/loading state if you need to route to matched content seamlessly.
-
Clipboard: including pastedLink improves match accuracy but may surface a paste permission prompt (iOS). Make this configurable in Config.shouldUseClipboard for UX control.