简体   繁体   English

Google Analytics(分析)Reporting API:JavaScript中的活跃用户数

[英]Google Analytics Reporting API: number of active users in Javascript

on my site I want to include the number of active users (real-time visitors) somewhere on a banner or whatsoever. 在我的网站上,我想包括横幅上某处或其他位置的活跃用户(实时访问者)数量。 The only problem is, I can only do it via Javascript (no PHP; Java, Phyton...), but I don't want users to sign up to see it. 唯一的问题是,我只能通过Javascript(没有PHP; Java,Phyton ...)来做到这一点,但是我不希望用户注册才能看到它。 I spent hours checking the Google Analytics Reporting API and I understand that what I want to achieve is probably not possible, but wanted to check whether some of you has found workarounds that could work for me, too. 我花了几个小时检查Google Analytics(分析)Reporting API,并且我了解到我可能无法实现的目标,但是我想检查一下您中的某些人是否也找到了对我有用的解决方法。

Thanks much to everyone. 非常感谢大家。 A. 一种。

Here is the documentation of Google Analytics API for realtime: https://developers.google.com/analytics/devguides/reporting/realtime/v3/reference/data/realtime/get#try-it 这是实时Google Analytics(分析)API的文档: https : //developers.google.com/analytics/devguides/reporting/realtime/v3/reference/data/realtime/get#try-it

But if you want a simple counter you already have plenty of sites that offer that, or you can implement one for your self. 但是,如果您想要一个简单的柜台,您已经有很多可以提供该服务的站点,或者您可以自己实现一个。

This one looks quite simple: https://github.com/felladrin/online-visitors-counter 这个看起来很简单: https//github.com/felladrin/online-visitors-counter

You cannot use the GA API without a form of authentication , therefore connecting GA directly to your website without client login isn't possible. 您必须先通过身份验证才能使用GA API ,因此无法在没有客户端登录的情况下将GA直接连接到您的网站。

As a workaround , you can use a middleware solution to pull data from the GA API, and then pull data from that midddleware to your website. 解决方法是 ,您可以使用中间件解决方案从GA API中提取数据,然后将数据从该中间件中提取到您的网站。 Here is an example: 这是一个例子:

GA API ---> Google Sheets ---> Website
  1. Use the GA add-on to pull your data to a Google Sheet 使用Google Analytics(分析)插件将数据提取到Google表格中
  2. Import that data into another Google Sheet with IMPORTRANGE 使用IMPORTRANGE将数据导入到另一个Google表格中
  3. Publish the Google Sheet from 2 so it's publicly readable via API (for instance as CSV). 从2发布Google表格,以便可以通过API(例如CSV)公开阅读。 You will be provided with a URL that looks like https://docs.google.com/spreadsheets/d/e/{some-uid}/pub?gid=0&single=true&output=csv 您将获得一个类似于https://docs.google.com/spreadsheets/d/e/{some-uid}/pub?gid=0&single=true&output=csv的URL
  4. Fetch data from that URL from the website (eg with jQuery ) 从网站的URL获取数据(例如jQuery

Note: you probably don't have to do step 2 if you're careful, and can publish as CSV your sheet from steo 1 directly: since it's a CSV export, people cannot get to the original spreadsheet so no security risk. 注意:如果您小心的话,可能不必执行第2步,并且可以直接从Steo 1以CSV格式发布工作表:由于这是CSV导出,因此人们无法使用原始电子表格,因此没有安全风险。 But just to be on the safe side (eg you could publish the whole spreadsheet by mistake), I would do step 2. 但是为了安全起见(例如,您可能会错误地发布整个电子表格),我将执行第2步。

As for which middleware you want to use, there's probably an infinite number of options :) 至于您要使用哪种中间件,可能有无数的选择:)

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

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