Google Analytics

Management API - Custom Data Source Developer Guide

This document explains how to use the Management API v3 to access Custom Data Source data.

  1. Introduction
  2. Before You Begin
  1. Listing a User's Custom Data Sources
  1. Sample Application


A Google Analytics custom data source is at the third level in the account hierarchy; each Custom Data Source has a single web property resource as its parent and can have a child that is a collection of one or more dailyUpload resources.

The Custom Data Source resource provided by the Management API represents all of the data uploaded from an external data source. The resource also includes metadata that identifies how a custom data source is configured: the name, description, and which views (profiles) have access to uploaded data. This resource is used for cost data uploads.

Before You Begin

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

  • 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.


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


analytics = # Read Hello Analytics Tutorial for details.

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.


The Management API allows you to list custom data sources for an authorized user. To list the custom data sources you need to create a service object to work with the API.

Listing a User's Custom Data Sources

An application can request a list of custom data sources for a user's account by using the Analytics service object and passing the Account ID, and the Web Property ID to the list method. For example, the following code requests a list of all custom data sources for the account with ID 1234 and web property ID UA-1234-1.


try {
  CustomDataSources customDataSources ='1234', 'UA-1234-1').execute();

} catch (GoogleJsonResponseException e) {
  System.err.println("There was a service error: "
      + e.getDetails().getCode() + " : "
      + e.getDetails().getMessage());


  custom_data_sources =

except TypeError, error:
  # Handle errors in constructing a query.
  print ('There was an error in constructing your query : %s' % error)

except HttpError, error:
  # Handle API errors.
  print ('Arg, there was an API error : %s : %s' %
         (error.resp.status, error._get_reason()))
  • If the query was successful, the API will return a 200 status code along with the requested data.
  • If there was an error, the API will return with status code other than 200, as well as a descriptive message describing what caused the error. Read the Error Response section in the reference guide for a full list of all the status codes and what they mean.

In the example above, results of the list method are stored in the customDataSources object. The following code shows how to iterate through them. For an explanation of all the properties of a customDataSource resource, see CustomDataSources.


for (CustomDataSources customDataSource : customDataSources.getItems()) {
  System.out.println("Account ID: " + customDataSource.getAccountId());
  System.out.println("Web Property ID: " + customDataSource.getWebPropertyId());
  System.out.println("Custom Data Source ID: " + customDataSource.getId());
  System.out.println("Custom Data Source Name: " + customDataSource.getName());
  System.out.println("Custom Data Source Description: " + customDataSource.getDescription());
  System.out.println("Linked Views (Profiles):");
  for (ProfilesLinked profilesLinked : customDataSource.getProfilesLinked()) {

  System.out.println("Custom Data Source Created: " + customDataSource.getCreated());
  System.out.println("Custom Data Source Updated: " + customDataSource.getUpdated());


for custom_data_source in custom_data_sources.get('items', []):
  print 'Account ID         = %s' % custom_data_source.get('accountId')
  print 'Web Property ID    = %s' % custom_data_source.get('webPropertyId')
  print 'Custom Data Source ID = %s' % custom_data_source.get('id')
  print 'Custom Data Source Name  = %s' % custom_data_source.get('name')
  print 'Custom Data Source Description = %s' % custom_data_source.get('description')

  print 'Linked Views (Profiles):'
  for profile in custom_data_sources.get('profilesLinked',[]):
    print '  View (Profile) ID = %s' % profile

  print 'Created = %s' % custom_data_source.get('created')
  print 'Updated = %s' % custom_data_source.get('updated')

Authentication required

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

Signing you in...

Google Developers needs your permission to do that.