Learn how to use deferred deep linking to track conversions and traffic.
Deep links require a Pro plan subscription or
higher.
Deferred deep linking allows you to track which link a user came from even when they don’t have your app installed.
When a user clicks a link without the app installed, they’re redirected to the app store. After installing and opening the app, you can retrieve the original link information and redirect them to the appropriate screen.
Android provides the Install Referrer API which allows you to retrieve information about how a user came to install your app, including the referrer URL.Here is how it works in a nutshell:
User taps a deep link on a device without your app installed
Dub redirects the user to the App Store or Play Store by using device targeting
User installs your app from the app store
App reads the install referrer on first launch
App extracts the deep link from the referrer URL and tracks the deep link open event using the /track/open endpoint
Redirect the user to the appropriate screen using the destination URL returned by the /track/open endpoint
When Dub redirects users to the Play Store, the referrer URL contains the deep link information in a nested structure. The referrer URL looks like this:
Now you’ll need to implement the logic to read the install referrer, extract the deep link, and track the deep link open.
Copy
Ask AI
// InstallReferrerTracker.jsimport { PlayInstallReferrer } from "react-native-play-install-referrer";class InstallReferrerTracker { constructor() { this.isFirstLaunch = true; } trackInstallReferrer() { // Check if this is the first launch if (!this.isFirstLaunch) { return; } PlayInstallReferrer.getInstallReferrerInfo((installReferrerInfo, error) => { if (!error) { console.log( "Install referrer = " + installReferrerInfo.installReferrer ); if (installReferrerInfo.installReferrer) { // Extract the deep link from the referrer URL const deepLink = this.extractDeepLinkFromReferrer( installReferrerInfo.installReferrer ); if (deepLink) { // Track the deep link open with the extracted URL this.trackDeepLinkOpen(deepLink); } } } else { console.log("Failed to get install referrer info!"); console.log("Response code: " + error.responseCode); console.log("Message: " + error.message); } this.isFirstLaunch = false; }); } extractDeepLinkFromReferrer(referrerUrl) { try { // Parse the referrer URL to extract the deep link // e.g. for referrer=deepLink%3Dhttps%253A%252F%252Fdub.sh%252Fgps // the deep link is https://dub.sh/gps const referrerUrlObj = new URL(referrerUrl); const deepLinkParam = referrerUrlObj.searchParams.get("deepLink"); return decodeURIComponent(deepLinkParam); return null; } catch (error) { console.error("Error extracting deep link from referrer:", error); return null; } } async trackDeepLinkOpen(deepLink) { try { const response = await fetch("https://api.dub.co/track/open", { method: "POST", headers: { "Content-Type": "application/json", }, body: JSON.stringify({ deepLink, }), }); if (response.ok) { const data = await response.json(); const destinationUrl = data.link.url; // Navigate to the destination URL in your app this.navigateToDestination(destinationUrl); } } catch (error) { console.error("Error tracking deep link open:", error); } } navigateToDestination(destinationUrl) { // Implement your navigation logic here // This will depend on your navigation library (React Navigation, etc.) console.log("Navigating to:", destinationUrl); }}export default InstallReferrerTracker;
First Launch Detection: The install referrer is only available on the first launch after installation. Make sure to track this properly to avoid duplicate tracking.
URL Decoding: The referrer URL is URL-encoded multiple times. Make sure to properly decode it to extract the original deep link.
Network Operations: The tracking API calls should be made on a background thread to avoid blocking the UI.
Error Handling: Always implement proper error handling for network requests and URL parsing.
Testing: Test your implementation thoroughly using the Google Play Console’s internal testing track.
To get started, we recommend using the quickstart guide to set up your deep links on Dub.