How to test android referral tracking?
Solution 1
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
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
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
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
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.
Related videos on Youtube
emmby
Author of Android Application Development for Dummies. Author of RoboGuice, as well as the OpenTable, TripIt, and Digg Android applications. bebop Mobile at Google http://about.me/michaelburton
Updated on March 20, 2020Comments
-
emmby over 4 years
I'm implementing some code to do my own referral tracking on downloads from the Android market.
See 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?
-
kreker about 5 years
-
-
Khan about 12 yearswhat sample output u get can u add here
-
Khan about 12 years@pjv i have test app get output but if i donwload app from play store than output is null can u exmplain little bit more
-
pjv about 12 years@Khan, yeah, mine also has issues in real life, even problems in general with Google Analytics. Especially when you have a complex app and maybe more than one BroadcastReceiver.
-
Geert Weening almost 12 yearsIf you use a static inner class as a BroadCastReceiver you have to escape the dollar sign. In my case I had to leave out the dot before the path up to the BroadCastReceiver. "am broadcast -a com.android.vending.INSTALL_REFERRER -n app.test/app.util.AndroidUtil\$TestBroadCastReceiver"
-
bkurzius about 11 yearsAfter lots of trial and error I found that if your Receiver is in a library, you need to omit the . after / -- so the example would look like this: adb shell am broadcast -a com.android.vending.INSTALL_REFERRER -n <your.package>/<full.path.in.library.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"
-
Luigi Agosti about 11 yearsit is my app and is open source so it is not like I'm trying to sell it github.com/giago/referraltester
-
JRun about 11 yearsSo put it on the play store for free :-)
-
Luigi Agosti about 11 yearsyou can download the code and deploy it on your phone... if you are lazy you pay, I think is fair enough
-
JRun about 11 yearsGave you a +1.Too lazy to build yet another project but still gave you a +1 for figuring it out. :-)
-
anticafe almost 10 years+1 for
adb shell <enter> am broadcast..
. I typeadb shell am broadcast...
by mistake and it doesn't output anything. -
Harry over 9 yearsWhen I tried using my own custom receiver, it's working when running the test above, but not in the real implementation. After having my app published on Play Store, I failed to get the referrer parameters. I wonder if Analytics Receiver has to be used instead. But then, how to collect the referral data?
-
KP_ over 8 years@pjv When i used it in live app, (not set) is shown in analytics.So is there something wrong in my development side?
-
KP_ over 8 yearsIm getting "not set" as medium , campaign value in analytics dashboard.Only source name is displayed .Can you figure out what may be the problem?
-
Atul O Holic over 8 yearsHow did you get 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
-
Nati Dykstein over 8 yearsAn important note is that all the ampersands(&) inside the referrer string should be prefixed with backspace () or else the string will be terminated at the first ampersand and won't reach the broadcast receiver. (resulting in only getting the first pair in this case "utm_source=utm_test")
-
a54studio about 8 yearsI battled with this too. The issue for me was is we were changing the package name to add the suffix .dev in the gradle for the build. I was trying to use that modified package name since that was essentially the new name. I was also running it as a debug build. It would successfully show in adb, but never trigger in the app. Once I tried it with the non modified package name in the production version, it triggers every time.
-
Utsav Gupta almost 8 years"But your BroadcastReceiver may need to be the AnalyticsReceiver" what do you mean by that ? What If I wantto have my own custom reciever
-
CorayThan over 7 yearsI found it easier to leave out the package specifier. Your app will still receive it. It's just other apps could too.
-
Khizar Hayat over 6 yearsIn my case adb shell and am command in one line is working with enter its not working.
-
Rahul Bansal almost 6 yearshow to send this campaign data to google analytics console using my tracking id?
-
Sachin Chandil over 5 yearsI had to use full package string to get it to work. i.e.
net.lp.collectionista/net.lp.collectionista.util.broadcast_receivers.FacadeBroadcastReceiver
. -
Rumit Patel over 5 yearslink broken => market.android.com/…
-
Jacky Chong over 3 yearsClear and save my day