Google Analytics

Management API - Goal Developer Guide

This document explains how to use the Management API to access Goal data.

  1. Introduction
  2. Before You Begin
  1. Using A Test Account
  2. Goal Limits and Behavior
  3. Code Examples
  1. Sample Application

Introduction

A Google Analytics Goal is at the fourth and lowest level in the account hierarchy; goals have no child entities. Each Goal resource has a single View (Profile) resource as its parent in the hierarchy.

The Goal data provided by the Management API describes how a goal is configured: its name, value, type, and whether or not it is active.

To learn about the different types of goals that can be created, read Setting Up Goals (Help Center).

Before You Begin

This guide demonstrates how to access the Google Analytics API using the following programming languages:
  • Java
  • Python
  • PHP

  • Read the client libraries page for a complete list of programming language specific client libraries that work with the Management API.
  • Read the Reference Guide to access the API without a client library

Each client library provides a single Analytics service object to access all Management API data. To create the service object you generally have to go through the following steps:

  1. Register your application in the Google Developers Console.
  2. Authorize access to Google Analytics data.
  3. Create an Analytics service object.

If you haven't completed these steps, please stop and read the Hello Google Analytics API Tutorial. This tutorial will walk you through the initial steps of building a Google Analytics API application. Once complete, you will be able to use this guide to perform real-world tasks.

The following code snippet continues from step 3: Create an Analytics service object and contains a variable to store an authorized service object.

Java

Analytics analytics = // Read Hello Analytics Tutorial for details.

Python

analytics = # Read Hello Analytics Tutorial for details.

PHP

$client = // Read Hello Analytics Tutorial for details.

// Return results as objects.
$client->setUseObjects(true);

$analytics = new apiAnalyticsService($client);

The PHP library will return all the API results as an associative array. To return real objects instead, you can call the client useObject method as demonstrated in the example above.

Once you create an Analytics service object, you are ready to make requests to the Management API.

Note: The same Analytics service object can also be used to access the Core Reporting API.

Using A Test Account

If you intend to use the Management API to create and/or configure Goals, it's recommended that you implement and verify your code with a test account. Using a test account will help prevent you from making accidental changes to an active Goal. Once you've tested and confirmed that your code is working as expected using the test account and Goal, then you can start using the implementation with your real accounts.

You can create a test account in the Admin section of the Google Analytics web interface.

Goal Limits and Behavior

The following limits and behaviors are applicable to the Goal resource:

  • There is an upper bound of 20 goals per view (profile). Once an view (profile) reaches this limit, additional goals cannot be created through the API for that view (profile). However, existing goals can be updated and reused. See Limits and Quotas to learn about general limits.
  • Goals cannot be deleted but they can be marked as inactive by setting the Goal active property to False. No data is recorded when a Goal is inactive but historical data will be available.

Code Examples

The Management API allows you to list, get, insert, update, and patch goals for an authorized user. To use any of these methods, you first need to create an Analytics service object, as described in the Before You Begin section.

For code examples that show you how to work with the Goal resource, visit the following method references:

  • list — Lists goals to which the user has access.
  • get — Gets a goal to which the user has access.
  • insert — Create a new goal.
  • patch — Updates an existing goal. This method supports patch semantics.
  • update — Updates an existing goal.

Sample Application

See the Management API Reference Sample for a working example of how to traverse and access all the data in the Management API.

Java


Google Analytics API Java client library Sample

Python


Google Analytics API Python client library Sample

PHP


Google Analytics API PHP client library Sample




Authentication required

You need to be signed in with Google+ to do that.

Signing you in...

Google Developers needs your permission to do that.