How to test android referral tracking?

AndroidGoogle AnalyticsGoogle PlayReferrer

Android Problem Overview


I'm implementing some code to do my own referral tracking on downloads from the Android market.

See https://stackoverflow.com/questions/4660044/android-referral-tracking-does-not-work for an idea of what my app is doing.

How can I test if this code is working before deploying to the public?

Android Solutions


Solution 1 - Android

The easiest way is using adb. You don't have to write any code.

Just run in a terminal:

adb shell 
am broadcast -a com.android.vending.INSTALL_REFERRER -n <your.package>/.<path.up.until.your.BroadcastReceiver> --es "referrer" "utm_source=test_source\&utm_medium=test_medium\&utm_term=test_term\&utm_content=test_content\&utm_campaign=test_name"

Here's my exact line:

am broadcast -a com.android.vending.INSTALL_REFERRER -n net.lp.collectionista/.util.broadcast_receivers.FacadeBroadcastReceiver --es "referrer" "utm_source=test_source\&utm_medium=test_medium\&utm_term=test_term\&utm_content=test_content\&utm_campaign=test_name"

But your BroadcastReceiver may need to be the AnalyticsReceiver, i.e.

For Google Analytics v2:

> com.your.package/com.google.analytics.tracking.android.CampaignTrackingReceiver

For Google Analytics v3:

> com.your.package/com.google.android.apps.analytics.AnalyticsReceiver

For Google Analytics v4:

> com.your.package/com.google.android.gms.analytics.CampaignTrackingReceiver

As Luigi said, you can also leave out the "-n" componentname part, but then every app on your device will receive the referral. This can be a good extra test to see if your BroadcastReceiver can be found properly.

The output I see (especially the last line is important):

05-13 17:28:08.335: D/Collectionista FacadeBroadcastReceiver(8525): Receiver called
05-13 17:28:08.335: V/Collectionista FacadeBroadcastReceiver(8525): Receiver called with action: com.android.vending.INSTALL_REFERRER
05-13 17:28:08.365: D/GoogleAnalyticsTracker(8525): Stored referrer:utmcsr=test_source|utmccn=test_name|utmcmd=test_medium|utmctr=test_term|utmcct=test_content

Solution 2 - Android

No! you have a few way to test it Send a broadcast manually with an intent of this form

    Intent i = new Intent("com.android.vending.INSTALL_REFERRER");
    //Set Package name
    i.setPackage("com.package.yourapp");
    //referrer is a composition of the parameter of the campaing
    i.putExtra("referrer", referrer);
    sendBroadcast(i);

Solution 3 - Android

None of the above commands works for me. After trying a lot of commands combinations here is the one that works for me:

./adb shell am broadcast -a com.android.vending.INSTALL_REFERRER -n <your package>/<your package>.<your BroadcastReceiver> --es "referrer" "utm_medium%3Dpartner%26utm_campaign%3Dpartner_name"

Note: the referrer should be url encoded.

Solution 4 - Android

pjv's answer works in the case where the package name in AndroidManifest.xml matches the applicationId in build.gradle. If they don't match, do the following:
Given:
applicationId is com.my.app.debug
package is com.package.app
receiver is path.to.MyReceiver
then broadcast to com.my.app.debug/com.package.app.path.to.MyReceiver
Details here: https://groups.google.com/forum/#!topic/adt-dev/PjTHX79Iomw

Solution 5 - Android

Found a nice open-source tool that lets you scan the referral qrcode that you generate here, and it sends a broadcast intent with all the correct information.

https://github.com/giago/referraltester

Solution 6 - Android

https://github.com/rogerbinns/referraltester here is a great app for initiate "com.android.vending.INSTALL_REFERRER" broadcast. you can input parameters as well.

Solution 7 - Android

For me extras added to the intent only when adding with "-e" instead of "--es". Might be my ad version issue. So my command is ./adb shell am broadcast -a com.android.vending.INSTALL_REFERRER -n <your package>/<your package>.<your BroadcastReceiver> -e "referrer" "utm_medium%3Dpartner%26utm_campaign%3Dpartner_name"

Solution 8 - Android

Goople Play receives an APP link and asks the user to click to download, and Google Play sends a broadcast when the download is complete. APP link will usually take some parameters (such as the following example) to let Google Play and APP know where the source comes from.

Https://play.google.com/store/apps/details?id=com.example.application
& Referrer = utm_source% 3Dgoogle
% 26utm_medium% 3Dcpc
% 26utm_term% 3Drunning% 252Bshoes
% 26utm_content% 3Dlogolink
% 26utm_campaign% 3Dspring_sale

So we can use adb to simulates the broadcast from Google Play.

echo 'am broadcast \
    -a com.android.vending.INSTALL_REFERRER \
    -n "com.google.samples.quickstart.analytics/com.google.android.gms.analytics.CampaignTrackingReceiver" \
    --es "referrer" \
      "utm_source=test_sourceCampaignTrackingReceiver&utm_medium=referral&utm_term=test_term&utm_content=test_content&utm_campaign=test_name"; \
    exit' | adb shell

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionemmbyView Question on Stackoverflow
Solution 1 - AndroidpjvView Answer on Stackoverflow
Solution 2 - AndroidLuigi AgostiView Answer on Stackoverflow
Solution 3 - AndroidPabloView Answer on Stackoverflow
Solution 4 - AndroidAtomicBooleanView Answer on Stackoverflow
Solution 5 - AndroidGyuriView Answer on Stackoverflow
Solution 6 - AndroidsammiweiView Answer on Stackoverflow
Solution 7 - AndroidSojan P RView Answer on Stackoverflow
Solution 8 - AndroidWeiYuanView Answer on Stackoverflow