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.
Deferred deep linking on Dub
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 Play Store

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:
  1. User taps a deep link on a device without your app installed
  2. Dub redirects the user to the App Store or Play Store by using device targeting
  3. User installs your app from the app store
  4. App reads the install referrer on first launch
  5. App track the open using the /track/open endpoint
  6. Redirect the user to the appropriate screen using the destination URL returned by the /track/open endpoint

Step 1: Add the Install Referrer dependency

First, you’ll need to add the Google Play Install Referrer library to your project.
// package.json
{
  "dependencies": {
    "@react-native-community/install-referrer": "^2.2.0"
  }
}

Step 2: Implement the Install Referrer logic

Now you’ll need to implement the logic to read the install referrer and track the deep link open.
// InstallReferrerTracker.js
import InstallReferrer from "@react-native-community/install-referrer";

class InstallReferrerTracker {
  constructor() {
    this.isFirstLaunch = true;
  }

  async trackInstallReferrer() {
    try {
      // Check if this is the first launch
      if (!this.isFirstLaunch) {
        return;
      }

      // Get the install referrer
      const referrerDetails = await InstallReferrer.getReferrerDetails();

      if (referrerDetails.referrerUrl) {
        // Track the deep link open with the full referrer URL
        await this.trackDeepLinkOpen(referrerDetails.referrerUrl);
      }

      this.isFirstLaunch = false;
    } catch (error) {
      console.error("Error tracking install referrer:", error);
    }
  }

  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;

Step 3: Initialize the tracker in your app

Now you need to initialize the Install Referrer tracker when your app starts.
// App.js
import React, { useEffect } from 'react';
import InstallReferrerTracker from './InstallReferrerTracker';

const App = () => {
  useEffect(() => {
    const tracker = new InstallReferrerTracker();

    // Track install referrer on app launch
    tracker.trackInstallReferrer();
  }, []);

  return (
    // Your app components
  );
};

export default App;

Step 4: Handle the navigation

Finally, implement the navigation logic to redirect users to the appropriate screen based on the destination URL.
// InstallReferrerTracker.js (navigation method)
navigateToDestination(destinationUrl) {
  // Parse the destination URL to determine which screen to navigate to
  const url = new URL(destinationUrl);
  const path = url.pathname;

  // Example navigation logic
  if (path.includes('/product/')) {
    const productId = path.split('/product/')[1];
    // Navigate to product detail screen
    navigation.navigate('ProductDetail', { productId });
  } else if (path.includes('/category/')) {
    const categoryId = path.split('/category/')[1];
    // Navigate to category screen
    navigation.navigate('Category', { categoryId });
  } else {
    // Navigate to home screen
    navigation.navigate('Home');
  }
}

Important Notes

  1. 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.
  2. Network Operations: The tracking API calls should be made on a background thread to avoid blocking the UI.
  3. Error Handling: Always implement proper error handling for network requests and URL parsing.
  4. 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.

iOS App Store

This feature is coming soon. If you’d like early access, please contact us.