mrdziuban
mrdziuban

Reputation: 799

How to access Google Analytics through the JavaScript API with one OAuth token?

I'm working on a page that will be available to certain users where they can see shared Google Analytics data. I want to pull the data with JavaScript and I've succeeded in getting an OAuth token for the account with the GA data, but it expires in 1 hour.

How can I use this token for all users coming to the page? I don't need the users to be able to access their own GA data, just the shared data. Is there a way to make the token permanent or to refresh it?

Upvotes: 0

Views: 585

Answers (1)

Matt
Matt

Reputation: 5168

Below I have listed three different possible solutions:

  1. The easiest method might be to grant permission for your desired users to have read access to the view (profile) you want to share and use the embed API to authenticate those users and display that data.

  2. You could look into using the Google Analytics Super proxy. The Google Analytics superProxy allows you to publicly share your Google Analytics reporting data. You can use it to power your own custom dashboards and widgets, transform responses to various formats, test, and much more.

  3. Or you could look into using an authenticated service account. The Google OAuth 2.0 system supports server-to-server interactions such as those between a web application and a Google service. For this scenario you need a service account, which is an account that belongs to your application instead of to an individual end user. Your application calls Google APIs on behalf of the service account, so users aren't directly involved.

Upvotes: 2

Related Questions