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%3DsummerAfter 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
The SDK creates an
InstallReferrerClientand connects to the Google Play service.If the connection succeeds, it reads the
ReferrerDetails— including the raw referrer string, click timestamps, and install timestamps.The result is cached after the first successful read. Subsequent calls return the cached result instantly.
If the service disconnects, the SDK retries the connection exactly once before reporting an error.
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 |
|---|---|---|
|
| Raw referrer string from Google Play, e.g. |
|
| Client-side timestamp (seconds) when the referrer click happened |
|
| Client-side timestamp (seconds) when the installation began |
|
| Server-side timestamp (seconds) when the referrer click happened |
|
| Server-side timestamp (seconds) when the installation began |
|
| App version at the time of first install |
|
| 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 foundExtracting 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 nullThe SDK supports two URL path formats:
https://domain.com/shortCode— shortCode onlyhttps://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:
Extracts
clickIdfrom the referrer query parametersExtracts
shortCodeanddltHeaderfrom the referrer URL pathExtracts the
domainfrom the referrer URL hostnameSends 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 |
|---|---|
| Google Play Install Referrer service is currently unavailable |
| Install Referrer API is not supported on this device |
| Developer error while using the Install Referrer API |
| App is not allowed to use the Install Referrer service |
| The service disconnected (after automatic retry attempt) |
| The service connection died unexpectedly |
| Failed to start the connection to the Install Referrer service |