Using Google Analytics to show subset of data for customers of web application using embed api

大憨熊 提交于 2019-11-28 23:33:55

Without seeing your code it's hard to know where the problem is, but using the serverAuth option definitely works. And when using the serverAuth option, you don't need to specify a client ID or container, all you need to enter is the following:

gapi.analytics.auth.authorize({
  serverAuth: {
    access_token: 'Server side generated token'
  }
});

Here's an example that will work if you enter in a valid access token and the idsfor a view to which you have access:

http://jsbin.com/vukezoheyeco/3/edit

Note: when doing auth like this, it happens sync. This can be a gotcha if you're used to an async auth flow (like normal) and you add an event handler listening for the "success" event after calling .authorize because then your handler will never run.

I think you need the Google Analytics Super Proxy

You download the github package and upload to your own App Engine project, do some minimal configuration and then you have an interface where you can setup Google Analytics API calls which require no user login.

It provides end user URLs that you can use to construct data tables in your front end, it also provides data-table format so it slots right into Google Charts.

So for example, you have a user that needs access to visits, revenue for site section /sectionA/

You set up the GA super proxy to serve them a URL that only includes data for that section - you can try out queries here in the GA query explorer. In this case, metrics=ga:visits,ga:productRevenue and filter~=ga:page=/sectionA/

This produces an end URL with JSON data, that refreshes daily/hourly - your choice. You import this URL into your app.

The end user then logs in to your app, and sees the chart data generated from the end URL for their login. They don't need to know about GA super proxy, they just see the end resulting chart.

You could get more sophisticated by providing dropdowns to select which data chart they see, which changes the GA super proxy URL that is requested.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!