Google Analytics

Campaign Measurement - Android SDK v4

This document provides an overview of how to measure campaigns and traffic sources with the Google Analytics SDK v4 for Android.

  1. Overview
  2. Google Play Campaign Attribution
    1. Implementation
    2. Testing
  1. Campaign Parameters
  2. Google Play URL Builder
More

Overview

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:

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 an INTENT_REFERRER 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 referrer parameter to any links that point to Google Play Store, and add a BroadcastReceiver 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 BroadcastReceiver 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

To learn how to build a campaign parameter strings, use the Google Play URL Builder, or consult the Campaign Parameters reference section.

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.

Alternatively, if you have campaign information in a form other than Google Analytics campaign parameters, you may set it on a Map and send it manually:

        // Get tracker.
        Tracker t = ((AnalyticsSampleApp) getActivity().getApplication()).getTracker(
            TrackerName.APP_TRACKER);
        // Set screen name.
        // Where path is a String representing the screen name.
        t.setScreenName(path);

        // In this example, campaign information is set using
        // a url string with Google Analytics campaign parameters.
        // Note that Fields.CAMPAIGN_KEYWORD is not necessary for this campaign.
        String campaignData = "http://my.site.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.AppViewBuilder()
            .setCampaignParamsFromUrl(campaignData)
            .build()
        );

See Advanced Configuration for details on the getTracker method.

Campaign Parameters

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:

Parameter Description Example(s)
utm_campaign Campaign name; used for keyword analysis to identify a specific product promotion or strategic campaign utm_campaign=spring_sale
utm_source Campaign source; used to identify a search engine, newsletter, or other source utm_source=google
utm_medium Campaign medium; used to identify a medium such as email or cost-per-click (cpc) utm_medium=cpc
utm_term Campaign term; used with paid search to supply the keywords for ads utm_term=running+shoes
utm_content Campaign content; used for A/B testing and content-targeted ads to differentiate ads or links that point to the same URL utm_content=logolink
utm_content=textlink
gclid 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.

Authentication required

You need to be signed in with Google+ to do that.

Signing you in...

Google Developers needs your permission to do that.