Broadcasting an INSTALL_REFERRER Intent issue

2019-06-18 23:36发布

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.

2条回答
虎瘦雄心在
2楼-- · 2019-06-19 00:22

You need to change some characters as below: Change %26 —> & %3D —> =

查看更多
爷、活的狠高调
3楼-- · 2019-06-19 00:30

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
查看更多
登录 后发表回答