Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Broadcasting an INSTALL_REFERRER Intent issue

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 don't have any 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"

The response:

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 run the app I get the I/GAV3(17797): Thread[GAThread,5,main]: No campaign data found.

Then I tried the 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 custom receiver: ~/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 response:

Broadcasting: Intent { act=com.android.vending.INSTALL_REFERRER cmp=com.myapp.myapplication/.ReferrerCatcher (has extras) }
Broadcast completed: result=0

Now when I run the app 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 however I am not getting the full referrer. I am just getting the source. Can you please have a look at the code and see if I am making any mistake? I have been struggling with this code for 2 days now.

Thank you in advance.

like image 901
Mr H Avatar asked Aug 15 '14 05:08

Mr H


1 Answers

Short and simple answer. You must encode your referrer information or you only get the first param. You can change the order of params and you'll still get the first param value.

utm_source%3DtestSource%26utm_medium%3DtestMedium%26utm_term%3DtestTerm%26utm_content%3DtestContent%26utm_campaign%3DtestCampaign
like image 134
Trung Nguyen Avatar answered Nov 13 '22 06:11

Trung Nguyen