How to Extend Google Analytics with API (Part 1)

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

Eliminate errors and speed up processes using Google Analytics and Google Tag Manager API
In this 2 part series I will introduce the range and possibilities of Google Analytics and Google Tag Manager API. Taking advantage of these interfaces can have a big impact on your analytics processes (eliminate errors, speed up the process, helps with consistency) and provide additional information about what's happening in your analytics properties. Learning the API is time well spent, and having someone on your analytics team who understands it will prove to be of amazing value. First things first: what is an API? API stands for Application Programming Interface. Public APIs for services are released to allow other software developers to build their own products on top of those services.

The Components of the Google Analytics Platform

The Google Analytics platform is made of 4 components each of which combines to give you a complete analytics reporting solution. Here they are:
  1. Collection - Getting the data into Google Analytics
  2. Configuration - Setting up accounts, properties, views, filters, custom dimensions/metrics, users etc.
  3. Processing - Processes the collected hits according to the configuration
  4. Reporting - Access to processed data
All of these (with the exception of the processing component) are accessible through the API.  That means that we can collect analytics data, configure accounts and access reports without ever entering the Web Interface by writing a set of API calls. By doing that, we can build our own custom applications that are powered by the Google Analytics platform. By doing that our crazy analytics ideas can come to life, but at the same time still rely on Google's amazing platform.

Using Google Analytics API to Track Non-Standard Interactions

Leveraging Collection APIs

Collection API tracks user interactions and sends them to Google Analytics. The most traditional way of doing this is using the  web tracking ga.js and analytics.js. With the growth of mobile and tablet usage, Google Analytics has also developed Android and iOS SDK to track user interactions in mobile applications. But perhaps the most interesting and "raw" way of sending user interactions to Google Analytics is using the collection's API  Measurement Protocol. Using the measurement protocol, any device (microwaves, point of purchase systems, TVs...) with access to the internet can be measured by sending simple HTTP requests. The Problems You Can Solve with Measurement Protocol Measurement Protocol takes the analytics out of the standard environments (web and app) and makes it possible to track user interactions in a huge  new set of environments. To give you just a few ideas: at Analytics Pros we were able to implement Measurement Protocol to track movement in our office. We used PIR sensors and Raspberry PI to measure the game of bocce using the MS Kinect, we have also written about how to use it to  track email opens and showed how we'd implement it in a car dashboard in our measurement protocol debugger article. If you want to start tracking user interactions with your business outside web/app environments, this is the way to go.

Leveraging Configuration APIs

Configuration API was built to provide access to the configuration component of the Google Analytics platform. API is divided in two parts  Management and  Provisioning. While the Provisioning API is in a limited edition and was only made to create Google Analytics accounts at a scale, management API offers the core access to the configuration component of Google Analytics. Using management API, it is possible not only to access the current settings of your Google Analytics accounts, but also to insert, update or delete existing settings. Those settings include basic property and view settings, filters, user permissions, segments, custom dimensions, custom metrics, AdWord links and goals. Besides those management APIs, you can also access or insert uploads, experiments and unsampled reports. The Problems You Can Solve with Configuration API Using the Configuration API has many benefits especially when working with a bigger number of views. It will help you  avoid clerical work, it will  eliminate mistakes and  speed up the process. Here are a few examples to compare the usual approach vs using the Configuration API.
Task Usual Approach With Configuration API
Create 10 custom dimensions for each of your 30 properties. Use the Admin part of the web interface. Open every single property and create every single custom dimension. 300 TIMES !!!!!!!
Estimated time: hours Possible mistakes: high (typos, skipped dimensions, wrong scopes...)
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 (triple check the input data, every property will get those exact dimensions)
Create 20 properties each with 3 different views. Names and settings are provided in a csv file. Use the Admin part of the web interface to create every  one of the 20 properties and then for each property create 3 views (60). Make sure to copy and paste data from the csv correctly.
Estimated time: hours Possible mistakes: medium (data can be copy pasted from the csv, possible wrong settings on views, possible missed views)
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 (run a test on a sandbox account, make sure everything came through, then run it on the real account)
Remove permissions for all users for all accounts (except yourself) on all levels. Only add the active analysts on team with all permissions on account level. A lot of clerical work changing the User Management settings for all accounts (removing and adding).
Estimated time: hours (depends on number of accounts, but a long boring work) Possible mistakes: medium (removing everyone should be easy, possible mistakes and misses when adding new users to accounts, possible permission mistakes when adding a user)
Write a script once then run it every time when faced with a similar task.
Time to write the script (once): 30min Estimated time: minutes Possible mistakes: low (run a test on a sandbox account, make sure everything came through, then run it on the real accounts)
Apply set of 5 filters from the "Marketers" view from the first property to all 50 properties. Again too much of boring clerical work. Creating and setting up the right filter settings for each view.
Estimated time: hours (long boring hours) Possible mistakes: high (once created correctly all filters have to be applied in a correct order to the right views)
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 (run a test on a sandbox account, make sure everything came through, then run it on the real account)

What's Left for Part 2?

In Part 2 we'll focus on the value of Reporting APIs and Google Tag Manager API. You'll learn what APIs to use to answer complex business questions, create custom dashboards, and fix 100 Google Analytics tags in minutes. Target /  Creative Commons License photo credit: ##Erika**