使用 Google Analytics 使用 embed api 为 Web 应用程序的客户显示数据子集 [英] Using Google Analytics to show subset of data for customers of web application using embed api

查看:18
本文介绍了使用 Google Analytics 使用 embed api 为 Web 应用程序的客户显示数据子集的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个应用程序,其中每个业务"都有自己的页面(或者说很多页面):

I'm developing an application where each 'business' has its own page (or rather many pages):

例如example.com/business/abc/

For example example.com/business/abc/

因此,对于系统中已登录的企业主,我想提供一个查看页面分析"功能.它会显示特定页面的访问次数(可能还有其他一些事情).

So, for the logged in business owners in the system I would like to give a feature 'View page analytics'. It would display how many visits (and maybe a couple of other things) that particular page has had.

有没有办法在我的约束下使用 Google Analytics API 做到这一点:

Is there a way of doing this using the Google Analytics API with my constraints:

  • 我不希望客户提供自己的 UA 代码
  • 我不希望他们要求拥有 GA 帐户
  • 客户无需拥有 Google 电子邮件帐户
  • 我不想自己构建整个前端和后端.我宁愿使用现有的东西

我已经研究这个主题好几个小时了,试图想出一个解决方案,但什么也找不到.

I've been researching this topic for hours trying to come up with a solution and can't figure out anything.

这是我尝试过的方法以及发生在我身上的问题:

Here is what I tried and what problems happened to me:

  • http://ga-dev-tools.appspot.com/演示/嵌入 API/
    • 这基本上正是我希望我的客户在我的网站上显示的内容(如示例中所示),除了 Embed Api 尝试授权用户使用他们自己的(拥有的)谷歌分析.我希望它使用我自己的 Google Analytics(分析)数据(或者更确切地说是其中的一部分)
    • 我考虑限制数据访问的方法是让我的每个客户在 GA 中创建一个视图,向该视图添加过滤器,以便在那里只列出客户页面,将用户分配给视图,并使用 Embed Api仅显示来自该视图的数据.这有几个问题:
      • 要将用户分配给查看,我们需要电子邮件地址.并且这必须是 Google 帐户电子邮件,或来自使用 Google Developers Console(应用程序)创建的项目的帐户.
      • 换句话说,我无法(以我所知道的任何方式)创建一个帐户,该帐户将成为我的客户对他们感兴趣的 GA 数据子集的屏蔽帐户.它必须是真实的用户或真实的应用电子邮件地址.
      • 所以我尝试做的是...我在 Google Developers Console 中创建了一个应用程序,创建了新的 OAuth 服务帐户.使用 Ruby 代码(在生产应用程序中将在后端运行)我获得了 OAuth 令牌.我将我的 OAuth 服务帐户的电子邮件作为用户添加到视图中
      • 我希望 Embed Api 使用此服务器端生成的 oauth 令牌.这将实现我在后端生成令牌的效果,用户可以在我的 GA 属性中没有 GA 用户的情况下使用它.因此,我根据文档更改了要使用的基本 Embed Api 示例
      gapi.analytics.auth.authorize({
        container: 'auth',
        clientid: 'xxx.apps.googleusercontent.com',
          serverAuth: {
            access_token: 'Server side generated token'
          }
      });
      

      代替

      gapi.analytics.auth.authorize({
        container: 'auth',
        clientid: 'xxx.apps.googleusercontent.com',
      });
      

      效果和我预期的不太一样.该示例不再显示(我看不到我的数据),但我可以在 Chrome 的 Netowrking 部分看到它实际上是从 GA 接收真实数据.但不知什么原因,什么也没有出现.

      The effects are not quite what I expected. The example doesn't show anymore (I can't see my data) but I can see in Netowrking section in Chrome that it is actually receiving real data from GA. But for unknown reason, nothing is appearing.

      我尽量避免构建一个解决方案,在该解决方案中,我需要构建查询 GA 数据的服务器端代码,将其提供给前端,然后由 JS 负责显示它.我宁愿使用 Embed API,但它似乎不太适合我不希望用户使用他们的 UA 数据而是使用我自己的 UA 数据限制在某些范围内的用例.我希望至少解决解决方案的前端或后端部分.该解决方案甚至不需要基于 Google Analytics.任何其他能让我轻松实现用例并让企业主看到他们的营销(流量、销售)效果的东西也会很有趣.

      What I try to avoid is building a solution in which I need to build server side code that is querying GA for data, providing it to the frontend and then JS is responsible for displaying it. I would rather use Embed API but it seems not to be well suited for the use case where I don't want users to play with their UA data but rather with my own UA data limited to some scope. I would like to have at least the frontend or backend part of the solution solved. The solution doesn't need to be even Google Analytics based. Anything else that would let me achieve the use case easily and let the business owners see the effects of their marketing (traffic, sales) would be interesting as well.

      相关:

      • Using google analytics API to show subset of data for customers of web application
      • Google analytics customer data?
      • Google Analytics API: filter by URI?
      • https://embeddedanalytics.com seems like something that could be useful, but their page and graphs look like from a few years ago. I would like something more pretty.
      • https://oocharts.com seems to be interesting because of what their docs.oocharts.com says about queries. But they don't charge anything for their product so I am skeptical of their business model and whether it is a good long-term solution. update: dead link
      • I don't have enough karma to post links ;)

      TLDR:向我的客户显示我的 GA 数据子集,而不强迫他们成为 GA 用户并将他们添加到我的 GA 帐户.

      TLDR: Displaying subset of my GA data to my customers without forcing them to become GA users and adding them to my GA account.

      感谢任何帮助!

      推荐答案

      如果没有看到您的代码,很难知道问题出在哪里,但是使用 serverAuth 选项绝对有效.并且在使用 serverAuth 选项时,您不需要指定客户端 ID 或容器,您只需输入以下内容:

      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'
        }
      });
      

      这是一个示例,如果您输入有效的访问令牌和您有权访问的视图的 ids:

      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

      注意:像这样进行身份验证时,会发生同步.如果您习惯于异步身份验证流程(像正常一样)并且在调用 .authorize 后添加一个监听成功"事件的事件处理程序,这可能是一个问题,因为这样您的处理程序将永远不会运行.

      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.

      这篇关于使用 Google Analytics 使用 embed api 为 Web 应用程序的客户显示数据子集的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆