Learn how to set up mobile app referral attribution
This guide explains how to add referral tracking capabilities to your existing attribution links without creating new ones. In this guide, we’ll use Branch.io as an example. The implementation is similar if you use other attribution libraries like AppsFlyer, Singular or Adjust.
Mobile attribution builds on top of web attribution since users typically click referral links on web before downloading your app. The web setup captures the initial referral code that will later be attributed to the mobile app installation and signup.
Instead of creating new links for each referrer, you’ll append referral data to your existing Branch.io (or other attribution library) app install link:
When a user clicks the referral link, Branch.io stores the referral data (including the referral_ucc) in their servers and associates it with the user’s device fingerprint. This allows the data to persist through:
import Branchclass AppDelegate: UIResponder, UIApplicationDelegate { func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool { Branch.getInstance().initSession(launchOptions: launchOptions) { (params, error) in // Check if the user came from a Branch link if let clickedBranchLink = params?["+clicked_branch_link"] as? Bool, clickedBranchLink { // Extract referral code if let referralCode = params?["referral_ucc"] as? String { print("Referral Code: \(referralCode)") // Store for use during signup UserDefaults.standard.set(referralCode, forKey: "pending_referral_code") } } } return true }}
class MainActivity : AppCompatActivity() { override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) Branch.getAutoInstance(this).initSession({ branchUniversalObject, linkProperties, error -> if (error == null) { // Check if user came from Branch link if (linkProperties?.has("+clicked_branch_link") == true) { // Get referral code val referralCode = linkProperties.get("referral_ucc") referralCode?.let { Log.d("Branch", "Referral Code: $it") // Store for signup getSharedPreferences("app_prefs", Context.MODE_PRIVATE) .edit() .putString("pending_referral_code", it) .apply() } } } }, this.intent.data, this) }}