Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to get "referrer" from intent where user clicks on the referral link and opens the pre installed app from playstore

The user has already installed the app via referrer link and installed the app.

When the user clicks again the same referrer link it navigates to PlayStore with open option. The documents Google Analytics Campaign says referring traffic sources or marketing campaigns may be attributed to user activity in subsequent sessions under General Campaign & Traffic Source Attribution

When the user starts the app by selecting open option from PlayStore, I have tried to capture the referrer from intent as per the document as below,

 Intent intent = this.getIntent();
 Uri uri = intent.getData();

The uri itself is null. How to know if user opens the app from PlayStore for first time onwards.

like image 817
Ajay Kumar Meher Avatar asked Sep 28 '22 09:09

Ajay Kumar Meher


1 Answers

You need to register broadcast receiver for "com.android.vending.INSTALL_REFERRER". Play Store will broadcast the campaign data to the receiver once after the app is installed and provide the referrer extra over the intent. If you are trying to get the receiver from your main activity it won't be there.

Analytics provides implementation for the receiver and the accompanying service. Add the following to your ApplicationManifest.xml to register the provided receiver and service:

<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>

You can simulate the broadcast using adb tool:

adb shell am broadcast -a com.android.vending.INSTALL_REFERRER -n your.app.package.name/com.google.android.gms.analytics.CampaignTrackingReceiver --es referrer  "'utm_source=testSource&utm_medium=testMedium&utm_term=testTerm&utm_content=testContent&utm_campaign=testCampaign'"

Note the double '" quotes around the URL. Double quoiting is needed to correctly escape the URL for the Android shell.

like image 78
djabi Avatar answered Oct 10 '22 01:10

djabi