Pete Frisella, Google Analytics Developer Advocate – October 2012
This document explains how to enable the performance measurement of non-Google campaigns by using cost data upload.
Similar to how Google AdWords can be linked to a Google Analytics view (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.
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:
- Tag campaign URLs
- Retrieve and format cost data as a CSV file
- Create a custom data source using the web interface
- Upload cost data CSV using the Management API
- 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.
In the following example ad, thedestination 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 visit:
|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 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.
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:
- Cost Data Dimensions and Metrics — Complete list of values that can be uploaded to Google Analytics.
- Cost Data Format and Constraints — Formatting requirements for CSV files.
- URL tagging and naming consistency — Campaign tracking parameters and the corresponding Google Analytics dimensions.
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:
- Navigate to the admin settings within the Google Analytics web interface.
- Select a web property for which you'd like to create a custom data source.
- Select the Custom Definitions tab.
- Click the New Custom Data Source button.
- Name the data source and provide a description.
- Link one or more views (profiles) to enable cost data in reports.
- Click Create.
The following screenshot shows a list of custom data sources associated with the selected web property. Note the
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
dailyUpload resource, which represents the cost data that has been uploaded for a particular date.
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 view (profile) ID
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.
- Cost Data Upload Reference Guide — Learn how cost data upload works.
- Custom Data Source Developer Guide — Learn about all the custom data source resources and methods.
- Daily Upload Developer Guide — Learn about listing, deleting, and appending cost data uploads.
- Custom Data Sources Reference
- Daily Uploads Reference