Google Analytics API quickstart

  • This quickstart guide demonstrates how to set up tools and access, enable the API, install an SDK, and make an API call using either the Data API or the Admin API.

  • You can choose to authenticate with a user account or a service account for this quickstart.

  • Before beginning, you need to create a service account and Google Cloud VM instance, install and initialize the gcloud CLI, and grant the service account access to a Google Analytics property.

  • The Admin API needs to be enabled for your Google Cloud project.

  • SDKs are available for various programming languages, including Java, PHP, Python, Node.js, .NET, Ruby, and Go, and REST access is also supported.

  • The guide provides code samples in multiple languages to demonstrate how to make an API call to list Google Analytics accounts accessible to the authenticated user.

You can use the Data API or Admin API for this quickstart:

Choose an API: Data API Admin API

You can authenticate with a user account or service account:

Choose an account type:

In this quickstart, you create and send a list request.

Here's a summary of the steps:

  1. Set up tools and access.
  2. Enable the API.
  3. Install an SDK.
  4. Make an API call.

Before you begin

  1. Install and initialize the gcloud CLI.

  2. To generate Application Default Credentials and give your account the necessary scopes, run the following:

    gcloud auth application-default login --scopes="https://www.googleapis.com/auth/cloud-platform,https://www.googleapis.com/auth/analytics.readonly"
    
  3. In the Google Analytics UI, grant your user account access to a Google Analytics property.

Enable the Admin API

To select or create a Google Cloud project, and enable the API, click Enable the Google Analytics Admin API.

Enable the Google Analytics API

Install an SDK

Install the SDK for your programming language.