1
votes

I need to access custom segments in Google Analytics via reporting the API. There is no trouble with it, except that custom segments are not shareable across multiple profiles/users set in Google Analytics, so a segment has to be created for each profile.

And in the case of using a Service Account generated through Google API's Console, segments have to be created for that account – how do I log in to Google Analytics with a Service account having Client ID, email address and public key fingerprint to be able to set segments for it?

It is not currently possible to create segments with the Google Analytics Management API.

Edit:

As of July 9, 2013 Google Analytics added access to custom dimension and metrics. Now it is possible to query custom dimensions without the need to create additional segments, so the roots of my problem have disappeared.

3

3 Answers

2
votes

It currently is not possible to create segments for a service account. As you suggested you'd need to be able to login to the GA account to create it, which is not possible with a service account. The only option right now is to use dynamic segments when querying the Core Reporting API.

3
votes

You have to share your segment to your collaborators to enable the API account to use it in the queries. Just click on the top right link "Change" and choose "Collaborators and I can apply/edit Segment in this View"

create segment view

2
votes

If you want to avoid having to create dynamic segments in your API query, you can also do this: create the segment at you would like it in your Analytics account.

Then go to the API query explorer and scroll down to the "segment" field.

When you select the segment you want, the id will appear. You can use that id to query the API as described here.