Skip to main content

Referral Tracking in Your Android App

Gameball referrals rely on Firebase Dynamic Links to track when an existing customer invites a new customer. Implementing referral tracking allows you to reward both the referrer and the referred customer based on your Gameball referral program rules.

Setup Requirements

1

Configure Firebase Dynamic Links

Set up Firebase Dynamic Links in your Firebase console and configure your app to receive deep links.
2

Add Dynamic Links Dependency

Add the Firebase Dynamic Links library to your build.gradle:
dependencies {
    implementation 'com.google.firebase:firebase-dynamic-links'
}
3

Configure Referral Settings in Gameball Dashboard

In the Gameball dashboard, provide your Firebase Dynamic Links domain and configuration.

Your app must capture the referral code from the Firebase Dynamic Link and store it until registration.
class MainActivity : AppCompatActivity() {

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)

        Firebase.dynamicLinks
            .getDynamicLink(intent)
            .addOnSuccessListener { pendingDynamicLinkData ->
                val deepLink = pendingDynamicLinkData?.link

                val referralCode = deepLink?.getQueryParameter("referralCode")

                if (referralCode != null) {
                    saveReferralCode(referralCode)  // Store locally
                }
            }
    }
}
Store the referral code locally (e.g., SharedPreferences) and use it during customer initialization.

Registering a Customer with a Referral Code

Include the stored referral code when registering or identifying the customer.
val customerRequest = InitializeCustomerRequest.builder()
    .customerId("customer-123")
    .email("customer@example.com")
    .referralCode(savedReferralCode)   // Attach referral code
    .build()

GameballApp.getInstance(context).initializeCustomer(
    customerRequest,
    object : Callback<InitializeCustomerResponse> {
        override fun onSuccess(response: InitializeCustomerResponse) {
            // Customer registered with referral applied
        }

        override fun onError(error: Throwable) {
            // Handle error
        }
    }
)

Use this to show the unique referral link that customers can share.
GameballApp.getInstance(context).getCustomerReferralInfo(
    "customer-123",
    object : Callback<ReferralInfo> {
        override fun onSuccess(referralInfo: ReferralInfo) {
            val referralLink = referralInfo.referralLink
            showShareDialog(referralLink)
        }

        override fun onError(error: Throwable) {
            // Handle error
        }
    }
)

Enable sharing via Android’s standard share sheet:
fun shareReferralLink(referralLink: String) {
    val shareIntent = Intent(Intent.ACTION_SEND).apply {
        putExtra(Intent.EXTRA_TEXT, "Join me on our app! Use my referral link: $referralLink")
        type = "text/plain"
    }

    startActivity(Intent.createChooser(shareIntent, "Share referral link"))
}

Full Referral Flow

1

Customer A Retrieves Their Referral Link

The existing customer receives their unique referral link.
2

Customer A Shares Referral Link

They share it via social media, messaging apps, etc.
3

Customer B Opens the Link

The new customer taps the link and installs/opens the app.
4

App Captures Referral Code

Firebase Dynamic Links provides the deep link with referralCode.
5

Customer B Registers

The referral code is included during registration.
6

Gameball Rewards Both Users

Based on your program settings in the Gameball dashboard.
Referral rewards and rules are fully configurable in your Gameball dashboard.

AndroidManifest Configuration

Add an intent filter to allow your app to receive Firebase Dynamic Links:
<activity android:name=".MainActivity">
    <intent-filter>
        <action android:name="android.intent.action.VIEW" />
        <category android:name="android.intent.category.DEFAULT" />
        <category android:name="android.intent.category.BROWSABLE" />
        <data
            android:host="yourdomain.page.link"
            android:scheme="https" />
    </intent-filter>
</activity>