Google Analytics

Measuring Performance Of Paid Campaigns

This document explains how to enable the performance measurement of non-Google campaigns by using cost data upload.

  1. Introduction
  1. Program Overview
    1. Tag Campaign URLs
    2. Retrieve and Format Cost Data as a CSV File
    3. Create a Custom Data Source Using the Web Interface
    4. Upload Cost Data Using The API
    5. Reporting with the Core Reporting API or Web Interface
More

Introduction

Similar to how Google AdWords can be linked to a Google Analytics profile, you can upload cost data for non-Google paid campaigns and leverage the Google Analytics platform to perform ROI analysis and compare campaign performance for all online advertising and marketing investments.

Program Overview

To demonstrate how to upload cost data to Google Analytics for an online advertising campaign, consider the following scenario:

An online pet store plans and executes a "summer sale" advertising campaign, using both Google AdWords and another search advertising platform. The store uses Google Analytics on their website to measure the performance of their campaigns.

The company wants to import non-google paid search campaign cost data into Google Analytics so that they can perform ROI analysis, and compare and optimize the performance of Google AdWords and other paid search campaigns.

The solution is to upload the paid search campaign cost data to Google Analytics. The steps to do this are:

  1. Tag campaign URLs
  2. Retrieve and format cost data as a CSV file
  3. Create a custom data source using the web interface
  4. Upload cost data CSV using the Management API
  5. Report using the Core Reporting API or web interface

Tag Campaign URLs

To perform ROI analysis on paid campaigns, you need to join cost data from external sources with visits data in Google Analytics. You can do this by adding campaign tracking parameters to all destination URLs in the non-Google ad system you're using.

Example:

In the following example ad, the Example Pet Store | examplepetstore.com destination URL is tagged with campaign tracking parameters. This ensures that visits to the website from ad clicks are associated with the summer sale campaign in Google Analytics.

The pet store has used the following destination URL for this ad:

http://www.examplepetstore.com?utm_campaign=Summer%2BSale&utm_source=ad%2Bnetwork&utm_medium=cpc&utm_term=dogbone

When the user clicks the ad, they will be taken to the pet store website and the following values will be set in Google Analytics for the visit:

Dimension Name in Google Analytics Web Interface Campaign tracking parameter Value set in Google Analytics
Campaign Name utm_campaign Summer Sale
Source utm_source ad network
Medium utm_medium cpc
Keyword utm_term dogbone

This ensures that Google Analytics has the campaign tracking parameters associated with the visit and that there is a way to correlate Google Analytics data with the external cost data source.

Retrieve And Format Cost Data as a CSV File

After properly tagging URLs with campaign tracking parameters, the next step is to retrieve the cost data for the campaign from the external data source and prepare it for uploading to Google Analytics.

Google Analytics expects cost data to be uploaded in a specific format with certain values. You need to makes sure that the cost data exported from an external source meets these requirements before uploading.

The primary modifications and validations that need to be made to the CSV file are:

  • Rename the column headers to match those recongnized by Google Analytics.
  • Add any required values that are missing.
  • Where applicable, values in the CSV file should match the values used for campaign tracking parameters.

Example:

The pet store exports daily cost data for the summer sale campaign. The data is exported in aggregate, for a single date, September 12, 2012 and saved as a CSV file:

The CSV file is then modified to meet the format required by Google Analytics:

The CSV file is ready to be uploaded to Google Analytics. The file name, adnetwork_summersale_2012-09-12.csv, will need to be specified during the upload later on.

For resources to help you with creating and formatting the CSV file see:

Create a Custom Data Source Using the Web Interface

After preparing the cost data CSV file, you must create a custom data source. A custom data source is used to represent one or more external data sources in Google Analytics. Creating a custom data source requires the use of Google Analytics the web interface.

The steps to create a custom data source are:

  1. Navigate to the admin settings within the Google Analytics web interface.
  2. Select a web property for which you'd like to create a custom data source.
  3. Select the Custom Definitions tab.
  4. Click the New Custom Data Source button.
  5. Name the data source and provide a description.
  6. Link one or more profiles to enable cost data in reports.
  7. Click Create.

The following screenshot shows a list of custom data sources associated with the selected web property. Note the UID of the custom data source, this is a required parameter for uploading to Google Analytics.

See Custom Data Source Reference Guide to learn more about custom data sources.

Upload Cost Data Using The Management API

Now that you've prepared a CSV file, created a custom data source using the UI, and retrieved a Custom Data Source ID (named UID in the web interface), you are ready to upload cost data.

The Managment API provides two resources for managing and uploading cost data to Google Analytics: A customDataSource resource, which represents all of the metadata for an external data source and a dailyUpload resource, which represents the cost data that has been uploaded for a particular date. The upload method for the dailyUpload resource is used to upload cost data for a custom data source and date.

The following is a simple example of how the upload would be performed in Python using the Google APIs Client Library for Python.

media = MediaFileUpload(
    'adnetwork_summersale_2012-09-12.csv', # The CSV file to upload
    mimetype='application/octet-stream',
    resumable=False)

analytics_service.management().dailyUploads().upload (
    accountId='1234'  # Google Analytics Account Id,
    webPropertyId='UA-1234-1',  # Web Property Id (child of the Account)
    customDataSourceId='xtoxp3J12xq83872xxYNhijw',  # Custom Data Source Id (UID in Web Interface)
    date='2012-09-12',  # Upload Date
    appendNumber=1,  # The append number of the current upload
    reset=false,  # Reset will delete any existing data for the date if set to true
    type='cost',  # Type of data being uploaded
    media_body=media).execute()

For complete details on upload parameters see the dailyUploads Reference

Reporting with the Core Reporting API or Web Interface

Once the cost data has been successfully uploaded, it can take up to 12 hours for the data to be available in reports.

Reports can be queried using the the Core Reporting API or through the web interface using custom reports or the standard Cost Analysis Report, available under the Traffic Source section.

The following is an example of a Core Reporting API query in Python for profile ID1234, for 2012-09-12. If processing has completed, this request will return cost data.

analytics_service.data().ga().get(
    ids='ga:1234',
    start_date='2012-09-12',
    end_date='2012-09-12',
    metrics='ga:impressions,ga:adClicks,ga:adCost',
    dimensions='ga:source,ga:medium,ga:campaign').execute()

It is also possible to append or delete data. See the Daily Upload Developer Guide for details on these methods.

Additional Resources

For a better understanding of how cost data upload works and its technical details, it is recommended you read the following documents:

Authentication required

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

Signing you in...

Google Developers needs your permission to do that.