Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Analytics PHP Interface (GAPI) User Impersonation

I've currently got around 100 sites in Analytics across a few different Google Accounts and one single account has full permissions for every site. If possible I'd like to avoid having to manually add permissions for the Google Service account to each analytics profile.

I'm using the Google Analytics PHP Interface

When attempting to impersonate a user using the $delegate_email argument, I get the following exception:

GAPI: Failed to authenticate user. Error: "{
    "error": "unauthorized_client",
    "error_description": "Unauthorized client or scope in request."
}

I have read elsewhere about needing to 'Delegate domain-wide authority to the service account' using the Google Apps admin console. However we don't have Google Apps at all. Is there any way around this?

tl;dr Is there a way to get read only access to Google analytics using a service account and impersonating a user without Google Apps?

like image 801
James Avatar asked Nov 01 '22 02:11

James


1 Answers

I would first encourage you to go through the various Scenarios listed on Google OAuth 2.0 documentation and decide which is best for your application.

Service account require that you add a user to each account you wish to access, but with a web server application the end user simply authorizes your application to read their Google analytics data.

The scope you are looking for is:

https://www.googleapis.com/auth/analytics.readonly
like image 93
Matt Avatar answered Nov 09 '22 03:11

Matt