UPDATE March 2014: We’ve published a new Google Docs add-on that makes it very simple to get your metrics from Google Analytics and other sources: Supermetrics for Google Docs
UPDATE: Due to changes by Google, this no longer works. We have a new version available here.

The functions for importing Google Analytics data to a spreadsheet are now also available for Google Docs! With this solution, you can create automatically updating Analytics reports in a GD spreadsheet – these can contain analyses and visualizations that are not available through the GA user interface. You can combine data from several GA profiles, and merge it with data from other systems, such as internal sales data. And having the reports in Google Docs makes it easy to share them within your company or with clients.
Try it now here!  (If you get a “We’re sorry, your spreadsheet cannot be copied at this time” error, open your Google Docs file list, click Create new-> From template -> Public templates, and search for “Google Analytics Functions Examples”)

You can use the functions following the instructions here (they are for Excel but usage is practically the same) and the parameter reference here. There’s also a nice tutorial made by someone else here.

The Google Docs functions also work on a Mac, as well as any other systems from which Google Docs can be accessed – you can even check the latest stats with your mobile.

There are three ways to get started using the functions in Google Docs:

  1. Do it yourself: Copy the function code from here and paste it to a Google Docs spreadsheet file (open the Script editor from the Tools: Scripts menu, paste the code there, and save).  
  2. A customized solution: Put an email to us at info@supermetrics.com describing the kind of report you’d like to see in Google Docs, and I’ll give you price for creating it.

Using the functions in a Google Docs spreadsheet is almost identical to how they are used in Excel: there are the same three functions (getGAauthenticationToken, getGAaccountData and getGAdata), and they take the same parameters as the Excel versions (with a few minor exceptions, which are explained below). The function code is of course different (I’ve converted it from VBA to Google Apps Script), but for the end user this doesn’t make a difference.

Having the GA functions available in Google Docs opens up some nice possibilities. See for example this chart I created using the functions in Google Docs – it’s embedded here to always show the distribution of visits during the last 30 days.

The few differences between the GD and Excel versions of the functions are that in the GD versions, you can specify the maximum number of rows fetched (‘maxRows’ parameter). It seems that GD currently gives an “all our servers are currently busy” error when trying to parse a large XML response, and this can be avoided by setting a limit on the rows fetched. My experience is that this error starts to appear when the result set is over 600 rows. You can also specify a ‘startFromRow’ parameter, to work around the row limit by combining several instances of the function.

Also in other ways, the GD version is less stable than the Excel one – every now and then the authentication doesn’t work, or fetching data gives the “servers busy” error. These are caused by problems in Google’s end, so unfortunately there isn’t anything we can do currently to fix them – but Google Docs is developing rapidly so I’m sure the stability will improve.

The other difference is that the GD version doesn’t yet support fetching conversion goals with the getGAaccountData function – I just didn’t have the time to implement that yet.

If you get an error complaining about “rate limit exceeded”, this is due to too many functions being updated simultaneosly (the GA API only allows 10 queries per second). You can avoid this by staggering the queries so that they are not all fired at the same second; to do this, go to Tools: Scripts: Script editor, and in the gatGAdata function, above the line which has the UrlFetchApp, insert these two rows:

var randnumber = Math.random()*5000;

Utilities.sleep(randnumber);

With this in place, the queries will wait for a random time of between zero and five seconds before being updated, thus it’s less likely that you would hit Google’s limitation of 10 queries per second. If you still have trouble, you can duplicate the second row, this will cause a wait of between zero and ten seconds (and of course, you can put this line there as many times as needed, if you’re still hitting the limit).

The code for these functions is now also available in the Google Docs script library.

In case you have any questions regarding the usage of this solution, please visit our help forum.

 

Get started with Supermetrics.

#1 reporting automation tool for PPC, SEO, social and web analytics.
 Free trial with full features. No credit card required.

Start a 30-day free trial