简体   繁体   English

实时显示Google Analytics(分析)数据

[英]Showing Google Analytics Data in real time

I would like to show number of visitors on a site since beginning of the month, number of users on the current day and currently on site. 我想显示自本月初以来网站上的访客数量,当天和当前网站上的用户数量。

I have Google Analytics installed, I tried to solve this issue with Embed API by enabling Google Analytics API from developer console - but I requires user authorization, etc. 我已经安装了Google Analytics(分析),我试图通过从开发者控制台启用Google Analytics(分析)API来解决Embed API的问题-但我需要用户授权等。

What would be the easiest way to show analytics on-site without user authentication and accepting access by Embeded API, etc. Application is written in Angular, so Javascript API is the one I look for. 在没有用户身份验证和不接受Embeded API等访问的情况下,最简单的现场显示分析方法是什么。应用程序是用Angular编写的,因此我寻找Javascript API。

Thank you for any suggestion. 感谢您的任何建议。

Authorization has to happen in order to get the data you want. 必须进行授权才能获取所需的数据。 Either you can let visitors to your site authorize themselves, or you'll have to authorize server-side on their behalf. 您可以让站点的访问者自己授权,也可以代表他们授权服务器端。

Once authorized, you can do something similar to what the Third Party Visualization Embed API demo shows. 获得授权后,您可以执行类似于“ 第三方可视化嵌入API”演示所显示的操作。 It uses a custom ActiveUsers Embed API component and includes the source code to show how it works. 它使用自定义的ActiveUsers Embed API组件,并包含源代码以显示其工作原理。

Whether you use the ActiveUsers component or not, the basic gist is that once the users is authenticated via the Embed API, you have access to the method gapi.client.analytics.data.realtime.get , which you can use to query this data. 无论是否使用ActiveUsers组件,基本要点是,一旦通过Embed API对用户进行身份验证,便可以访问gapi.client.analytics.data.realtime.get方法,您可以使用该方法查询此数据。

Here's where that happens in the source code for the ActiveUsers component: 这是ActiveUsers组件的源代码中发生的情况:
https://github.com/googleanalytics/ga-dev-tools/blob/master/src/javascript/embed-api/components/active-users.js#L69-L87 https://github.com/googleanalytics/ga-dev-tools/blob/master/src/javascript/embed-api/components/active-users.js#L69-L87

Authentication with the Analytics service is mandatory. 必须使用Google Analytics(分析)服务进行身份验证。 But the OAuth 2.0 Service Accounts (for Server to Server Applications) can be used to automate it in many cases. 但是在许多情况下, OAuth 2.0服务帐户(用于服务器到服务器应用程序)可用于使其自动化。

It's unclear to me (from a quick scan) if the Auth options of the Embeed API would work with the automated authentication scheme, you may want to go through the details. 对我而言(从快速扫描中还不清楚),是否Embeed APIAuth选项可以与自动身份验证方案一起使用,您可能需要详细了解。

You should be able to use the Analytics Core Reporting API and maybe the Analytics Real Time Reporting API (beta) which work with the automated authentication according to their guides (look for the Authorisation sections on the left frames of the respective guides). 应该能够使用根据其指南与自动身份验证配合使用的Analytics Core Reporting API以及Analytics Real Time Reporting API(测试版) (请在相应指南的左侧框架中查找“ Authorisation部分)。

Donno if this qualifies as easy, tho, YMMV :) 如果符合条件的话,请不要,YMMV :)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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