Vijay Kansal
Vijay Kansal

Reputation: 839

Google Analytics - Access custom segments through Service Account

My application needs to fetch Google Analytics data from backend servers.

I am using Google Service Account in my application. Though I have given all permissions to my service account through Google Developer console, it turns out that my service account cannot access custom segments of my user account.

A way could have been to copy these segments from user account to service account, but there seems like no way to login via service account and be able to copy segments from user account to service account.

So, there seems like no way to be able to fetch custom segments in a web application from backend...

Is there any way to do so? Can any other account(web application, Installed application account) serve my purpose? Reading the documentation of above two Google accounts reveals that user would be prompted for authentication (at least once) during authorization in these 2 accounts which is not feasible in backend servers.

I found a similar thread for my query Google Analytics V3 - How to create custom segments for API Service Accounts , but user in this thread resorted to not using segments at all, but I do need to use them in my account.

PS: I am writing my application in RubyOnRails and would be using Ruby Gem for Google Authentication

Upvotes: 3

Views: 718

Answers (1)

Linda Lawton - DaImTo
Linda Lawton - DaImTo

Reputation: 117301

Answer: No there is no way to add segments to the Service account. Even the Mangment api only allows you to list segments not add them. Segment Management API documentation

An Idea: You could us normal Oauth2 Authenticate it using your account, Save the refresh token someplace and use that in your application to see the data. Then it would be like the Application is always you and would be able to see your segments.

Sorry I don't know ruby so I cant help you with getting the idea working.

Upvotes: 2

Related Questions