Background

Over the past year, I have been able to work closely with some brilliant digital analysts or digital marketers. They are experts at creating website tracking concepts and implementing them in Google Analytics (GA) and Google Tag Manager (GTM). You don’t need to know how to code for most tasks. But if you know how to code, it can be an advantage in some cases. Especially if you need to manage large or complex analytics accounts. Large businesses have many users and many websites. Google Analytics APIs allow developers to programmatically set up and configure GA accounts and create custom reports, saving a lot of time, hassle and manual errors.

What is an API?

An Application Programming Interface (API) is a set of commands, functions, protocols and objects that programmers can use to create software or interact with an external system. In simple terms, an API is a way for two or more computer programs to communicate with each other. Unlike the UI, which is easy for people to use, you need to call the API with some code.

An API consists of several components:

  • Endpoint: each server has an endpoint.
  • Path: to access a custom API, e.g. endpoint/accounts
  • Method: specifies the request action, e.g. GET, POST, DELETE, etc.
  • Parameters / Request Body: the request data sent to the API.
  • Authentication: to allow only authorised users to access the API.
  • Response: the data that API sends back in response to the request.

Google Analytics API Overview

On the official google analytics developer website, there are 9 different APIs are provided by Google. Currently, APIs are available for Universal Analytics and Google Analytics 4. There are two types of GA APIs. One is an admin and management API, the other is for extracting data for reporting.

API name GA Type Description Usage Case
Management API UA View and manage accounts, properties, views, filters, permissions etc - List accounts & properties
Reporting API v4 UA Query for dimensions & metrics to produce customized reports - Extract historical data
Admin API (Preview) GA4 Access the GA4 configuration data - List all GA4 properties
Data API (preview) GA4 Access report data in GA4 properties - Access GA4 reporting data

How to Get Started?

The prerequisites for working with API are

  • A project on Google Cloud Platform (GCP)
  • Basic knowledge of a programming language, such as Python

Step 1: Create a new project in the Google Cloud Platform Console

Create a project

Step 2: Enable the API

Find the API you want to use in the Marketplace, then enable it! Enable API

Step 3: Create a service account and download the key

Create a service account and generate a secret key. Download and rename the key to client_secrets.json in a project folder that you will use later.

Step 4: Add service account email to GA account access

Last but not least, we need to add the service account email to the Account Access Management and assign it the role of Editor or Analyst.

Voila, you’ve done the first setup with the API. Next, you need to write some code to perform some tasks.

Summary

The Google APIs are useful for large and complex analytics accounts. It’s also a good option for extracting historical data or custom reports. I will write more about Google APIs. See you soon.

PS: I use deepl.com/write new feature to improve my writing. It’s very useful. Check it out!

Reference:

❤️ Please visit my home page for more contents. I look forward to connecting with you via LinkedIn.