sammiwei
sammiwei

Reputation: 3210

when would broadcast "com.android.vending.INSTALL_REFERRER" get send?

Here is my question My goal is to track app installs from google play. I have a BroadcastReceiver written in my app. So when the app gets downloaded from the goole play, there will be a broadcast "com.android.vending.INSTALL_REFERRER" according to the google page: https://developers.google.com/analytics/devguides/collection/android/v2/campaigns

But my question is the if this happens while my app is getting installed, then how can I initiate my broadcastreceiver which comes with the app, to receive this intent.?

In other words, my logic is that my app has to finish installing in order for me do perform any receiving. Or does it mean, the intent that starts my app for the first time is the "com.android.vending.INSTALL_REFERRER" intent, so that intent gets passed in to my onCreate() function.

I am bit confused here, and dont see like finding some good documentations for this. Anybody point me the right direction? Thanks.

Upvotes: 4

Views: 3663

Answers (2)

sammiwei
sammiwei

Reputation: 3210

"Remember that the rest of your app won’t be running when the receiver is called so usually you record the referrer string somewhere such as SharedPreferences and then when the main app is run gather it up and use analytics libraries. (You certainly don’t want to block processing in the receiver waiting for network connections and similar!)

Reference

Upvotes: 2

Andrew Mackenzie
Andrew Mackenzie

Reputation: 5745

When the app is installed this Intent will be "fired".

If you have a receiver declared in your AndroidManifest.xml with an intent-filter that matches the fired Intent, then that receiver code will be started and passed the Intent. It will not be passed in to the onCreate() of your Application, nor any Activity started later.

<receiver
        android:exported="true"
        android:name="com.yourapp.InstallReceiver">
        <intent-filter>
            <action android:name="com.android.vending.INSTALL_REFERRER" />
        </intent-filter>
</receiver>

In this broadcast receiver code you can parse the Intent received and do whatever you want: e.g. start a background thread and log that info locally or on the network.

The Intent may even contain a "referrer" (i.e. where was the link to the Playstore that causes this download and install?) identifier passed in initially (via an additional parameter on the link to your app in the store). This can be very useful to track the sources of referrals that actually lead to app installations.

Also, the link could contain additional parameters to configure your app, that you process (and store?) in the receiver code, and then read when the app is started later.

Upvotes: 0

Related Questions