Google Analytics Management API – Uses 1


Google Analytics

Have you ever need to get a list of the Google Analytics accounts for a user of your Application?  Would you like to display a list of Accounts with their associated web properties and views (profiles), to allow the user of your application to select which View they would like to see tracking data for.  Would you like to see a list of Goals a user has set up for a Google Analytics view (profile)?   Well the Google Analytics Management API will let you do all that and more!

Global_managerThe Google Analytics Management API version 3.0 provides you with access to the current Authenticated users Google Analytics account.  You will have access to the same list of accounts the user sees when they login through the Google Analytics Website.   The user may can have access to multiple Google Analytics accounts these can be websites, or mobile apps.

Note: This API doesn’t give you to access the tracking data gathered for each of the users Google Analytics accounts.  For that, you’ll need to look at the Google Analytics Core Reporting or the Google Analytics Real Time Reporting APIs.

Resources

  • Account Summary  – A basic list of Accounts with their associated Web Properties and views.

  • Account –  A list of Accounts the current Authenticated user has access to

  • Web Properties – A list of the Web properties for an account.

  • Views – A list of views for a Web property.

  • Goals – A list of goals for a view.

  • Segments – A list of segments the current Authenticated user has access to.

  • User Account permissions – permissions for the users of the account.

  • Custom Data Sources – available to the the current Authenticated user.

  • Uploads –  uploads for the user’s custom data sources.

Authentication and Scope

In order to use the Google Analytics Management API, your user must be authenticated using Oauth.  When requesting authentication from your user, you should tell them the scope of access you are looking for.

Best Practice: you should only request the level of access that you need. For example, if you’re not going to be writing to a user’s account, don’t ask them to give you permission to write to it.

[table caption=”Scopes” width=”600″ colwidth=”” colalign=”left|left”]
Scope,Meaning
https://www.googleapis.com/auth/analytics.readonly, Read-only access to the Analytics API
https://www.googleapis.com/auth/analytics, Write access to the Analytics API
https://www.googleapis.com/auth/analytics.manage.users, View and manage user permissions for Analytics accounts
[/table]

Account Summary

The account summary report gives you a simple list of all of the accounts and their associated web properties and views in one request, but  the information in this report is very limited. This report is very good to use for displaying lists to your users, allowing them to select which view they would like to see data for when working with the Core Reporting API. This report has been optimized and will return information to you faster than requesting the information individually.

I have an extended tutorial on the Account summary report which includes a sample project for Google Analytics Management API.   Account Summary Report

Account

The only method available to you with account is the list method.  This will allow you to get a list of the accounts the user has access to. The list that is returned is all of the information for that account, including the permissions the user has, when it was created, and a child link to the web properties for each account.

Web Property

The web property resource has several methods you can take advantage of in your application.  All of them require that you know the Account ID in order to use the method.

  • Get – Gets the web property the user has access to. In order to use this method you must already know the Account ID and the Web Property ID for the Web Property you want to get.  This is useful for checking permissions the user may have.

  • Insert – Insert will allow you to create a new web property for an account. In order to use this method you must know the Account ID for the account which you would like to make a new web property for.

  • List –  List returns a list of all of the Web Properties for a given account. In order to use this, you must know the Account ID for the Account you would like get a list of Web Properties for.

  • Patch – Patch allows you to update a web property. In order to use this you must know the Account ID and the Web Property ID for the Web Property you would like to update.

  • Update – similar to patch.

 Views (Profiles)

Profiles have recently been renamed to Views, on the Google Analytics Website.  The API resource is still called profile.  The profiles resource exposes several methods for you to take advantage of in your application.

  • Delete – Allows you to delete a profile.  This requires that you know the Account ID, web property ID and the (view) profile ID for the view you wish to delete.

  • Get – Gets the view.  This requires that you know the Account ID, web property ID and the (view) profile ID for the view you wish to get.  This is useful for checking permission the user may have.

  • Insert –  Allows you to create a new view for the Web Property.  This requires that you know the Account ID, and Web Property ID for the Web Property you would like to add a new view to.

  • List – List returns a list of all of the Views (profiles) that a Web Property contains. This requires that you know the Account ID, and Web Property ID for the Web property you would like list Views (profiles) for.

  • Patch – Allows you to update a View(profile).  This requires that you know the Account ID,  Web Property ID, and View(profile) ID for the View(Profile) you would like to update.

  • Update – similar to patch. 

Goals

The Goals resource exposes several methods you may wish to take advantage of in your application.

  • Get – Gets a goal.  This requires that you know the Account ID, Web Property ID, View(Profile) ID and the Goal ID for the Goal you wish to get.

  • Insert –  Allows you to create a new Goal for a View(Profile).  This requires that you know the Account ID, Web Property ID, and View(Profile) ID for the View(Profile) you would like to add a new Goal to.

  • List – List returns a list of all of the Goals that a View(Profile) contains. This requires that you know the Account ID, Web Property ID, and View(Profile) ID for the View(Profile) you would like to list Goals for.

  • Patch – Allows you to update a Goal.  This requires that you know the Account ID,  Web Property ID, View(profile) ID  and Goal ID for the Goal you would like to update.

  • Update – similar to patch.

 

Segments

The only method available to you with the segments resource is list.   This will return a list of all of the advanced segments the user has access to.

User Links

Account User Links, Web Property User Links, and Profile User Links all give you information about the account permissions for a single user; this is not necessarily the current authenticated user. In the event your current authenticated user is the administrator of the account, they will be able to manipulate the access of others on the account. There are several methods available to you for use with these.

  • Delete – Delete a user

  • Insert – insert a user

  • List – list users for an account

  • Update – update a user

In order to use any of the above methods, you must know the Account ID. It will depend upon which one you are looking at (Account User Links, Web Property User Links, or Profile User Links) if Web property ID and View(Profile) ID are also required. I feel this is an advanced topic and will be creating a post dedicated to it soon.

Custom Data Source

This allows you access to data uploaded from an external data source. The only method available to you is list. I feel this is an advanced topic and will be creating a post dedicated to it soon.

The daily uploads collection is a set of dailyUpload resources, each of which describes a daily upload for one of the user’s custom data sources. Delete , list and upload methods are available through this resource.  I feel this is an advanced topic and will be creating a post dedicated to it soon.

Conclusion

If you need to get information about an Authenticated users account the Management API is where you can find that information.

Sample Project

You can find code for some of this in the main Google Analytics C# tutorial.  I also have a C# sample project for some of this.  I am working on tutorials to go along with it: Google Analytics Management API .Net


About Linda Lawton

My name is Linda Lawton I have more than 20 years experience working as an application developer and a database expert. I have also been working with Google APIs since 2012 and I have been contributing to the Google .Net client library since 2013. In 2013 I became a a Google Developer Experts for Google Analytics.

Leave a comment

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

One thought on “Google Analytics Management API – Uses