You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

非Google Play分发的Android应用邀请追踪实现方案咨询

Hey there! I’ve built a few referral systems for apps distributed outside Google Play, so I can walk you through the most reliable, actionable approaches here. Let’s break this down step by step:

Core Problem Breakdown

Since we can’t use Google Play’s Install Referrer API, we need two key things:

  1. A way to get the referred_by_user parameter from the invite link to the installed app.
  2. A secure, repeatable process to validate the referral and issue rewards.

First, set up your server to respond to the invite link (https://example.com/download_app?referred_by_user=12345678_john) with a web page that does two things:

  • Automatically triggers the APK download for your app.
  • Prepares to pass the referral code to the app (we’ll cover the "how" in Step 2).

Keep the web page simple: add a clear message like "App downloading! Open it after installation to claim your referral reward."


Step 2: Pass Referral Parameters to the Installed App (Key Part!)

Here are the most practical methods to get the referral code into the app post-installation, ranked by reliability and ease of implementation:

Option 1: Clipboard + Web Page Prompt (Simplest, Works for Most Cases)

When a user clicks the invite link, your web page uses JavaScript to copy the referred_by_user value to the device’s clipboard, then prompts the user about it.

On the app’s first launch:

  • Check the clipboard for a valid referral code pattern (e.g., matches \d{8}_\w+).
  • If found, use it for verification, then clear the clipboard to avoid reprocessing.

Sample Android code to read the clipboard:

val clipboardManager = getSystemService(Context.CLIPBOARD_SERVICE) as ClipboardManager
if (clipboardManager.hasPrimaryClip() && clipboardManager.primaryClip!!.itemCount > 0) {
    val clipboardText = clipboardManager.primaryClip!!.getItemAt(0).text.toString()
    if (clipboardText.matches(Regex("\\d{8}_\\w+"))) {
        // Pass code to your processing logic
        validateAndRewardReferral(clipboardText)
        // Clear clipboard to prevent duplicate processing
        clipboardManager.setPrimaryClip(ClipData.newPlainText("", ""))
    }
}

Pros: No complex server setup, easy to implement.
Cons: Users might clear the clipboard before opening the app; requires clear user instructions.

Option 2: Server-Side Device Matching (Most Reliable)

Tie the referral code to the user’s device before installation:

  1. When a user clicks the invite link, your server captures device identifiers (IP address, user agent, or mobile browser-specific details via JS) and stores them with the referred_by_user code.
  2. On first app launch, send a unique device identifier (e.g., a randomly generated UUID stored in SharedPreferences) to your server.
  3. Your server matches the device data to the earlier click record and returns the referral code.

Pros: Doesn’t rely on user actions; works even if users rename the APK.
Cons: IP-based matching can be inaccurate (e.g., multiple devices on the same network); requires careful handling of device identifiers to avoid privacy issues.

Option 3: Embed Referral Code in APK Filename (Fallback)

Modify your server to generate unique APK filenames per referral (e.g., MyApp_v1.0_referral_12345678_john.apk). After installation:

  1. The app reads its own APK file name.
  2. Parses the filename to extract the referral code.

Sample code to get the APK filename:

val packageManager = packageManager
val packageInfo = packageManager.getPackageInfo(packageName, 0)
val apkPath = packageInfo.applicationInfo.sourceDir
val apkFilename = File(apkPath).name
// Extract referral code from filename
val referralMatch = Regex("referral_(\\d{8}_\\w+)").find(apkFilename)
referralMatch?.groups?.get(1)?.value?.let { referralCode ->
    validateAndRewardReferral(referralCode)
}

Pros: No dependency on browsers or server tracking.
Cons: Users might rename the APK, breaking code extraction; requires generating unique APKs per referral.


Step 3: App-Side Processing & Reward Logic

Once you have the referral code, follow these steps to ensure security and avoid duplicates:

  1. Prevent reprocessing: Store a flag in SharedPreferences (e.g., isReferralProcessed) to ensure the code is only checked once per installation.
  2. Validate with your backend: Send the referral code to your server to confirm 12345678_john is a valid user.
  3. Issue rewards: If valid, your server adds积分 to the referrer’s account and returns a success message to the app.
  4. Update app state: Mark the referral as processed in SharedPreferences so it doesn’t get checked again on subsequent launches.

Critical Security & Reliability Notes
  • Sign referral codes: To prevent tampering, generate a signed version of the code on your server (e.g., referred_by_user=12345678_john&signature=abc123...). Your backend verifies the signature before issuing rewards.
  • Handle edge cases: Decide how to handle multiple referral links clicked by the same user (e.g., use the most recent one) and build that logic into your server.
  • Permissions: For the clipboard method, Android 13+ requires the READ_CLIPBOARD_IN_BACKGROUND permission (declare it in your AndroidManifest.xml).
  • User experience: Add a first-launch popup to inform users: "We found a referral from John! You’ll get X points once you complete setup."

内容的提问来源于stack exchange,提问作者Mayank Kumar

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.28 06:26:11