Getting started with google-analytics-api

Download google-analytics-api eBook

Remarks

The Google Analytics APIs allow you to access data within Google Analytics. It should not be confused with the measurement protocol which is used for inserting data into Google Analytics.

The Google Analytics API is split into serval parts.

Google Analytics Reporting APIs

  1. The Google Analytics Core Reporting API v3 gives you access to most of the report data in Google Analytics. With the Core Reporting API you can:

    • Build custom dashboards to display Google Analytics data.
    • Save time by automating complex reporting tasks.
    • Integrate your Google Analytics data with other business applications.
  2. The Google Analytics Reporting API V4 is the most advanced programmatic method to access report data in Google Analytics. With the Google Analytics Reporting API, you can:

    • Build custom dashboards to display Google Analytics data.
    • Automate complex reporting tasks to save time.
    • Integrate your Google Analytics data with other business applications.
  1. The Real Time Reporting API enables you to request real time data—for example, real time activity on a view—for an authenticated user. You can use the Real Time Reporting API to:

    • Display active viewers of a page and create a sense of urgency for users looking at an item with finite inventory.
    • Display the most popular content such as the top 10 active pages.
    • Create and display a real time dashboard.

The Real Time Reporting API, in limited beta, is available for developer preview only. Sign up to access the API.

  1. The Multi-Channel Funnels Reporting API enables you to request Multi-Channel Funnels data for an authenticated user. Data is derived from conversion path data, which shows user interactions with various traffic sources over multiple sessions prior to converting. This allows you to analyze how multiple marketing channels influence conversions over time. For more details on what data is available, read the About Multi-Channel Funnels, as well as About Multi-Channel Funnels Data. With the Multi-Channel Funnels Reporting API you can:

    • Create custom reports using Multi-Channel Funnels data. For example, you could use the Top Conversion Paths data to report on attributes such as relative position of interactions in a conversion path.
    • Integrate Multi-Channel Funnels data with your business data. For example, you could correlate online conversion data with offline sales data and media cost data to arrive at a more complete picture of marketing ROI.
    • Display Multi-Channel Funnels in new environments. For instance, you could create visualizations and other presentations of the data that communicate the value of different marketing channels in driving conversions.

Helpers

  1. The Metadata API returns the list and attributes of columns (i.e. dimensions and metrics) exposed in the Google Analytics reporting APIs. Attributes returned include UI name, description, segments support, and more. You can use the Metadata API to:

    • Automatically discover new columns.
    • Access all dimensions and metrics attributes for Google Analytics reporting APIs.

Note: This only returns metadata for the Core Reporting API and the Reporting API. Not real-time metadata.

  1. The Google Analytics Embed API is a JavaScript library that allows you to easily create and embed a dashboard on a 3rd party website in a matter of minutes. It gives you a set of pluggable components that can work together to build complex tools, making it both simple and powerful at the same time.

Configuration APIs

  1. The Analytics Management API allows for programmatic access to the Google Analytics configuration data. You can build applications to more efficiently manage large or complex Analytics accounts. Large companies with many properties can automate account setup. Even if you are building a reporting application the Management API provides you tools to navigate your account. You can use the Google Analytics Management API to:

    • List all the Account, Property and View information for a user.
    • Manage Properties, Views, and Goals.
    • Manage user permissions for an account hierarchy.
    • Retrieve a View ID to use with the Core Reporting API.
    • Determine which goals are active and access their configured names.
    • Manage Links between Analytics properties and AdWords accounts.
    • Manage Remarketing Audiences.

Write operations in the Management API (e.g. create, update, delete, patch) for Web Property, View (Profile), and Goal resources is currently available as a developer preview in limited beta. If you're interested in using these features, request access to the beta.

  1. The Provisioning API can be used to create new Google Analytics accounts and enable Google Analytics for your customers at scale. It is intended for qualified service providers and large partners. For example, you could use the Provisioning API as part of a new user onboarding process to create a new Google Analytics account for a client and then use additional Management API resources to programmatically configure the account and link it to AdWords. This can all be automated and initiated from within your own admin or reporting interface.

The Provisioning API is available by invitation only. We are not currently accepting new projects.

Versions

There are currently three versions of the Google Analytics API live.

Google Analytics V2 Version 2.4 of the Core Reporting API is an XML-only API that is mostly backwards compatible with version 2.3. (Legacy)

Google Analytics V3 which includes the Core Reporting API, Management API, MetaData API and an number of other APIs. These APIs return Json

Google Analytics V4 which currently only includes the reporting API and is considered to be the most advanced way of retrieving reporting data from Google Analytics.

Accessing Google Analytics APIs

You can technically access the Google Analytics APIs using any programing language that can handle a HTTP Post or HTTP Get request.

That being said, Google has also created a number of official standard client libraries to help you with this. Using a standard client library for your chosen programming language can be much easier than coding it from the ground up yourself.

OFFICAL Client libraries with Google Analytics API support:

  1. Google APIs PHP Client library - GitHub
  2. Google APIs .Net Client library - GitHub NuGet
  3. Google APIs Python Client library - GitHub
  4. Google APIs Java Client library - link
  5. Google APIs Objective-C library - GitHub

There are more libraries here.

Hello World Reporting API - Rest

POST https://analyticsreporting.googleapis.com/v4/reports:batchGet?access_token={Access token from auth request}
{
  "reportRequests":[
  {
    "viewId":"XXXX",
    "dateRanges":[
      {
        "startDate":"2015-06-15",
        "endDate":"2015-06-30"
      }],
    "metrics":[
      {
        "expression":"ga:sessions"
      }],
    "dimensions": [
      {
        "name":"ga:browser"
      }]
    }]
}
 

Introduction

The Google Analytics APIs allow you to access data within Google Analytics. It should not be confused with the measurement protocol which is used for inserting data into Google Analytics.

The Google Analytics API is split into serval parts.

Google Analytics Reporting APIs

  1. The Google Analytics Core Reporting API v3 gives you access to most of the report data in Google Analytics. With the Core Reporting API you can:

    • Build custom dashboards to display Google Analytics data.
    • Save time by automating complex reporting tasks.
    • Integrate your Google Analytics data with other business applications.
  2. The Google Analytics Reporting API V4 is the most advanced programmatic method to access report data in Google Analytics. With the Google Analytics Reporting API, you can:

    • Build custom dashboards to display Google Analytics data.
    • Automate complex reporting tasks to save time.
    • Integrate your Google Analytics data with other business applications.
  1. The Real Time Reporting API enables you to request real time data—for example, real time activity on a view—for an authenticated user. You can use the Real Time Reporting API to:

    • Display active viewers of a page and create a sense of urgency for users looking at an item with finite inventory.
    • Display the most popular content such as the top 10 active pages.
    • Create and display a real time dashboard.

The Real Time Reporting API, in limited beta, is available for developer preview only. Sign up to access the API.

  1. The Multi-Channel Funnels Reporting API enables you to request Multi-Channel Funnels data for an authenticated user. Data is derived from conversion path data, which shows user interactions with various traffic sources over multiple sessions prior to converting. This allows you to analyze how multiple marketing channels influence conversions over time. For more details on what data is available, read the About Multi-Channel Funnels, as well as About Multi-Channel Funnels Data. With the Multi-Channel Funnels Reporting API you can:

    • Create custom reports using Multi-Channel Funnels data. For example, you could use the Top Conversion Paths data to report on attributes such as relative position of interactions in a conversion path.
    • Integrate Multi-Channel Funnels data with your business data. For example, you could correlate online conversion data with offline sales data and media cost data to arrive at a more complete picture of marketing ROI.
    • Display Multi-Channel Funnels in new environments. For instance, you could create visualizations and other presentations of the data that communicate the value of different marketing channels in driving conversions.

Helpers

  1. The Metadata API returns the list and attributes of columns (i.e. dimensions and metrics) exposed in the Google Analytics reporting APIs. Attributes returned include UI name, description, segments support, and more. You can use the Metadata API to:

    • Automatically discover new columns.
    • Access all dimensions and metrics attributes for Google Analytics reporting APIs.

Note: This only returns metadata for the Core Reporting API and the Reporting API. Not real-time metadata.

  1. The Google Analytics Embed API is a JavaScript library that allows you to easily create and embed a dashboard on a 3rd party website in a matter of minutes. It gives you a set of pluggable components that can work together to build complex tools, making it both simple and powerful at the same time.

Configuration APIs

  1. The Analytics Management API allows for programmatic access to the Google Analytics configuration data. You can build applications to more efficiently manage large or complex Analytics accounts. Large companies with many properties can automate account setup. Even if you are building a reporting application the Management API provides you tools to navigate your account. You can use the Google Analytics Management API to:

    • List all the Account, Property and View information for a user.
    • Manage Properties, Views, and Goals.
    • Manage user permissions for an account hierarchy.
    • Retrieve a View ID to use with the Core Reporting API.
    • Determine which goals are active and access their configured names.
    • Manage Links between Analytics properties and AdWords accounts.
    • Manage Remarketing Audiences.

Write operations in the Management API (e.g. create, update, delete, patch) for Web Property, View (Profile), and Goal resources is currently available as a developer preview in limited beta. If you're interested in using these features, request access to the beta.

  1. The Provisioning API can be used to create new Google Analytics accounts and enable Google Analytics for your customers at scale. It is intended for qualified service providers and large partners. For example, you could use the Provisioning API as part of a new user onboarding process to create a new Google Analytics account for a client and then use additional Management API resources to programmatically configure the account and link it to AdWords. This can all be automated and initiated from within your own admin or reporting interface.

The Provisioning API is available by invitation only. We are not currently accepting new projects.

Stats

32 Contributors: 4
Tuesday, November 29, 2016
Licensed under: CC-BY-SA

Not affiliated with Stack Overflow
Rip Tutorial: info@zzzprojects.com

Download eBook