Skip to content Skip to sidebar Skip to footer

Google Analytics / Campaign Measurement

I am not able to understand one thing in Google Analytics. I need a functionality in my app like if A user refer my app to B user then he got some rewards but I want to track A use

Solution 1:

Create a Broadcast receiver with following code:

publicclassCampaignBroadCastReceiverextendsBroadcastReceiver {
    @OverridepublicvoidonReceive(Context context, Intent intent) {
       String referrer= intent.getExtras().getString("referrer", ""); //your referrernew com.google.android.gms.analytics.CampaignTrackingReceiver().onReceive(context, intent); //update the same to Google Analytics  
    }
}

In your manifest:

<serviceandroid:name="com.google.analytics.tracking.android.CampaignTrackingService" /><receiverandroid:name="yourpackage.CampaignBroadCastReceiver"><intent-filter><actionandroid:name="com.android.vending.INSTALL_REFERRER" /></intent-filter></receiver>

Solution 2:

I haven't tried this out yet. But according to the documentation available on Google Analytics Campaign Tracking. The following code should work inside your main activity onCreate or onStart

// Get the intent that started this Activity.Intentintent=this.getIntent();
Uriuri= intent.getData();
Stringcampaign= uri.getQueryParameter("utm_source");

And add the receiver on your manifest file to get INSTALL_REFERRER broadcasts from play store

<receiverandroid:name="com.google.android.gms.analytics.CampaignTrackingReceiver"android:enabled="true"android:exported="true"><intent-filter><actionandroid:name="com.android.vending.INSTALL_REFERRER" /></intent-filter></receiver>

https://developers.google.com/analytics/devguides/collection/android/v3/campaigns

Post a Comment for "Google Analytics / Campaign Measurement"