Understanding the Google Analytics API

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

Google Analytics is generally viewed as a tool that is, after the initial implementation, controlled and read from the web user interface. An average user can definitely be satisfied with all the reports and configuration options inside the web user interface, but Google Analytics has a lot more to offer through its API.

What is an API?

API stands for Application Programming Interface. Public-facing APIs allow software developers to build their own products on top of different services. Let’s take a look at a few examples that not only better explain the functions of APIs, but also give a good overview of the three types of APIs Google Analytics offers.

Using an API to Extract Data

Imagine that you’re developing an application for gardening. To make your application richer for the end user you decide to include a weather forecast into the application. Because building weather stations all over the world to satisfy every location does not make sense, you decide to use the data from one of the existing weather services. After a short search you discover that you can request for weather reports for free through an online weather reporting service like OpenWeatherMap using their API. Now your application can ask the OpenWeatherMap about the weather in Seattle this Sunday and get an appropriate response. Questions like this one pointed at API services are called queries. As you may have assumed, querying for the data uses server resources of the API service that we are querying—that is why API services use quotas, limits, and pricing plans. Limits and quotas are something that we will have to deal with when using Google Analytics and Google Tag Manager APIs as well, but more about that later! Much like a gardening application can show weather data, a custom dashboard can display data from your Google Analytics views using the Reporting API.

Using API to Send Data

Let’s go back to our gardening application. The novice gardener uses the information that our app provides (which included the weather report) and decides to plant strawberries next Saturday when conditions seem to be perfect. To make sure our gardener does not forget about their plans, the application includes an option to store a schedule in the Google Calendar. To make the process easier, the application sends data to Google Calendar through the Google Calendar API where the data is collected and stored by the service. Just like Google Calendar can collect information about user’s plans, Google Analytics collects hit information through its Collection API called the measurement protocol. Because Google Analytics hits are processed through a predefined set of views, filters, and other settings, the Google Analytics API also enables us to access and update those settings through the Google Analytics’ Configuration API or in case where the digital property uses Google Tag Manager through its API.

APIs and the Google Analytics Platform

Screen Shot 2016-02-02 at 12.37.05 PMNow that we know what APIs are capable of let’s look at where and how they provide additional value to Google Analytics. Google Analytics platform is build out of four main components: Collection, Configuration, Processing, and Reporting.

The Collection Component

The collection component collects interactions by sending raw hits of users’ behavior to Google Analytics. As you can see from the image, with an exception of “classic” Google Analytics implementation (ga.js), all collection hits are sent to Google Analytics through the measurement protocol. Measurement Protocol is a low level protocol for Google Universal Analytics that allows developers to track user interactions using “raw” HTTP requests or using libraries and development kits built around the protocol. In the future all hits will “travel” to Google Analytics through this protocol. Measurement Protocol represents the collection API for Google Analytics that we can use to sent one of the eight hit types (pageview, screenview, event, transaction, item, social, exception, timing) to Google Analytics’ storage.

The Configuration Component

Configuration component of the Google Analytics platform provides the information needed regarding how data should be processed. This is the place where accounts, properties, views, filters, user permissions, goals, segments and other are set up. As you can see from the sketch this can be accessed and configured through Management and Provisioning API. The Provisioning API is available only through an invitation and is used to create and enable Google Analytics accounts at scale. The Management API is used for everything else. As the name suggests we use it for managing accounts, properties, views, and any associated functionalities like filters and goals.

The Processing Component

Processing component does not have an API associated with it. In this component Google Analytics processes the raw data provided from the collection component by applying settings from configuration component. Once the data is processed it is permanently changed and ready to be read by the reporting component.

The Reporting Component

The final component deals with reporting. Most commonly we work with in the Google Analytics’ web interface when we are looking through processed data. There are several Reporting APIs that allow you to query for processed data. Mostly they are use to automated tasks or extract data for custom dashboards and building own business insights. The reporting component has “read only” access through the following APIs: Core Reporting API (for extracting historical data), Embed API (which lies on top of the Core Reporting API and lets user build custom dashboards fast), Multi-Channel Funnels Reporting API (to derive conversion path data), Real Time Reporting API (for querying real time hit data) and Metadata API (to access list of available dimensions and metrics).