Provisioning partner-controlled accounts – API Developer Guide

Introduction

createAccountTree is a part of the Provisioning API that can be used to create new Google Analytics accounts at scale. Unlike createAccountTicket, createAccountTree does not require any end-user interaction in order to complete creation of the account; the process is entirely automated. This is useful when you need to provision an Analytics account that you control on behalf of a customer, and where you provide a custom view of that data to your customer.

This API is reserved for partners who control their users' websites or web properties. If your users control their own websites or web properties, you should instead create user-controlled Analytics accounts.

Before You Begin

All Google Analytics APIs are accessed in a similar manner. Before you begin with the Provisioning API you should:

  • Read the client libraries page for a complete list of programming language specific client libraries that work with the API.
  • Read the Reference Guide to learn about the API interface and how to access data without a client library.

Each client library provides a single analytics service object to access the Provisioning API. To create the service object you generally have to go through the following steps:

  1. Register your application in the Google API Console.
  2. Authorize to create a new Google Analytics account.
  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 understand how to access Google Analytics APIs to perform real-world tasks.

The Template Account

As part of being whitelisted to use this API, you will have to provide a new Google Analytics Account, which serves as the template account for this API. When new accounts are created, they inherit various settings from the template account, including the Terms of Service acceptor, Organization, and various data sharing settings. See the createAccountTree reference for more details about the template account, including a list of all the inherited data.

Provisioning an Account

To provision a new Google Analytics account, make a request to the createAccountTree API endpoint. You will need the following provisioning details:

  • Account Fields
    • An accountName for the account.
  • Web Property Fields
    • A webpropertyName for the property.
    • A websiteUrl. This should be the URL associated with the user property for this Analytics account.
  • View Fields
    • A profileName for the view.
    • A timezone for the view.

Once you have the details, make an authenticated call to the API endpoint:

POST https://www.googleapis.com/analytics/v3/provisioning/createAccountTree
{
    "accountName": "Analytics Account",
    "webpropertyName": "Default Property",
    "profileName": "Default View",
    "timezone": "America/Los_Angeles",
    "websiteUrl": "www.example-pet-store.com",
}

If successful, the API will respond with the details of the newly created account, web property, and view:

{
    "account": {
        "id": "999999999",
        "name": "Analytics Account",
        "created": "2018-03-16T23:35:20.699Z",
        "updated": "2018-03-16T23:35:20.699Z",
        ...
    },
    "webproperty": {
        "id": "UA-999999999-1",
        "name": "Default Property",
        "websiteUrl": "www.example-pet-store.com",
        "created": "2018-03-16T23:35:20.699Z",
        "updated": "2018-03-16T23:35:20.699Z",
        ...
    },
    "profile": {
        "id": "999999999",
        "name": "Default View",
        "timezone": "America/Los_Angeles",
        "created": "2018-03-16T23:35:20.699Z",
        "updated": "2018-03-16T23:35:20.699Z",
        ...
    },
    ...
}

Account Ownership and Management

The created Google Analytics Account will be owned by whichever user account authorized the response via OAuth. For this reason, we recommend that your organization use a service account to manage the Analytics Account, rather than an individual user account.

After the account has been created, you can configure it with the Management API. Here are some common tasks for a newly created account:

Account Relationships Clarification

Like with all Google APIs, a Google Cloud project is required as a starting point for request authorization. As described in the OAuth 2.0 documentation, this account is where you’ll manage your credentials for API requests. However, the created Google Analytics account is not directly affiliated in any way with the Cloud project, or its managing accounts; It is only affiliated with the user or service account that authorized the request. You can use the Management API if you need to configure account access to the Analytics account.