If you’ve ever had to work with the Omniture SDK you may eventually be tasked with enabling tracking for campaign referral tracking.
I won’t go into the details of setting up your receivers and doing the SDK setup. That’s pretty well covered in the documentation.
What’s not covered however, is how in the world you would test that.
Never fear! there are a couple of ways actually test this by faking an install event.
First, a word on how the referral is normally processed
Referral tracking happens at installation time, when the apk is installed, a broadcast intent is created by the system and fired sometime after your app has installed and its broadcast receivers registered.
That’s the gist of it. So if your app is properly set up with a broadcast receiver filtering for that intent you should be good to go.
What to do if you need to process the same intent with multiple receivers
You may run into a situation where you already have some other receiver consuming the broadcast. Because you can’t register two receivers for the same intent filter in your manifest, you’ll have to employ a technique called broadcast intent forwarding. You basically select a receiver to get the intent and in its meta-data you specify the next receiver that will receive that intent. I will cover that in more detail later, but I hope you get the idea.
So now on to our two ways of faking the broadcast!
Our friend adb
With a device or emulator connected, you can go into the adb shell and type the following command:
am broadcast -a com.android.vending.INSTALL_REFERRER --es "referrer" "utm_source=test_source&utm_medium=test_medium&utm_term=test_term&utm_ content=test_content&utm_campaign=test_name"
I’ll break the command down with you.
the first parameter -a is the action, in this case an install referrer action
–es is a string extra where the field name is “referrer” and the value consists of all of the referral data from the google campaign.
As a side note, google provides a handy url builder tool to make testing easier: https://support.google.com/analytics/answer/1033867?hl=en
That’s it! that’s all you need to do with this approach.
Create your intent in code
You can create an intent and code and send out a broadcast. This makes it easier to test with unit tests or even manually by a QA person.
// Create an intent to be broadcast containing the referrer url Intent referrerIntent = new Intent(); referrerIntent.setAction("com.android.vending.INSTALL_REFERRER"); referrerIntent.putExtra("referrer", "utm_source=test_source&utm_medium=test_medium&utm_term=test_term&utm_ content=test_content&utm_campaign=test_name"); this.getBaseContext().sendBroadcast(referrerIntent);
A word on testing
You’ll no doubt want to verify that the Omniture is firing off the proper calls. This can be a little tricky because the referral tracking is tied to Omniture’s lifecycle tracking which may not always fire when you expect it to. In order to get lifecycle tracking to fire when you want it to, here’s what you have to do.
- Launch the app.
- Exit the app and clear cache but DO NOT force stop.
- Use method 1 or 2 to broadcast the intent.
- Launch the app
- You should see the request be made into your tracking suite. FYI I use the every awesome and simple Charles Proxy to do this kind of testing. Or when unit testing I just examine the response.
There isn’t very clear documentation on Omniture’s side on how you should be testing this. Manual testing is not feasible because it would mean having to upload to the play store, download the app and hope you did everything right the first time. No es bueno.
The only way to feasibly test is to fake the events and understand a little bit about the process. Hopefully with this humble post, now you do!
Once again my gratitude goes to StackOverflow for helping me find the answer: http://stackoverflow.com/questions/5890914/how-to-test-android-referral-tracking