How to Extend Google Analytics with API Part 2 (+GTM-API)

Subscribe to our monthly newsletter to get the latest updates in your inbox

Access Processed Data with Reporting APIsIn part 1 of the series we've covered the basic structure of Google Analytics platform and discussed many possibilities that collection and configuration API have to offer. In part 2 we'll continue with the Google Analytics' Reporting APIs and as an extra  explore some of the capabilities of Google Tag Manager API.

Accessing Processed Data with Reporting APIs

Reporting API offers access to Google Analytics' processed data. Using this API you can dig deeper into and discover more data than by accessing the web interface. There are 5 APIs that relate to the reporting component of the Google Analytics platform:
  1. Core Reporting - Access data querying by dimensions and metrics
  2. Embed - Javascript library, provides a fast way to create custom GA reports
  3. Multi-Channel Funnels Reporting - Access MCF data querying by mcf dimensions and metrics
  4. Real Time Reporting - Access real time analytics data querying by rt dimensions and metrics
  5. Metadata - Access list of API dimensions and metrics with attributes
The most often used out of the set is the Core Reporting API. With a combination of dimensions and metrics there are thousands of ways to query for your data for a given date range. A very fast way to test this API is through the  query explorer. Just as an example to find the most popular country-browser combination in January for one of your views filtered to Europe your query would be the following. GA Query Explorer Click here to replicate the query for your own view Why does reporting API matter? With reporting API it is possible to create very complex reports and execute them fast. Access to data directly offers a great way to build your own custom dashboards (historic and real time) or put the data next to your existing business data. Especially if you query for data from a powerful programming language your analysis options are limitless. At Analytics Pros we've shown how to extract GA data in R to create custom heat mapsdiscover the related product dimensions and metrics, visualize data by minute and more.

Google Tag Manager API

Just like Google Analytics APIs, GTM API provides a way to access and manage your Google Tag Manager configurations. With it you are able to control:
  1. Accounts
  2. Containers
  3. Tags
  4. Rules
  5. Triggers
  6. Macros
  7. Variables
  8. Container Versions
  9. Permissions
Why does configuration API matter? The reasons to use GTM API relate to those for GA Management API, avoiding clerical work, speeding up the process and eliminating mistakes.
Task Usual Approach With GTM API
Update all GA pageview tags in all containers of an account by adding a new custom dimension. Access every container, find all GA pageview tags, add a custom dimension to the settings.
Estimated time: hours Possible mistakes: very high (missed tags, typos for CD index)
Write a script once then run it every time when faced with a similar task.
Time to write the script (once): 1h Estimated time: minutes Possible mistakes: low (test in in sandbox or a new container version, then run it for all containers )
Add a blocking rule to all GA tags (all containers in an account) Access every container, find all GA tags, add a new blocking rule to it. If blocking rule does not exist yet create one.
Estimated time: hours (long boring hours) Possible mistakes: high (missed tags, blocking rule creation mistakes etc.)
Write a script once then run it every time when faced with a similar task.
Time to write the script (once): 1-2h Estimated time: minutes Possible mistakes: low (test in in sandbox or a new container version, then run it for all containers )