Reputation: 6417
I have a site that allows users to post their websites. I want to display some graphs from their Google Analytics account on my pages, showing traffic, visitors, etc.
I have seen this similar feature on Flippa
It asks you to authorize their account via OAuth2 (https://developers.google.com/analytics/devguides/reporting/core/v3/).
I've also seen Google Analytics Embed API (https://developers.google.com/analytics/devguides/reporting/embed/v1/), so I'm confused on which I should be using.
It seems using the Embed API is easiest, however, it only uses a client id. I want to show these pages publicly to everyone, so I will need an access token to request in behalf of the user right?
So here are my questions:
Let me know if I'm missing something. Thanks!
Upvotes: 0
Views: 562
Reputation: 30461
To answer your questions:
1) It's not really a one or the other kind of thing. The Embed API actually uses the Core Reporting API under the hood to query data and display it on the page. You can think of the Embed API as kind of a wrapper on top of the Core Reporting API, making it easier to use from JavaScript.
2) If you have access to a Google Analytics view, then yes, you can use the Embed API to display data from that view. If you want to display data to users who don't have access to that view, then you'll have to authorize on their behalf. You can do that using the Embed API's serverAuth
option. Here are the docs for that:
https://developers.google.com/analytics/devguides/reporting/embed/v1/component-reference#auth
3) Again, these aren't two competing technologies. The Embed API uses the Core Reporting API under the hood. If you don't use the Embed API then yes you'll have to implement that stuff yourself.
Upvotes: 1