Google Analytics API: Basic Guide and Key Resources
We are going to look at a veryyy simple way of using the Google Analytics API with Google Drive spreadsheets. All with resources that are 100% free, and only as an initial introduction to what it means working with the API and automating reports. There are much better paid for resources (for example Supermetrics or Next Analytics) but let’s go one step at at time.
How to connect with the Google Analytics API in Google SpreadSheet
- Create a new spreadsheet.
- In Add-ons / Get Add-ons, search for and install the Google Analytics Add-On for Google Spreadsheet:
Note: Before, in Tools / Script editor, you needed to activate the Google Analytics API. And also you needed to access Google Developers to allow the connection to your Google account with the API. Fortunately it now seems that it’s all done by simply installing the Add-on. 🙂
Basic First Reports: getting started with the Google Analytics API in Google Spreadsheet
Once this has been done, you can create and automate your reports. Go to Add-ons / Google Analytics / Create Report and carry out your first tests. You’ll see that it’s very simple and that you even have drop down boxes to choose metrics and dimensions. For example:
When at last you carry out your first query and you see the decimals badly, illegible, as below … don’t go crazy!!
One simple adjustment and you’ll see them like this:
All you have to do is change the “language” of the decimals. You need to put Regional settings: United States to correct this.
Reports advanced configuration: API Google Analytics – Spreadsheet Add On
The previous menu for creating reports will be too short straight away, above all if you want to apply advanced segments, filters, send the results to another Spreadsheet with a different URL etc. So you will start to get more used to this other table with manual configuration.
Name of report, up to the user. Regarding the type of report, it is interesting to highlight that there are various options available to generate reports with the API, including:
- CORE: the main reports you’ve always known, with the metrics and dimensions of the Google Analytics interface (except multi channel conversions): sessions, users, bounce, goals, etc.
- MCF: Multi Channel Funnel (very good to obtain easily campaign assisted conversions, analysis of display campaigns, etc). It´s a pain, at the moment you cannot cross both types of dimensions and metrics… a shame! You have to connect core and mcf reports manually.
View (Profile) ID /ids, is the number of the view from which we want to import the data.
For the period of analysis we select either start and end date, or taking into account data from the last 1 / 7 / 30 / N days.
Following this we enter metrics and dimensions, we define the order of everything, the filters to apply, the level of sampling “desired” (“DEFAULT”, “FASTER”, or “HIGHER_PRECISION”), the row number of the database from which to start obtaining data (Start index, by default 1) and the maximum number of results / rows to be shown.
To finish, we decide if we want to get the results of the report in the same spreadsheet or in another (in this instance, we put the URL).
Official documentation of the Google Analytics Add On for Spreadsheet
Key resources to work with the Google Analytics API
To follow are some tips about the most complex parts of generating reports, above all if we want to configure them manually to have access to greater personalisation.
Google Analytics Dimensions & Metrics Explorer
Each metric and dimension have their specific nomenclature within the API and these are different depending on the type of report we want to generate:
- List/Reference of dimensions and metrics for Core Reports >– List/Reference of dimensions and metrics for MCF Reports>
As icing on the cake, if you select a dimension or metric in the reference, those that cannot be crossed become unselected, which can often be very useful.
List of advanced segments created (Google Analytics APIs Explorer)
Last but not least, you can find the ID – segmentId – for each of your advanced segments in GA connecting with your Google Analytics account in this API Explorer link. By doing this, you will have access to all those segments you have created before in Analytics with the SAME USER you are AUTHORISING.
The API acquires much greater strength with segments, you can compare results between multiple segments easily, etc.
Filters for the Google Analytics API
In the same way as in the interface, we can use all kinds of filters and search strings (same as, contains, regular expressions…), for which we choose the corresponding OPERATOR. They are a bit different depending on what they are going to filter: metrics or dimensions.
And well, that’s all folks! Good luck with your first reports, you’ll see how great it feels to get so much useful data in so little time.
Comments