This guide describes how to import cost data using the Management API.
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:
- Read the Data Import Guide (Help Center) to learn about the data import feature.
- Read the Data Import Developer Guide to learn about concepts on how to use the Management API to import data.
- Read the Upload resource reference to learn about uploading data.
Importing Cost Data to Google Analytics using the Management API requires the following steps:
- Tag campaign URLs
- Create a data set
- Prepare the cost data CSV file for upload
- 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.
In the following example advertisement, the 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:
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|
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:
- Select the Data Import tab.
- Click the New Data Set button.
- Select the Cost Data for the type and click Next Step.
- Name the data set and select one or more views (profiles) to enable Cost Analysis in reports and click Next Step.
- Select the Dimensions and Metrics you intend to upload.
- 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.
- Click Save.
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.
With the pet store example, the data is exported in aggregate, and saved as a CSV file:
The CSV file is then modified to meet the format required by Google Analytics:
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
Uploaded cost data will be available as part of the Cost Analysis reports under Acquisition in Google Analytics as well the Core Reporting API.