Sent intent message INSTALL_REFERRER
My Android manifest file
<service android:name="com.google.android.gms.analytics.CampaignTrackingService" /> <receiver android:name="com.google.android.gms.analytics.CampaignTrackingReceiver" android:exported="true" > <intent-filter> <action android:name="com.android.vending.INSTALL_REFERRER" /> </intent-filter> </receiver> I have no other receiver.
Test:
~/development/sdk/platform-tools $ ./adb shell am broadcast -a com.android.vending.INSTALL_REFERRER -n com.myapp.myapplication/com.google.android.gms.analytics.CampaignTrackingService --es "referrer" "utm_source=testSource&utm_medium=testMedium&utm_term=testTerm&utm_content=testContent&utm_campaign=testCampaign" Answer:
Broadcasting: Intent { act=com.android.vending.INSTALL_REFERRER cmp=com.myapp.myapplication/com.google.android.gms.analytics.CampaignTrackingService (has extras) } Broadcast completed: result=0 Now, when I launch the application, I get I/GAV3(17797): Thread[GAThread,5,main]: No campaign data found.
Then I tried a custom receiver: Here is my code:
<service android:name="com.myapp.myapplication.ReferrerCatcher"/> <receiver android:name="com.myapp.myapplication.ReferrerCatcher" android:exported="true"> <intent-filter> <action android:name="com.android.vending.INSTALL_REFERRER" /> </intent-filter> </receiver> And my receiver:
package com.myapp.myapplication; import android.content.BroadcastReceiver; import android.content.Context; import android.content.Intent; import android.os.Bundle; import android.util.Log; import com.google.analytics.tracking.android.CampaignTrackingReceiver; public class ReferrerCatcher extends BroadcastReceiver { private static String TAG = "INSTALL_RECEIVER"; @Override public void onReceive(Context context, Intent intent) { Log.d(TAG, "Received install event"); String referrer = ""; Bundle extras = intent.getExtras(); if(extras != null) { referrer = extras.getString("referrer"); } Log.d(TAG, "Referer is: " + intent + " :: " + extras ); new CampaignTrackingReceiver().onReceive(context, intent); } } And this is my test for the user recipient: ~/development/sdk/platform-tools $ ./adb shell am broadcast -a com.android.vending.INSTALL_REFERRER -n com.myapp.myapplication/com.myapp.myapplication.ReferrerCatcher --es "referrer" "utm_source=testSource&utm_medium=testMedium&utm_term=testTerm&utm_content=testContent&utm_campaign=testCampaign"
And this is the answer:
Broadcasting: Intent { act=com.android.vending.INSTALL_REFERRER cmp=com.myapp.myapplication/.ReferrerCatcher (has extras) } Broadcast completed: result=0 Now when I run the application, this is what I get:
08-15 14:59:38.391: D/INSTALL_RECEIVER(24996): Referer is: Intent { act=com.android.vending.INSTALL_REFERRER flg=0x10 cmp=com.myapp.myapplication/.ReferrerCatcher (has extras) } :: Bundle[{referrer=utm_source=testSource}] Which is better than the last test, but I do not get a full referrer. I just get the source. Could you take a look at the code and see if I am mistaken? I have been struggling with this code for 2 days now.
Thanks in advance.
Short and simple answer. You must encode information about your referrer or receive only the first parameter. You can change the order of the parameters, and you still get the first parameter value.
utm_source%3DtestSource%26utm_medium%3DtestMedium%26utm_term%3DtestTerm%26utm_content%3DtestContent%26utm_campaign%3DtestCampaign