This document provides an overview of how to measure campaigns and traffic sources with the Google Analytics SDK v4 for Android.
Measuring campaigns in Google Analytics enables the attribution of campaigns and traffic sources to user activity within your application. These options are available for campaign and traffic source attribution in the Google Analytics SDK for Android:
- Google Play Campaign Attribution - See which campaigns, websites, and other apps are referring users to Google Play Store to download your app.
- General Campaign & Traffic Source Attribution - See which campaigns or referrers launch your app after it is installed.
The following sections will describe when and how to implement each type of campaign measurement in your app.
Google Play Campaign Attribution
Google Play Campaign Measurement allows you to see which campaigns and traffic sources are sending users to download your app from the Google Play Store. It is recommended that all developers implement Google Play Store Campaign Measurement.
Implementing Google Play Campaign Attribution
When your app is downloaded from Google Play Store, the Play Store app broadcasts
INSTALL_REFERRER intent to your app during installation. This intent contains
the value of the
referrer parameter of the link used to reach your app's
Google Play Store page, if one was present.
To attribute an app download to a campaign, you must add a
parameter to any links that point to Google Play Store, and add a
to your app to receive and set the campaign information contained in the intent on your
Google Analytics tracker.
It is recommended that most developers use the
provided with the SDK. To implement Google Play Store Campaign Measurement using
the included receiver:
1. Add the Google Analytics receiver to your
AndroidManifest.xml file. To add the Google Analytics receiver to
the manifest, copy and paste the following markup:
<!-- Used for Google Play Store Campaign Measurement--> <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>
2. Add Google Analytics Campaign Parameters to Google Play URLs
Next, add a
referrer parameter to any URLs that will be
linking directly to Google Play Store and set the value of that parameter
to a string of Google Analytics campaign parameters that describe the source,
as in this example:
https://play.google.com/store/apps/details?id=com.example.app &referrer=utm_source%3Dgoogle %26utm_medium%3Dcpc %26utm_term%3Dpodcast%252Bapps %26utm_content%3DdisplayAd1 %26utm_campaign%3Dpodcast%252Bgeneralkeywords
Testing Google Play Campaign Attribution
To verify that your Google Play Campaign Measurement implementation is working as expected before publishing your app, use the Testing Google Play Campaign Attribution Solution Guide.
General Campaign & Traffic Source Attribution
After an app has been installed, it may be launched by referrals from ad campaigns,
websites, or other apps. In this scenario, referring traffic sources or marketing
campaigns may be attributed to user activity in subsequent sessions by setting
the campaign parameters on a tracker directly by using the
// Get tracker. Tracker t = ((AnalyticsSampleApp) getActivity().getApplication()).getTracker( TrackerName.APP_TRACKER); // Set screen name. t.setScreenName(screenName); // In this example, campaign information is set using // a url string with Google Analytics campaign parameters. // Note: This is for illustrative purposes. In most cases campaign // information would come from an incoming Intent. String campaignData = "http://examplepetstore.com/index.html?" + "utm_source=email&utm_medium=email_marketing&utm_campaign=summer" + "&utm_content=email_variation_1"; // Campaign data sent with this hit. t.send(new HitBuilders.ScreenViewBuilder() .setCampaignParamsFromUrl(campaignData) .build() );
Advanced Configuration for details on the
Campaign parameters are used to pass information about the traffic sources and campaigns that are bringing users to your app.
The table below contains the available campaign parameters that can be used in Google Play or general campaign measurement:
||Campaign name; used for keyword analysis to identify a specific product promotion or strategic campaign||
||Campaign source; used to identify a search engine, newsletter, or other source||
||Campaign medium; used to identify a medium such as email or cost-per-click (cpc)||
||Campaign term; used with paid search to supply the keywords for ads||
||Campaign content; used for A/B testing and content-targeted ads to differentiate ads or links that point to the same URL||
||AdWords autotagging parameter; used to measure Google AdWords ads. This value is generated dynamically and should never be modified.|
Google Play URL Builder
Use the tool below to generate URLs for Google Play Campaign Measurement.