Upload Click and Cost Data to Google Analytics Using Excel or Google Docs Files

Update 1/23/2012 – As the commenters have pointed out you will need to delete the analytics.dat file from the program download in order to authenticate successfully.  Will update blog post/files soon.

Update 1/24/2012 – Link to github – https://github.com/CharlesFarina/Google-Analytics-Cost-Data-Upload–Python-


As the year closes, I wanted to make you aware of a feature in Google Analytics that has amazing potential.  This will tie in with all of your New Year resolutions around making better marketing decisions.   In October at the Google Analytics Certified Partner Summit we attended, Google announced the new cost data upload feature.  For the first time we can measure the return on investment for all of our paid advertising campaigns.  You can segment and dive into this data to find what aspects of each paid traffic source or the overall campaign are under or over performing and optimize accordingly.  This feature allows you to upload non-AdWords cost data for Bing, Facebook, LinkedIn and any of your other paid traffic sources.  What we are trying to create is the report below:

You can now make decisions on your marketing campaigns based on ROI inside of Google Analytics!  It is very apparent in the above report that we need to reevaluate or do optimization for the cnn.com campaign, since we are making less than what we are spending with an ROI of -1.43%.  This is the type of insight I want to help you find.

Use This Program or an API?

The first thing you should do is check to see whether the traffic source you want to upload cost data from has an API. Many popular services like  Facebook and Bing have an API that you can leverage to save you a significant amount of time and effort.  E-Nor has leveraged this with many of our clients like OEMPCWorld.  If your source has an API, you can use a tool like ShufflePoint In2GA and work with them to establish the connection.  This connection will upload all of your historical cost data as well as upload your new cost data each day.  This means you don’t have to do anything on your end outside of creating/paying for an account with ShufflePoint.

It is very likely that you will also have sources that don’t have an API.  This could be affiliate networks, banner ads, e-mail lists, and the like.  You could also decide you don’t want to pay someone to establish an API connection, so the following instructions could apply to Facebook and Bing as well.  The instructions below will allow you to upload cost data from any .csv files on a Mac to Google Analytics.  These files can be created in Microsoft Excel, Google Docs, iWork, or any of your favorite spreadsheet tools.  I tried to make these as detailed and easy to understand as I could, so that anyone could use it.  The best part about this tool is that it is free and will be a great way to end the year or kick off the new year with new insights.

Disclaimer:  These instructions are for Mac only.  If you are familiar with programming languages, getting it to work on Windows shouldn’t be difficult.  I can also not be responsible if anything breaks or your computer explodes, this is a free tool after all =)

Here are the six steps:

1. Create Project and Obtain OAuth 2.0 Client ID

a. Go to Google API’s page and click the blue “Create project…” button

 b.  Slide “Analytics API” to On

c. Agree to the terms of service
d. Click on “API Access” in the left navigation


e. Click the blue “Create an OAuth 2.0 client ID…” button

f. Fill in “Product name” field with “Cost Data Upload Program”.  Leave rest of form blank and click grey “Next” button.

g. For Application Type select “Installed application” radio button.  Leave installed application type defaulted to “Other.”  Click grey “Create client ID” button.

  h. Find and click the “Download JSON” link in the Client ID for installed applications section on the right side of page

2. Download and Install Cost Data Program

a. Place the downloaded “clients_secrets.json” file from step 1h on your desktop.
b. Download the “e-nor cost data upload program” to your desktop.  Select file then download to download entire zip, instead of each file individually.
c. Unzip the download and make sure it is on your desktop.
d. Drag the “clients_secrets.json” file (step 1h and 2a) from your desktop into the unzipped “e-nor_costdataupload” folder (step 10-11) on your desktop.  Select “Replace” when prompted.
e. Login to Google Analytics and go to the profile you want to upload data to

f. Click “Admin” Button in top-righthand corner
g. Record the provided Property ID: UA-XXXXX-XX
h. Click “Custom Definitions” Tab
i. Click “New Custom Data Sources (Beta)” Button
j. Enter a name, description and select profiles to send data to and click “create”

k. Record the UID


l. Open the “e-nor_costdataupload” folder and open the “upload_csv_file.py” file

m. Scroll to the bottom and replace the accountId, webPropertyId and CustomDataSourceID with what you recorded in steps 2g and 2k.  The accountId is the same as the webPropertyId, just with the beginning and end removed.  If you recorded UA-123456-1 in steps 2g.  You will put UA-123456-1 as the webPropertyId and 123456 as the accountId.

n. Save and close the files

3. Installing Google Analytics API files through Easy Install

a. Download the Easy Install files here and place file on desktop
b. Click spotlight in top right hand corner of your Mac and type in “Terminal” and open it.

c. In Terminal type or paste: cd Desktop

d. Type or paste: sudo sh setuptools-0.6c11-py2.7.egg

e. Enter your password and you should see the below message if successful

f. In terminal type or paste: sudo easy_install –upgrade google-api-python-client

g. If successful you will see this message

4. Creating Cost Data Files

There are 17 different dimensions and metrics you can upload, but only 5 are required: cost, impressions, clicks, source and medium.  In the e-nor_costdataupload/October-Cost-Data folder you can find examples of the fields and formatting that is required or view the image below.

You will need to create a file per day for your cost data.  If you want to upload the month of November you will have one file per day of data.  You can create this using your favorite spreadsheet software (Excel, iWork, Google Docs, etc).  The only requirement is they have to be saved as “Comma Separated Values” which are the .csv file extension.  There are templates/examples in the cost data program provided.

5. Uploading Cost Data

You will now be uploading a cost data file.  You need to first create and save the file as explained in step 4.  We will now upload one day of data using the following command: ./upload_csv_file.py {yyyy-mm-dd} ~{cost-file-location}

If we are trying to upload the example files included with the program we would enter the following in terminal:

a. Open Terminal and type or paste: cd Desktop/e-nor_costdataupload
b. ./upload_csv_file.py 2012-11-01 ~/Desktop/e-nor_costdataupload/October-Cost-Data/2012-11-01.csv

6. Viewing Cost Data in Google Analytics

This is the hardest part of all!  You will need to be patient and wait for up to 12 hours to see the cost data appear in Google Analytics.  In my experience on average it took about 30 minutes.  You will find it in the Traffic Sources Section as “Cost Analysis”.  You can also create custom reports to add in metrics such as revenue, transaction and to apply various advanced segments or filters.

Need Help With Google Analytics? Click Here

Closing Thoughts

I love this new feature, but as you can tell if you aren’t leveraging an API tool it can be quite a bit of work to get the data into Google Analytics.  Two improvements I have planned are first to have a way to batch upload buckets of files at one time and also for a script in Excel to create multiple files from a master spreadsheet based on date.  Ideally, I would like to be able to create one spreadsheet with all of the dates/data I need and have the program parse and upload it from memory.  The source code for the program is given to you, so I encourage one of you to do it and let me test it =)

Related Posts:

  1. Google Cost Data Announcement
  2. Cost Data Development Goodies
  3. E-Nor / OEMPCWorld Use Case
  4. E-Nor Cost Data Announcement 


22 thoughts on “Upload Click and Cost Data to Google Analytics Using Excel or Google Docs Files”

  1. Great job!
    I’m writing PHP application for Uploading CSV file to GA,
    and I would love to get in touch with you!

    Thanks and once again: Great job! :)

  2. Hi, I did all steps and I’m getting an error msg on the last step:
    Arg, there was an API error : 403 : User does not have sufficient permissions for this account.

    Do you know why?

    Thanks! Great Job!

  3. Thanks for the wonderful stepwise guide. I am getting the following error :
    Arg, there was an API error : 403 : User does not have sufficient permissions for this account.

    I have tried creating a new client ID, new custom definition but the same error is appearing. In the zip folder download, the instruction file has step 6. How do we autorize the data?
    Really appreciate your help.

  4. The first time you make the request, it should open up a browser and ask you to authenticate.

  5. Hi, First of all, Nice Job, excelent Initative.
    I did all of steps, but when I run the upload_csv_file.py I received the following message:

    C:\Users\mvendemiatti\Desktop\e-nor_costdataupload>upload_csv_file.py c:\Users\m
    Traceback (most recent call last):c
    File “C:\Users\mvendemiatti\Desktop\e-nor_costdataupload\upload_csv_file.py”,
    line 18, in
    import extra_utils
    File “C:\Users\mvendemiatti\Desktop\e-nor_costdataupload\extra_utils.py”, line
    6, in
    from apiclient.discovery import build
    ImportError: No module named apiclient.discovery

    Could you know what’s happen?

    Thank you in advantage,


  6. Hi Renato,

    If you would like you could zip up what you have and e-mail it to me and I can take a look.


  7. Hi Mauro,
    It sounds like you are missing the root API files. Can you try step 3 again and verify the outputs match the screenshots.


  8. Can you try executing this?

    python ./upload_csv_file.py 2012-11-01 ~/Desktop/e-nor_costdataupload/October-Cost-Data/2012-11-01.csv

  9. Hello,

    I have an error why I try the 3g :

    error: Not a URL, existing file, or requirement spec: ‘\xe2\x80\x93upgrade’

    why have I this message ? Any idea ? thanks a lot.

  10. Okay, I found the solution :
    It’s ” sudo easy_install –upgrade google-api-python-client ” on the step 3F and 3G !
    ( you miss a ” – ” before “upgrade ) ;-)

  11. I have the same problem as Renato. Error 403, insufficient permission. Deal anyone know, what to do? Thanks a lot.

  12. In step 3F I keep getting this error: error: Not a URL, existing file, or requirement spec: ‘\xe2\x80\x93upgrade’ when i run “sudo easy_install –upgrade google-api-python-client”

    Any ideas on how to fix this?

  13. Hi JP,

    I am not sure. There has been a lot of developments and improvements, since I first released this. At the time this was the only publicly available free tool. For simple uploads, I would recommend using Lunametrics free tool that has a GUI: http://www.lunametrics.com/cost-data-upload/upload.html or purchasing a license for nextanalytics if you need batch uploads.

  14. Hi Charles, first of all thank for taking the time to share with all of us this valuable information.

    I’m having a problem when executing the commands for uploading. Step 5. I already checked the step 3. and everything looks ok as shown in the step by step.
    When I type ./upload_csv_file.py 2012-11-01 ~/Desktop/e-nor_costdataupload/October-Cost-Data/2012-11-01.csv
    I get the following error in the terminal.

    Santiagos-MacBook-Pro-2:e-nor_costdataupload ssuarez$ ./upload_csv_file.py 2012-11-01 ~/Desktop/e-nor_costdataupload/October-Cost-Data/2012-11-01.csv
    Traceback (most recent call last):
    File “./upload_csv_file.py”, line 18, in
    import extra_utils
    File “/Users/ssuarez/Desktop/e-nor_costdataupload/extra_utils.py”, line 7, in
    import gflags
    ImportError: No module named gflags
    Santiagos-MacBook-Pro-2:e-nor_costdataupload ssuarez$ python ./upload_csv_file.py 2012-11-01 ~/Desktop/e-nor_costdataupload/October-Cost-Data/2012-11-01.csv
    Traceback (most recent call last):
    File “./upload_csv_file.py”, line 18, in
    import extra_utils
    File “/Users/ssuarez/Desktop/e-nor_costdataupload/extra_utils.py”, line 7, in
    import gflags
    ImportError: No module named gulags

    Could you give me and idea of what might be happening.

    Thanks in advanced for your time.

  15. Hello, I got to step 5 without any problems, but when I try and upload a file that I prepared myself using the below command, I get the below error:

    Command: ./upload_csv_file.py ~/Desktop/FB_Cost_Data_FB_Cost_Data_18th_21st_May_2015.csv

    Error Message: webPropertyId=’UA-54529591-1’, # Web Property Id (child of the Account)
    SyntaxError: EOL while scanning string literal

    I couldn’t see any unclosed commas etc. Is there anything really obvious that this syntax error is telling me and I’m just not getting?

    I really appreciate the help. Your blog post is ace!

    All Best,


Leave a Reply

Your email address will not be published. Required fields are marked *


You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code class="" title="" data-url=""> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre class="" title="" data-url=""> <span class="" title="" data-url="">