Implementing a Referral Program in Mobile Apps
A referral program is attribution on the mobile platform, not just "share a link". The main technical challenge: linking app installation to a specific referrer when days can pass between clicking the link and opening the app, and devices can change.
Deep linking and deferred deep linking
Regular deep link doesn't work: if the app is not installed, the user lands in App Store and the link is lost. You need a deferred deep link — a mechanism where the link is "remembered" and passed to the app on first launch after installation.
Tools: Branch.io, Firebase Dynamic Links (deprecated from 2025, not recommended for new projects), AppsFlyer OneLink, Adjust. Branch is most universal.
// iOS — Branch SDK
Branch.getInstance().initSession(launchOptions: launchOptions) { params, error in
if let referrerID = params?["referrer_id"] as? String {
// First launch with referral parameter
ServerAPI.attributeInstall(referrerID: referrerID, newUserID: currentUser.id)
}
}
Branch tracks link clicks via fingerprinting (IP + User-Agent + time) and matches with installation in a 2-hour window. Accuracy ~85-95% — not 100%, but sufficient for business metrics.
Generating referral links
Each user gets a unique short link:
let linkProperties = BranchLinkProperties()
linkProperties.channel = "app_share"
linkProperties.feature = "referral"
let universalObject = BranchUniversalObject(canonicalIdentifier: "referral/\(userID)")
universalObject.contentMetadata.customMetadata["referrer_id"] = userID
universalObject.getShortUrl(with: linkProperties) { url, error in
self.referralLink = url
}
On Android — similarly through Branch SDK for Android.
Attribution and bonus crediting
After successful attribution (new user installed and opened app) — server logic:
- Check that
new_user_idis truly new (no previous sessions, no device fingerprint match with existing accounts — to protect against fraud via reinstalls) - Create record in
referral_attributions: referrer_id, referred_id, attributed_at, status=pending - Credit bonus to referrer only after condition is met — for example, after first purchase of referral or after 7 days of activity
Cannot credit early: user installs, gets bonus for referrer, uninstalls — this is garbage traffic.
Conditions and anti-fraud
Basic protections: one referral bonus per device (device_id), limit on referrals per month, minimum account age for referrer to participate (e.g., 7 days).
For serious volumes — integrate with anti-fraud service (Adjust Fraud Prevention, Branch Fraud Protection): they check behavioral patterns and emulator signals.
Screens in app
Referral program page: current referral bonus balance, number of invited, history of credits, "Share" button with native share sheet.
Estimated time — 3–5 days: Branch SDK integration (iOS + Android), server attribution logic, basic anti-fraud, UI screens.







