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

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

问题描述

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

例如。 com / business / abc /



因此,对于系统中已登录的业务所有者,我想提供一个功能查看网页分析。它会显示特定网页有多少次访问(可能还有其他一些内容)。



有没有一种方法可以使用Google Analytics API限制:


  • 我不希望客户提供自己的UA代码

  • t希望他们要求拥有GA帐户

  • 客户无需拥有Google电子邮件帐户

  • 我不想构建整个前端和后端自己。我宁愿使用现有的东西



我一直在研究这个主题几个小时,试图提出一个解决方案,

以下是我试过的以及发生在我身上的问题:


  • http://ga-dev-tools.appspot.com/demos/embed-api/

    • 这基本上就是我希望我的客户在我的网站上显示的内容(如示例中所示),但Embed Api会尝试授权用户使用他们的拥有(拥有)谷歌分析。我希望它能够使用我自己的Google Analytics数据(或者更确切地说是它的一部分)。

    • 我认为限制数据访问的方式是让我的每一位客户创建一个View GA,将过滤器添加到该视图,以便仅列出客户页面,将用户分配给视图,并使用Embed Api仅显示来自该视图的数据。有几个问题:

      • 要将用户分配到视图,我们需要电子邮件地址。而这必须是Google帐户电子邮件或Google Developers Console(应用程序)创建的项目中的帐户。

      • 换句话说,我无法创建(以我所知的任何方式)并且将帐户作为我的客户的屏蔽帐户,用于他们感兴趣的GA数据子集。它必须是真实用户或实际应用电子邮件地址。

      • 我试图做的是...我在Google Developers Console中创建了一个应用程序,创建了新的OAuth服务帐户。使用Ruby代码(在生产应用程序中将运行在后端)我获得了OAuth令牌。我将我的OAuth服务帐户的这封电子邮件作为用户添加到了View

      • 我希望此服务器端生成的oauth标记可供Embed Api使用。这将实现我在后端生成令牌的效果,并且用户可以在GA用户没有GA属性的情况下使用它。所以我根据文档更改了使用基本Embed Api示例





  gapi.analytics.auth.authorize({
container:'auth',
clientid :'xxx.apps.googleusercontent.com',
serverAuth:{
access_token:'服务器端生成的令牌'
}
});

而不是

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

效果不是我所期望的。该示例不再显示(我看不到我的数据),但我可以在Chrome的Netowrking部分看到它实际上是从GA接收真实数据。但是,由于未知的原因,没有出现任何东西。



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



相关:




  • stackoverflow.com / questions / 13514775 / using-google-analytics-api-to-show-subset-of-data-for-customers -of-web-applicati

  • stackoverflow.com / questions / 3994708 / google-analytics-customer-data

  • stackoverflow.com / questions / 4245132 / google-analytics-api-filter-by-uri

  • embeddedanalytics.com看起来像是有用的东西,但它们的页面和图形看起来像几年前。我想要更漂亮的东西。

  • oocharts .com似乎很有趣,因为他们的docs.oocharts.com提到的关于查询的内容。但是他们不会为他们的产品收取任何费用,所以我对他们的商业模式持怀疑态度,并且是否是一个很好的长期解决方案。

  • 我没有足够的业力发布链接;)



TLDR:向我的客户展示我的GA数据的子集,而不强制他们成为GA用户并将其添加到我的GA帐户。 / p>

任何帮助表示赞赏!

解决方案

知道问题出在哪里,但使用 serverAuth 选项绝对有效。当使用 serverAuth 选项时,您无需指定客户端ID或容器,只需输入以下内容:

  gapi.analytics.auth.authorize({
serverAuth:{
access_token:'服务器端生成的令牌'
}
});

下面是一个例子,如果您输入一个有效的访问令牌并且 ids ,您可以访问该视图:



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


$ b 注意: when像这样做auth,它发生同步。如果您习惯了异步身份验证流程(正常情况),并且您在调用 .authorize 之后添加了侦听成功事件的事件处理程序,那么你的处理程序将永远不会运行。


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

For example example. com/business/abc/

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

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

  • I don't want customers to provide their own UA code
  • I don't want them to require to have GA account
  • Customers don't need to have Google email account
  • I don't want to build entire frontend and backend myself. I would rather use something existing

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/demos/embed-api/
    • This is basically exactly what I want for my customers to be displayed on my site (like in the examples), except that Embed Api tries to authorize users to their own (owned) google analytics. I want it instead to use my own Google Analytics data (or rather part of it)
    • They way I thought about limiting data access would be for every one of my customer to create a View in GA, Add filter to that View so only customer pages are listed there, assign User to the view, and use the Embed Api to display data from that View only. There are a couple of problems with that:
      • To assign User to View we need email address. And this must be either google account email, or account from a project created with Google Developers Console (application).
      • In other words I can't create (in any way that I know) and account that would be a shield account for my customers to subset of my GA data that they would be interested in. It must be either a real user or real application email address.
      • So what I tried to do is... I created an app in Google Developers Console, Created new OAuth Service Account. Using Ruby code (that in production app would be running on backend) I obtained OAuth token. I added this email of my OAuth service account as a User to the View
      • I wanted this server side generated oauth token to be used by Embed Api. That would achieve the effect that I generate the token for on my backend and user can use it without having GA user in my GA property. So I changed according to documentation the basic Embed Api example to use

gapi.analytics.auth.authorize({
  container: 'auth',
  clientid: 'xxx.apps.googleusercontent.com',
    serverAuth: {
      access_token: 'Server side generated token'
    }
});

instead of

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

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.

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 responsbile for displaying it. I would rather use Embed API but it seems not be well suited for the usecase 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 usecase easily and let the business owners see the effects of their marketing (traffic, sales) would be interesting as well.

Related:

  • stackoverflow .com/questions/13514775/using-google-analytics-api-to-show-subset-of-data-for-customers-of-web-applicati
  • stackoverflow .com/questions/3994708/google-analytics-customer-data
  • stackoverflow .com/questions/4245132/google-analytics-api-filter-by-uri
  • embeddedanalytics .com seems like something that could be useful, but their page and graphs looks like from few years ago. I would like something more pretty.
  • 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 longterm solution.
  • I don't have enough karma to post links ;)

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

Any help appreciated!

解决方案

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.

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

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