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

Importing Cost Data using the Management API

This guide describes how to import cost data using the Management API.

  1. Introduction
  2. Before you begin
  3. Overview
  1. Tag campaign URLs
  2. Create a data set
  3. Prepare the cost data CSV file for upload
  4. Upload cost data using the Management API
  5. Reports

Introduction

Importing cost and click data for non-Google paid campaigns allows you to leverage the Google Analytics platform to perform ROI analysis and compare campaign performance for all your online advertising and marketing investments.

Before you begin

Before beginning this guide, developers should do the following:

Overview

Importing Cost Data to Google Analytics using the Management API requires the following steps:

  1. Tag campaign URLs.
  2. Create a data set.
  3. Prepare the cost data CSV file for upload.
  4. Upload cost data using the Management API.

Tag campaign URLs

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

Example

In the following example advertisement, the destination URL is tagged with campaign tracking parameters (utm_campaign, utm_source, utm_medium, utm_term). This ensures that visits to the website from ad clicks are associated with the summer sale campaign in Google Analytics.

Figure 1: Advertisement Example.

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 session:

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 session and that there is a way to join Google Analytics data with the external cost data source.

Create a data set

To import your cost data you must create a Data Set. A data set is used to represent one or more external data sources in Google Analytics. A data set can only be created through the Web Interface.

Under the property tab of the admin page perform the following steps:

  1. Select the Data Import tab.
  2. Click the New Data Set button.
  3. Select the Cost Data for the type and click Next Step.
  4. Name the data set and select one or more views (profiles) to enable Cost Analysis in reports and click Next Step.
  5. Select the Dimensions and Metrics you intend to upload.
  6. Select the desired Import Behavior.
    • This setting controls whether to overwrite or sum cost data in cases where a duplicate key is found. To learn more about import behavior see the Cost Data Summation vs Overwrite section of the Data Import Developer Guide.
  7. Click Save.
Figure 2: Creating a cost data set.

Prepare the cost data CSV file for upload

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

The primary modifications and validations that you need to make to the CSV file are:

  • Rename the column headers to match those recognized by Google Analytics. You can retrieve the header from the data set details page in the web interface.
  • Add any required values that are missing.
  • Where applicable, values in the CSV file should match the values used for campaign tracking parameters.

Example

With the pet store example, the data is exported in aggregate, and saved as a CSV file:

Figure 3: Exported cost data CSV file.

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

Figure 4: Formatted cost data CSV file.

Once you’ve prepared the CSV file, the format should look similar to the following example:

ga:date,ga:source,ga:medium,ga:campaign,ga:keyword,ga:impressions,ga:adClicks,ga:adCost
20140615,ad network,cpc,Summer Sale,dogbone,9387,288,100.3
20140615,ad network,cpc,Summer Sale,dog treat,1684,52,19.35
20140615,ad network,cpc,Summer Sale,pet store,3187,143,76.23
20140616,ad network,cpc,Summer Sale,dogbone,8754,188,86.21

See the Data Import Developer Guide for general file format constraints.

Upload cost data using the Management API

Once you've created the Data Set and prepared your cost data for upload in a CSV, you're ready to upload your cost data using the Management API or through the web interface.

Reports

Uploaded cost data will be available as part of the Cost Analysis reports under Acquisition in Google Analytics as well the Core Reporting API.