Google Analytics Embed API authentication

2019-02-19 03:31发布

I'm looking at getting some stats out of Google Analytics using the Embed API to display on our site using javascript.

My question is:

Is it possible to display the stats without the user authenticating? I.e. I would like to make some traffic statistics available to anonymous users.

Thanks, Chris.

1条回答
爷的心禁止访问
2楼-- · 2019-02-19 04:10

This is definitely possible, but you'll have to get the access token yourself (server side, using whatever OAuth 2.0 flow you want).

Once you have a valid access token, you can pass it to the gapi.analytics.auth component and use the Embed API as normal.

Here's some documentation on that:
https://developers.google.com/analytics/devguides/reporting/embed/v1/component-reference#auth

UPDATE: (07/27/2015)

A demo of server-side authorization with the Embed API is now featured on the Google Analytics Demos & Tools site. You should look there to see a working example.

查看更多
登录 后发表回答