How to use Google Analytics API without any coding

In this article I will show you how to use Google Analytics API without doing any coding.

Introduction to APIs

Application programming interface (or API) is the interface between two program modules.

This interface is made up of set of routines, protocols and tools.

Through API you can:

  1. Create new software applications.
  2. Integrate your application with a third party application.
  3. Enhance the functionality of an existing application.

Every program has to depend upon another program in order to carry out some of its functions.

For example your web browser has to depend upon an operating system in order to work.

Your operating system has to depend upon system applications in order to work.

In fact API itself has to depend upon ABI (Application binary interface) in order to work.

Without APIs, you need to create all of the functionality from scratch and that too at the binary level (01010101).

There are many different types of APIs.

There are APIs used by operating systems, APIs used by non-system applications, APIs used by websites (Web APIs) etc.

A Web API is an API which defines the interface between a web browser and web server.

If you want to use the functionality provided by Facebook in your program/application, then you need to write a program that can interact with Facebook API by making a request called API call.

You need to go through the developers documentation provided by Facebook in order to understand how you can make your program interact with Facebook API.

Similarly, if you want to use the functionality provided by Google Analytics, then you may need to write a program that can interact with Google Analytics API. 

Get the E-book (52 Pages)

Get the E-Book (37 Pages)

Introduction to Google Analytics APIs

Google Analytics provides two types of APIs:

#1 Management API

#2 Core Reporting API

Through management API you can access information related to your Google Analytics accounts (like account ID), web properties and views. But you can’t access actual report data through Management API.

To access the actual report data (like sessions, pageviews, bounce rate etc) you need to use the Core Reporting API.

Following are some of the advantages of using Google Analytics APIs:

#1 Query and manage dozens of analytics properties/websites at once.

#2 Merge Google Analytics data with other data sources.

#3 Retrieve information in almost any way you want.

#4 Schedule Google Analytics exports to Excel, Big Query etc.

#5 Automate dashboards and reports creation.

#6 Reduce/eliminate data sampling through query partitioning.

#7 Automate the import of cost data into Google Analytics

#8 Simplify data extraction, integration and visualization.

#9 and the list goes on …….

You indirectly access both management API and core reporting API without writing any code through the online software provided by Google Analytics. Every time you access one of the report of Google Analytics, you are indirectly using the Google Analytics APIs.

However if you want to access Google Analytics APIs directly, for example access Google Analytics data directly into your spreadsheet, you need to write a code which can make a request to Google Analytics API.

This is where many people struggle.

Writing a code which can make API calls is not easy. So in order to facilitate this process there are number of third party tools out there (like Analytics Canvas) which make it possible to directly interact with Google Analytics APIs without writing any program.

In this article I will show you how to access Google Analytics APIs without doing any coding via the Google Analytics Spreadsheet add-on.

In order to use this add on you need to first get familiar with:

#1 Google Analytics Account Explorer

#2 Google Analytics Dimensions and Metrics Explorer

#3 Core Reporting API Dimensions and Metrics

#4 Core Reporting API Filters

#5 Google Analytics Query Explorer

 

Google Analytics Account Explorer

Through ‘Google Analytics Account Explorer’ tool you can get the following information:

#1 You can determine the list of all the Google Analytics Accounts, Properties and Views you have got access to.

#2 You can determine your account ID, web property ID, view ID and table ID. This information comes handy when later you access Google Analytics (GA) via APIs:

 

In order to use this tool, follow the steps below:

Step-1: Navigate to Google Analytics account explorer: https://ga-dev-tools.appspot.com/account-explorer/

Step-2: Connect this tool to your Google Analytics Account by clicking on the ‘Click here to authorize’ link:

If you are not already logged in your Google account then Google will ask you to log in first.

However if you are already logged in then you will be asked to allow ga-dev-tools.appspot.com to view your Google Analytics data:

Click on the ‘Allow‘  button.

Note: You need this authorization in order to use Account explorer and Query explorer tools.

Step-3: Select your Google Analytics account, web property and view from the drop down menus:

search account information

You can now see the various IDs (account IDs, web property IDs, view IDs and table IDs) related to your GA account.

 

Google Analytics Dimensions and Metrics Explorer

Google Analytics Dimensions and Metrics Explorer tool list and explain all of the dimensions and metrics available via Core reporting API.

It also tells you which dimensions and metrics can be queried/used together.

Not all dimensions and metrics can be queried together.

In order to use this tool, follow the steps below:

Step-1: Navigate to Google Analytics Dimensions and Metrics explorer: https://ga-dev-tools.appspot.com/dimensions-metrics-explorer/

You can also access this tool by clicking on the ‘Dimensions and Metrics explorer‘ link from the left hand side navigation menu while using the Google Analytics account explorer tool:

Note: ‘Account explorer‘, ‘Query Explorer‘, ‘Campaign URL builder‘, ‘Hit Builder‘ and ‘Google Analytics spreadsheet Add-on‘ tools are also accessible via this navigation menu.

You will now see the landing page like the one below:

This landing page list and explain all the dimensions and metrics available via Core Reporting API.

The dimensions and metrics are listed under groups:

The screenshot above shows following groups:

  • User
  • Session
  • Traffic Sources
  • Adwords
  • Goal Conversions
  • Platform or Device

Step-2: Click on the plus (+) button next to a group name to see the list of all the dimensions and metrics which are available for that group:

From the screenshot above we can conclude following two things:

#1 Following dimensions are available for the ‘User’ group:

  1. User Type (ga:userType)
  2. Count of Sessions (ga:sessionCount)
  3. Days Since Last Session (ga:daysSinceLastSession)
  4. User Defined Value (ga:userDefinedValue)
  5. User Bucket (ga:userBucket)

#2 Following metrics are available for the ‘User’ group:

  1. Users (ga:users)
  2. New Users (ga:newUsers)
  3. % New Sessions (ga:percentNewSessions)
  4. 1 Day Active Users (ga:1dayUsers)
  5. 7 Day Active Users (ga:7dayUsers)
  6. 14 Day Active Users (ga:14dayUsers)
  7. 28 Day Active Users (ga:28dayUsers)
  8. 30 Day Active Users (ga:30dayUsers)
  9. Number of Sessions per User (ga:sessionsPerUser)

 

Step-3: Click on the checkbox next to a dimension, to see which metric(s) can be used / queried together with the dimension. For example in the screenshot below, I selected the ‘User Type’ dimension:

Now all the metrics which are greyed out can not be used together with the ‘user type’ dimension.

So the metrics which can be used / queries together with the ‘user type’ dimension are:

  1. Users (ga:users)
  2. New Users (ga:newUsers)
  3. % New Sessions (ga:percentNewSessions)
  4. Number of Sessions per User (ga:sessionsPerUser)

 

Step-4: To learn more about a particular dimension, just click on its name:

Step-5: To learn more about a particular metric, just click on its name:

That’s how you can use dimensions and metrics explorer tool.

Now at this point, you may be wondering, what is the point of knowing all this.

All of the knowledge will later help you when you use the Google Analytics Spreadsheet Add-on.

Core Reporting API Dimensions and Metrics

When we access Google Analytics directly via API, we use the API name of a dimension/metric/segment instead of the web view name (also known as UI name):

web view name

Web view names (or User Interface names) are the names of dimensions, metrics and custom segments you see in Google Analytics reports:

web view names2

Following are the corresponding API names:

api names google analytics

It is important that you understand the difference between web view name and API name.

Otherwise you can’t access GA via API through Google Analytics Spreadsheet Add-on.

Core Reporting API Filters

In order to get meaningful data via Core reporting API, you must know, how to use and apply API filters.

Following is the syntax of the core reporting API filter:

name operator expression

Here,

name – is the API name of a Google Analytics dimension or metric to which you want to apply a filter. For example: ga:region, ga:country, ga:sessions etc.

operator –  it can be any dimension or metric filter operator listed below:

api filters

Note: These operators must be URL encoded before they can be included in a query string. For example the URL encoded form of == operator would be %3D%3D.

However, if you are using ‘Query explorer’ or ‘GA spreadsheet add-on’ that you don’t need to URL encode the operators.

expression – it is a regular expression

For example:

ga:country==United States

This filter instructs the Google Analytics API to report only that hit data (pageview, screenviews, events, items etc) which is from the country called ‘United States’.

Another example:

ga:region=~^c

This filter instructs the Google Analytics API to report the hit data of only those regions whose name start with the letter ‘C’.

Here =~ is one of the dimension filter operator and ^ is the caret sign which has got special meaning in regex.

 

API filters become most useful when they are combined with other filters.

You can use AND and OR operators to combine two or more filters.

The AND operator is denoted by a semicolon ; whereas OR operator is denoted by comma ,

For example:

ga:country==United States;ga:region=~^c

This filter instructs the API to report only that hit data which is from US regions and whose names start with the letter ‘C’.

Another example,

ga:country==United States,ga:country==United Kingdom

This filter instructs the API to report only that hit data which is either from the US or from the UK.

 

Google Analytics Query Explorer

In order to access GA data via core reporting API, you need to build and execute queries. Through Google Analytics query explorer you can do that.

Just to show you how this tool can be used, I will reproduce the data from the following Google Analytics report via API:

organic traffic report

There are few things which you need to note about this report:

#1 This report list only the regions in US.

#2 This report list only those regions whose name start with the letter ‘C’. This was achieved by using an advanced filter on the reporting interface.

#3 A default custom segment called ‘organic search’ is applied to this report.

#4 This report includes one dimension called ‘Region‘ and 4 metrics: New users, % New Sessions, Sessions and Goal 4 value.

#5 This report sort the ‘New Users’ metric in descending order.

 

Follow the steps below to use the Query explorer tool:

Step-1: Navigate to Google Analytics Query explorer tool: https://ga-dev-tools.appspot.com/query-explorer/

Step-2: Select the Google Analytics account, property and view whose data you want to access via the API from the drop down menus:

query explorer

Step-3: Select ‘Start date’ and ‘end date’. This is the date range for which you want to see the data:

set the date range

set the date range2

Step-4: Select the metrics you want to include in your report from the drop down menu:

select metrics

select metrics2

Here I have selected the four metrics whose API names are: ga:newUsers, ga:percentNewSessions, ga:sessions and ga:goal4value in order to reproduce the data from the GA report above.

Step-5: Select your dimension (in this case ga:region) from the drop down menu:

select dimension

Step-6: Select the sorting order and the sorting direction from the drop down menu:

select sort

I selected new users descending (-ga:newUsers) because the GA report above, sort the ‘New Users’ metric in descending order.

Step-7: Enter the filter expression in the ‘filters’ box:

api filters2

I entered the following filter expression: ga:country==United States;ga:region=~^c because the GA report  (whose data i want to reproduce) list only those regions in US whose name start with the letter ‘C’.

Step-8: Select the ‘organic traffic’ segment from the drop down menu:

organic traffic segment

Step-9: Set the sampling level (to adjust data sampling) to DEFAULT, FASTER or HIGHER_PRECISION:

sampling level

I set the sampling level to DEFAULT by leaving the ‘sampling level’ parameter field blank.

Step-10: Set the ‘start index’ parameter:

start index

This parameter is used to specify the row number i.e. the row from where you want to start retrieving the GA data.

For example, if you have got say 1000 rows in your report and you want to retrieve data from the 900th row then set the ‘start index’ parameter to 900.

The default value of this parameter is 1 which can also be specified by leaving the ‘start index’ parameter field empty.

Since I want to retrieve results from the beginning, I left the ‘start index’ parameter field empty.

 

Step-11: Set the ‘max-results’ parameter:

max-results

This parameter denotes the maximum number of rows you want to include in your report.

Since I don’t want to include more than 10 rows in my report, I set the max-results parameter to 10.

Step-12: Click on the ‘Run Query’ button. You will then see a report from the query explorer tool like the one below:

query explorer report

Note the data from this report matches with our Google Analytics report:

organic traffic report

This proves that our query was correct.

 

Google Analytics Spreadsheet Add-on

Once you understand how to use the query explorer, you are in a good position to use the Google Analytics spreadsheet add-on.

Through this add-on you can access Google Analytics data directly via core reporting API into a Google Spreadsheet.

Just to show you how this tool can be used, I will reproduce the data from the following Google Analytics report via the Google Analytics spreadsheet add-on:

organic traffic report

Follow the steps below to use this tool:

Step-1: Install Google Analytics Spread sheet add-on from here: https://chrome.google.com/webstore/detail/google-analytics/fefimfimnhjjkomigakinmjileehfopp

Step-2: Open a new Google Spreadsheet and then go to Add-ons menu > Google Analytics > ‘Create New Report‘:

create new report

Step-3: Configure the new report like the one below:

configure the report

I have selected the metrics and dimension according to the GA report I want to reproduce.

Step-4: Click on the ‘create report’ button. You will then a see a report like the one below:

configure the report2

If you look closely at this report, you can see that following fields are empty:

  1. Start date
  2. End date
  3. Sort
  4. Filters
  5. Segment
  6. Max Results

You can get all of this data from ‘query explorer’.

Once you have supplied all of the required data, your Google spreadsheet may look like the one below:

configure the report3

Note: Here I deleted the value of the ‘Last N Days‘ field and changed the metric ga:goalXXValue to ga:goal4Value.

Step-5: Again navigate to Add-ons menu > Google Analytics > ‘Run Reports‘:

run report

If there is no error in any of your query parameters, you will get a ‘completed successfully’ report status like the one below:

report status

If there is an error in one of your query parameters, you will get a ‘report failed’ report status like the one below:

report status failed

Note: You are less likely to get errors, if you build your queries through query explorer (instead of manually) before you start using GA Spreadsheet add on.

 

Step-6: Click on the ‘ok’ button of the ‘Report Status’ dialog box:

report status

If there is no error in your query parameters then you will see a new tab added to your Google spreadsheet.

This tab contains your new report:

new tab

final report

Note the data from this report matches with the Google Analytics report:

organic traffic report

This is a proof that you correctly downloaded data from Google Analytics into Google Sheets via the ‘Google Analytics Spreadsheet’ add-on.

Other Web Analytics Tools

 

Do you know the difference between Digital Analytics and Google Analytics?


99.99% of course creators themselves don’t know the difference between Digital analytics, Google Analytics (GA) and Google Tag Manager (GTM).

So they are teaching GA and GTM in the name of teaching Digital analytics.

They just copy each other. Monkey see, monkey do.

But Digital analytics is not about GA, GTM.

It is about analyzing and interpreting data, setting up goals, strategies and KPIs.

It’s about creating strategic roadmap for your business.


Digital Analytics is the core skill. Google Analytics is just a tool used to implement ‘Digital Analytics’.

You can also implement ‘Digital analytics’ via other tools like ‘adobe analytics’, ‘kissmetrics’ etc.

Using Google Analytics without the good understanding of ‘Digital analytics’ is like driving around in a car, in a big city without understanding the traffic rules and road signs.

You are either likely to end up somewhere other than your destination or you get involved in an accident.


You learn data analysis and interpretation from Digital analytics and not from Google Analytics.

The direction in which your analysis will move, will determine the direction in which your marketing campaigns and eventually your company will move to get the highest possible return on investment.

You get that direction from ‘Digital analytics’ and not from ‘Google Analytics’.


You learn to set up KPIs, strategies and measurement framework for your business from ‘Digital analytics’ and not from ‘Google Analytics’.

So if you are taking a course only on 'Google Analytics’, you are learning to use one of the tools of ‘Digital analytics’. You are not learning the ‘Digital analytics’ itself.

Since any person can learn to use Google Analytics in couple of weeks, you do no get any competitive advantage in the marketplace just by knowing GA.

You need to know lot more than GA in order to work in digital analytics and marketing field.


So what I have done, if you are interested, is I have put together a completely free training that will teach you exactly how I have been able to leverage digital analytics to generate floods of news sales and customers and how you can literally copy what I have done to get similar results.

Here what You'll Learn On This FREE Web Class!


1) The number 1 reason why most marketers and business owners are not able to scale their advertising and maximise sales.

2) Why you won’t get any competitive advantage in the marketplace just by knowing Google Analytics.

3) The number 1 reason why conversion optimization is not working for your business.

4) How to advertise on any marketing platform for FREE with an unlimited budget.

5) How to learn and master digital analytics in record time.

 
 

My best selling books on Digital Analytics and Conversion Optimization

Maths and Stats for Web Analytics and Conversion Optimization
This expert guide will teach you how to leverage the knowledge of maths and statistics in order to accurately interpret data and take actions, which can quickly improve the bottom-line of your online business.

Master the Essentials of Email Marketing Analytics
This book focuses solely on the ‘analytics’ that power your email marketing optimization program and will help you dramatically reduce your cost per acquisition and increase marketing ROI by tracking the performance of the various KPIs and metrics used for email marketing.

Attribution Modelling in Google Analytics and Beyond
Attribution modelling is the process of determining the most effective marketing channels for investment. This book has been written to help you implement attribution modelling. It will teach you how to leverage the knowledge of attribution modelling in order to allocate marketing budget and understand buying behaviour.

Attribution Modelling in Google Ads and Facebook
This book has been written to help you implement attribution modelling in Google Ads (Google AdWords) and Facebook. It will teach you, how to leverage the knowledge of attribution modelling in order to understand the customer purchasing journey and determine the most effective marketing channels for investment.

Himanshu Sharma

Digital Marketing Consultant and Founder of Optimizesmart.com

Himanshu helps business owners and marketing professionals in generating more sales and ROI by fixing their website tracking issues, helping them understand their true customers purchase journey and helping them determine the most effective marketing channels for investment.

He has over 12 years experience in digital analytics and digital marketing.

He was nominated for the Digital Analytics Association's Awards for Excellence.

The Digital Analytics Association is a world renowned not-for-profit association which helps organisations overcome the challenges of data acquisition and application.

He is the author of four best-selling books on analytics and conversion optimization:

error: Alert: Content is protected !!