Click here to see your recently viewed pages and most viewed pages.
Hide

Campaign Measurement - iOS SDK

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

  1. Overview
  2. Campaign Parameters
  3. General Campaign & Traffic Source Attribution
  1. iOS Install Campaign Measurement
    1. Troubleshooting iOS Campaign Measurement
    2. iOS Campaign Tracking 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 iOS:

The following sections will describe when and how to implement each type of campaign measurement in your app.

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

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 can be attributed to user activity in subsequent sessions by setting the campaign fields on a tracker directly.

The easiest way to send campaign data is to use [GAIDictionaryBuilder setCampaignParametersFromUrl:urlString], where urlString is a string representing a URL that may contain Google Analytics campaign parameters. Note that in the following examples, campaign data is not set on the tracker directly, as it only needs to be sent once:

/*
 * MyAppDelegate.m
 *
 * An example of how to implement campaign and referral attribution.
 * If no Google Analytics campaign parameters are set in the referring URL,
 * use the hostname as a referrer instead.
 */
- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url
  sourceApplication:(NSString *)sourceApplication annotation:(id)annotation {

  NSString *urlString = [url absoluteString];

  id<GAITracker> tracker = [[GAI sharedInstance] trackerWithName:@"tracker"
                                                      trackingId:@"UA-XXXX-Y"];

  // setCampaignParametersFromUrl: parses Google Analytics campaign ("UTM")
  // parameters from a string url into a Map that can be set on a Tracker.
  GAIDictionaryBuilder *hitParams = [[GAIDictionaryBuilder alloc] init];

  // Set campaign data on the map, not the tracker directly because it only
  // needs to be sent once.
  [[hitParams setCampaignParametersFromUrl:urlString] build];

  // Campaign source is the only required campaign field. If previous call
  // did not set a campaign source, use the hostname as a referrer instead.
  if(![hitParams valueForKey:kGAICampaignSource] && [url host].length !=0) {
    // Set campaign data on the map, not the tracker.
    [hitParams set:@"referrer" forKey:kGAICampaignMedium];
    [hitParams set:[url host] forKey:kGAICampaignSource];
  }

  NSDictionary *hitParamsDict = [hitParams build];

  // A screen name is required for a screen view.
  [tracker set:kGAIScreenName value:@"screen name"];

  // Previous V3 SDK versions.
  // [tracker send:[[[GAIDictionaryBuilder createAppView] setAll:hitParamsDict] build]];

  // SDK Version 3.08 and up.
  [tracker send:[[[GAIDictionaryBuilder createScreenView] setAll:hitParamsDict] build]];

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

// Assumes at least one tracker has already been initialized.
id<GAITracker> tracker = [[GAI sharedInstance] defaultTracker];

// Note that it's not necessary to set kGAICampaignKeyword for this email campaign.
NSMutableDictionary *campaignData = [NSDictionary alloc dictionaryWithObjectsAndKeys:
    @"email", kGAICampaignSource,
    @"email_marketing", kGAICampaignMedium,
    @"summer_campaign", kGAICampaignName,
    @"email_variation1", kGAICampaignContent, nil];

// A screen name is required for a screen view.
[tracker set:kGAIScreenName value:@"screen name"];

// Note that the campaign data is set on the Dictionary, not the tracker.
// Previous V3 SDK versions.
// [tracker send:[[[GAIDictionaryBuilder createAppView] setAll:campaignData] build]];

// SDK Version 3.08 and up.
[tracker send:[[[GAIDictionaryBuilder createScreenView] setAll:campaignData] build]];

iOS install campaign measurement

Google Analytics offers out-of-the-box support for iOS Install Campaign Measurement for popular networks and provides the ability to generate your own custom URLs for any additional networks.

To enable iOS Install Campaign Measurement, use the iOS Campaign Tracking URL Builder below to generate destination URLs for your ads that send users to the App Store. In order for iOS Campaign Tracking to work, you must have already implemented Google Analytics in your iOS app, enabled IDFA collection, and be tracking one or more screen views or events in your app.

Troubleshooting iOS install campaign measurement

If you do not see conversions for your iOS install campaigns, review the following steps to troubleshoot:

  1. Confirm that iOS campaign tracking is enabled
  2. Confirm the correct App Id is set
  3. Confirm that the IDFA is being sent

1. Confirm that iOS campaign tracking is enabled

Visit the Google Analytics admin interface to confirm that this feature is enabled for the target property.

Sign into Google Analytics, then:

  1. Click Admin in the menu bar at the top of any page.
  2. Select your Property then click Property Settings.
  3. Under the iOS Campaign Tracking section, confirm that the toggle is set to ON.

2. Confirm the correct App Id is set

To correctly attribute campaigns with app tracking data, the iOS Campaign Tracking URL and your app tracking implementation need to use the same App Id. To determine the App Id for an app that you're currently tracking you can create a custom report in the Google Analytics web interface with App Id as a dimension and Sessions as a metric or use the following pre-defined Query Explorer report.

3. Confirm that the IDFA is being sent

Google Analytics requires Identifier for Advertiser (IDFA) for iOS campaign tracking. Ensure that you are using Google Analytics SDK for iOS version 3.10 or higher, you have enabled IDFA collection, and are tracking one or more screen views or events in your app.

iOS Campaign Tracking URL Builder

Use the tool below to generate URLs for measuring the source of iOS application installs.