简体   繁体   中英

How to integrate Google Analytics data in my pages?

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

( https://flippa.com/3259993-reserve-met-pr-3-site-with-29-103-uniques-mo-making-avg-88-month-bin-bonus )

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:

  1. What exactly does each do? (Using Google Analytics Core Reporting API vs Embed API)
  2. Can I use Embed API in my situation?
  3. Embed API seems to already have built in graph and charting tools, do I have to re-implement those if I use Core Reporting API?

Let me know if I'm missing something. Thanks!

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM