5

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.

Ajay Kumar Meher
  • 1,932
  • 16
  • 24
  • hey ajay. is your problem solved? – Mohit Oct 23 '15 at 12:13
  • play store broadcasts an intent [com.android.vending.INSTALL_REFERRER] at the time of install. So if you are trying to capture any information from the 'launch' intent, it won't be the same. use adb to simulate a broadcast. follow this for testing https://developers.google.com/analytics/solutions/testing-play-campaigns – Rajat Sharma Feb 12 '17 at 16:28

1 Answers1

4

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.

djabi
  • 5,601
  • 18
  • 25
  • I have already made your suggested changes but after first time user install the app, I am getting the receiver callback but when user clicks referral link second time and opens the app, the doc mentioned i will get the info from the intent. But, there is no such information available. Anyways thanks for providing such good implementation. – Ajay Kumar Meher Apr 02 '15 at 18:28
  • I believe the install_referrer intent is only send once when the application is installed. If the application is already installed Google Play store will not broadcast install_referrer again. Its mean to notify the app of the installation. You are looking for deep linking: https://developers.google.com/analytics/solutions/mobile-campaign-deep-link – djabi Apr 06 '15 at 23:56
  • Thanks djabi. I am looking into deep linking and will revert back soon. – Ajay Kumar Meher Apr 07 '15 at 07:03