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.

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];

  // 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 get: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. You will also need to add an additional framework to your app if you want to use automatic iAd install campaign measurement.

Self-serve diagnosis for iOS conversion tracking

If you do not see conversions for your iOS campaigns, follow these steps to troubleshoot:

  1. Confirm iOS campaign tracking is enabled
  2. Confirm application ID matches
  3. Confirm GA SDK is sending the IDFA
  4. Look at the demographics report to confirm IDFA is being sent
  5. Ensure iOS campaign tracking URLs are correct

Step 1: Confirm iOS campaign tracking is enabled

To confirm iOS campaign tracking is enabled for the target property:

  1. Click the Admin tab.

    admin tab

  2. Select the property and click Property Settings.

    property settings

  3. Make sure iOS Campaign Tracking is ON.

    iOS campaign tracking

Step 2: Confirm application ID matches

To correctly attribute a campaign with app 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, create a custom report in the Google Analytics web interface with App Id as a dimension and Sessions as a metric.

While creating a click iOS campaign tracking URL, use the App ID appearing in the custom report.

create custom report

Step 3: Confirm Google Analytics SDK is sending the IDFA

Google Analytics uses Identifier for Advertiser (IDFA) as one of the keys to join mobile clicks with Google Analytics hits. Ensure that:

  • Your app is using Google Analytics SDK for iOS version 3.10 or higher.
  • Your app is linked with libAdIdAccess.a as part of the Google Analytics iOS release.
  • Your app is linked with AdSupport.framework.
  • You have enabled IDFA collection on each tracker:
    tracker.allowIDFACollection = YES;
    
  • If possible use a debugging proxy application to view HTTP requests and confirm IDFA is included.

Step 4: Look at the demographics report to confirm IDFA is being sent

Google Analytics uses IDFA to generate the demographics reports. In Google Analytics, click the Reporting tab and click Audience > Demographics > Overview to check if you see demographic data. If you do, IDFA is being sent correctly.

custom report

Step 5: Ensure iOS campaign tracking URLs are correct

Use the iOS Campaign Tracking URL Builder to verify that the iOS campaign tracking URLs are correct.

When selecting the Custom option for Ad Network, make sure to also consult with that network to confirm it supports tracking individual device IDs using redirect URLs. If it doesn't, then you will not see any data in Google Analytics reporting.

iOS Campaign Tracking URL Builder

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