Android

Complete guide to reading the Google Play Install Referrer in React Native using the Smler SDK. Parse UTM params, extract short codes, and track clicks.


On Android, the Smler React Native SDK uses the Google Play Install Referrer API to read deferred deep link parameters after a user installs your app from Google Play.

How It Works

When a user clicks a link that redirects to the Google Play Store, the link can include a referrer query parameter:

https://play.google.com/store/apps/details?id=com.yourapp&referrer=utm_source%3Dsmler%26utm_campaign%3Dsummer

After the user installs and opens the app for the first time, the SDK reads this referrer string from Google Play. You can then parse it to extract UTM parameters, short codes, click IDs, or any custom data you encoded in the referrer.

What Happens Under the Hood

  1. The SDK creates an InstallReferrerClient and connects to the Google Play service.

  2. If the connection succeeds, it reads the ReferrerDetails — including the raw referrer string, click timestamps, and install timestamps.

  3. The result is cached after the first successful read. Subsequent calls return the cached result instantly.

  4. If the service disconnects, the SDK retries the connection exactly once before reporting an error.

  5. All pending JavaScript promises are resolved or rejected from the same cached result.

Reading the Install Referrer

import { SmlerDeferredLink } from '@smler/deferred-link';
import type { ReferrerInfo } from '@smler/deferred-link';

try {
  const info: ReferrerInfo = await SmlerDeferredLink.getInstallReferrerAndroid();
  console.log('Raw referrer:', info.installReferrer);
  console.log('Click time:', info.referrerClickTimestampSeconds);
  console.log('Install time:', info.installBeginTimestampSeconds);
} catch (error) {
  console.error('Failed to read install referrer:', error);
}

Important: This method only works on Android. Calling it on iOS will throw an error: "Install Referrer is only available on Android."

ReferrerInfo Fields

Field

Type

Description

installReferrer

string | null

Raw referrer string from Google Play, e.g. "utm_source=foo&utm_medium=bar"

referrerClickTimestampSeconds

number

Client-side timestamp (seconds) when the referrer click happened

installBeginTimestampSeconds

number

Client-side timestamp (seconds) when the installation began

referrerClickTimestampServerSeconds

number

Server-side timestamp (seconds) when the referrer click happened

installBeginTimestampServerSeconds

number

Server-side timestamp (seconds) when the installation began

installVersion

string | null

App version at the time of first install

googlePlayInstantParam

boolean

Whether the app's instant experience was launched in the last 7 days

Parsing Referrer Parameters

The raw installReferrer string is typically URL-encoded query parameters. The SDK provides helpers to parse them:

// Parse all parameters
const params = SmlerDeferredLink.parseReferrerParams(info);
console.log('utm_source:', params.utm_source);
console.log('utm_campaign:', params.utm_campaign);
console.log('referrer:', params.referrer);

// Get a single parameter by key
const uid = SmlerDeferredLink.getReferrerParam(info, 'uid');
console.log('uid:', uid); // Returns empty string if not found

Extracting Short Code & DLT Header

If the referrer contains a Smler short link URL (or its path), you can extract the shortCode and optional dltHeader:

const { shortCode, dltHeader } = SmlerDeferredLink.extractShortCodeAndDltHeader(info);
console.log('Short code:', shortCode);   // e.g. "Ffo6TOPIkd"
console.log('DLT header:', dltHeader);   // e.g. "BKMTCH" or null

The SDK supports two URL path formats:

  • https://domain.com/shortCode — shortCode only

  • https://domain.com/dltHeader/shortCode — dltHeader followed by shortCode

Automatic Click Tracking

If the referrer string contains a clickId query parameter, you can automatically track the click via the Smler API:

const tracking = await SmlerDeferredLink.trackClick(info);

if (tracking) {
  console.log('Click tracked successfully:', tracking);
} else {
  console.log('No clickId found in referrer — nothing to track');
}

The trackClick method:

  1. Extracts clickId from the referrer query parameters

  2. Extracts shortCode and dltHeader from the referrer URL path

  3. Extracts the domain from the referrer URL hostname

  4. Sends all of this to POST https://smler.in/api/v2/track/{clickId}

Returns null if no clickId is present in the referrer string.

Full Android Example

import { Platform } from 'react-native';
import AsyncStorage from '@react-native-async-storage/async-storage';
import { SmlerDeferredLink } from '@smler/deferred-link';

async function handleAndroidDeferredAttribution() {
  if (Platform.OS !== 'android') return;

  // Only run on first install
  const hasRun = await AsyncStorage.getItem('smler_first_install');
  if (hasRun !== null) return;

  try {
    // 1. Read the install referrer
    const info = await SmlerDeferredLink.getInstallReferrerAndroid();
    console.log('Raw referrer:', info.installReferrer);

    // 2. Parse parameters
    const params = SmlerDeferredLink.parseReferrerParams(info);
    console.log('UTM source:', params.utm_source);

    // 3. Extract short code
    const { shortCode, dltHeader } = SmlerDeferredLink.extractShortCodeAndDltHeader(info);

    // 4. Track the click (if clickId is present)
    const trackingResult = await SmlerDeferredLink.trackClick(info);

    // 5. Navigate to the correct screen based on params
    if (shortCode) {
      // Resolve the short link to get the original URL
      const data = await SmlerDeferredLink.resolveDeepLink(
        `https://yourdomain.com/${dltHeader ? dltHeader + '/' : ''}${shortCode}`,
        { triggerWebhook: true }
      );
      // Route to screen based on data.originalUrl
    }
  } catch (error) {
    console.error('Android deferred attribution failed:', error);
  }

  await AsyncStorage.setItem('smler_first_install', 'done');
}

Error Handling

The native module can reject the promise with these error codes:

Error Code

Description

SERVICE_UNAVAILABLE

Google Play Install Referrer service is currently unavailable

FEATURE_NOT_SUPPORTED

Install Referrer API is not supported on this device

DEVELOPER_ERROR

Developer error while using the Install Referrer API

PERMISSION_ERROR

App is not allowed to use the Install Referrer service

SERVICE_DISCONNECTED

The service disconnected (after automatic retry attempt)

DEAD_OBJECT_EXCEPTION

The service connection died unexpectedly

CONNECTION_FAILED

Failed to start the connection to the Install Referrer service

Published with LeafPad