Skip to main content
7 min read

How to Add Affiliate Tracking to Your React Native App

Step-by-step guide to adding creator and affiliate install attribution to a React Native app using the Appfiliate SDK. Track which creators drive installs and revenue.

A
Appfiliate
How to Add Affiliate Tracking to Your React Native App
The Problem: Creators Are Promoting Your React Native App, But You Can't Attribute Installs

You have creators posting about your app. Some of them are driving real installs. Others are not. Without attribution in your React Native app, you have no way to tell who is actually delivering results. You are paying commissions based on guesswork, or worse, not paying commissions at all because you cannot prove anything.

Adding affiliate tracking to a React Native app fixes this. The SDK runs on first launch, matches the install against recent creator link clicks, and tells you exactly which creator drove that user. If the user later subscribes or makes a purchase, that revenue is attributed to the same creator.

This guide walks through the full integration, from npm install to webhook setup, in about 10 minutes.

Why Affiliate Tracking Matters for React Native Apps

React Native apps have the same attribution gap as native apps. A user taps a link in a creator's Instagram bio, gets redirected to the App Store or Google Play, installs the app, and opens it. By the time your app code runs, the browser session is gone. There is no referrer header, no query parameter, no cookie. The link click and the app open happened in completely different environments.

This is the problem that affiliate tracking SDKs solve. The SDK collects non-identifying device signals on first launch (screen size, timezone, language, OS version) and matches them against recent link clicks on the server side. On Android, the Google Install Referrer API provides a deterministic match. On iOS, probabilistic fingerprint matching fills the gap left by the absence of IDFA.

The result: you know which creator drove each install, without requiring any special permissions, without triggering the ATT prompt, and without adding native modules to your React Native project.

Step 1: Install the Package

Install the Appfiliate SDK and its peer dependency:

npm install appfiliate-react-native @react-native-async-storage/async-storage

AsyncStorage is used to persist attribution state across app launches so the SDK only fires once per install.

The SDK is pure JavaScript/TypeScript. No native modules, no linking, no pod install. It works with React Native 0.72 and above.

Step 2: Configure and Track Installs

Find your app's root component or entry point, typically App.tsx or index.js. Add the SDK initialization there so it runs on every app launch:

import { appfiliate } from 'appfiliate-react-native';

// On app startup (e.g., in useEffect or componentDidMount):
appfiliate.configure({ appId: 'APP_ID_HERE', apiKey: 'API_KEY_HERE' });
const result = await appfiliate.trackInstall();
console.log('Attributed:', result.matched);

Your appId and apiKey are available in your Appfiliate dashboard.

trackInstall() is idempotent. It only fires on the first launch after install. Calling it on every launch is safe and recommended, because it ensures attribution is captured even if the first launch was interrupted.

After trackInstall() completes, you can check attribution status synchronously:

appfiliate.isAttributed;  // boolean
appfiliate.attributionId; // string | null

Step 3: Track Purchases

If your app has in-app purchases, call trackPurchase after every successful transaction:

await appfiliate.trackPurchase({
  productId: 'premium_monthly',
  revenue: 9.99,
  currency: 'USD',
  transactionId: purchase.transactionId,
});

This links the revenue event to the creator who drove the install. In your dashboard, you will see not just installs per creator, but actual revenue generated, which is the number that matters when deciding commission structures and which creators to invest in.

The currency parameter defaults to "USD" if omitted. The transactionId is optional but recommended, as it prevents duplicate revenue tracking if the function is called more than once for the same purchase.

Step 4: Automate with Webhook Integrations

Manual trackPurchase calls work, but if you use a subscription platform, there is a better approach. Appfiliate provides automatic purchase tracking. You can connect your subscription provider’s webhooks to Appfiliate and track purchases, renewals, and cancellations without making a separate call. This is the recommended approach if you use RevenueCat, Superwall, Adapty, Qonversion, or Stripe. Other integrations can be added on request. See the integrations page for the current list.

The setup requires one additional line of code. After trackInstall, set the user’s subscription platform ID:

await appfiliate.setUserId(await Purchases.getAppUserID());

You can also set the subscription platform ID at a later point in the app’s lifecycle if that is more convenient. Appfiliate will handle the storage securely and wait until it is available before sending the automatic install postback.

With the subscription platform ID linked to the user, add the Appfiliate webhook to your subscription provider’s configuration. The Appfiliate dashboard will display a prompt with instructions on how to find the correct webhooks section in the dashboard of your subscription provider.

Once the Appfiliate webhook is connected, every purchase, renewal, and cancellation will be automatically attributed to the creator who drove the original install. No additional code is required. See the full setup instructions on the integrations page.

Testing the Integration

Before you ship to production, make sure to test the integration:

  • Install the app on a test device (or simulator)
  • Verify trackInstall returns a result. In development, result.matched will be false unless you clicked a test creator link on that device first. If you want to test the full flow, create a test creator link in your Appfiliate dashboard, click it on the device, then install and launch the app. result.matched will return true.
  • For purchase tracking, perform a sandbox purchase and verify the event shows up in the Appfiliate dashboard.
The SDK logs are minimal by default, but the AttributionResult object returned by trackInstall gives you everything you need to verify the integration is working:

interface AttributionResult {
  matched: boolean;
  attributionId: string | null;
  confidence: number;
  method: string;
  clickId: string | null;
}

The Complete Integration

Here is the full integration in one place, combining install tracking with automatic purchase attribution:

import React, { useEffect } from 'react'
import { appfiliate } from 'appfiliate-react-native'
import Purchases from 'react-native-purchases'

function App() {
  useEffect(() => {
    async function initAttribution() {
      appfiliate.configure({ appId: 'APP_ID_HERE', apiKey: 'API_KEY_HERE' })
      await appfiliate.trackInstall()
      await appfiliate.setUserId(await Purchases.getAppUserID())
    }
    initAttribution()
  }, [])

  return (
    // your app here
  )
}

That is the entire integration. Three function calls. No native modules, no IDFA, no ATT prompt. The SDK handles the rest. For the full API reference and additional options, see the React Native SDK documentation. Pricing details are on the pricing page.

FAQ

Does the Appfiliate SDK require native modules or linking? No. The SDK is pure JavaScript/TypeScript. It has no native module dependencies, no pod install step, and no manual linking. The only peer dependency is @react-native-async-storage/async-storage, which you likely already have in your project. Does the SDK trigger the ATT prompt on iOS? No. The SDK does not use IDFA or any advertising identifier. Users will never see the “Allow this app to track you?” dialog because of the Appfiliate SDK. Attribution on iOS works through probabilistic fingerprint matching using non-identifying device signals. Can I use webhook integrations instead of calling trackPurchase manually? Yes, and it is the recommended approach if you use RevenueCat, Superwall, Adapty, Qonversion, or Stripe. Call setUserId once with the user’s subscription platform ID, configure the webhook in your subscription platform’s dashboard, and all purchases, renewals, and cancellations are tracked automatically. See the integrations page for setup details. What version of React Native is required? The SDK requires React Native 0.72 or later, with iOS 15+ and Android 5.0+ as the minimum platform targets.