我想在我的网络应用程序中嵌入实时Google Analytics(分析)活动用户数

在Google Analytics(分析)信息中心上,它的外观-数字现已随实际活动用户实时变化-:

javascript - 如何将Google Analytics(分析)实时活跃用户公开-LMLPHP

我需要把这个号码放到我的Web应用程序上。

但是API有点奇怪:它仅向“您”(具有Google帐户授权)提供此访问权限



gapi.analytics.ready(function() {
  /**
   * Authorize the user immediately if the user has already granted access.
   * If no access has been created, render an authorize button inside the
   * element with the ID "embed-api-auth-container".
   */
  gapi.analytics.auth.authorize({
    container: 'embed-api-auth-container',
    clientid: '1061030166084-94nlg92ep9aejnepvggfr72pkg4h2lnc.apps.googleusercontent.com'
  });
  /**
   * Create a new ActiveUsers instance to be rendered inside of an
   * element with the id "active-users-container" and poll for changes every
   * five seconds.
   */
  var activeUsers = new gapi.analytics.ext.ActiveUsers({
    container: 'active-users-container',
    pollingInterval: 5
  });
});





那么,如何将这个实时号码作为应用下载促销活动公开给“公众”

最佳答案

“公开”作为应用下载促销


我不确定我是否理解下载促销的含义。

但是,您应该注意以下几点。每个视图每天可以发送到此API的请求数是有限制的。该限制是每天10000个请求。此配额限制适用于所有应用程序,因此如果用户安装了Web应用程序以查看其实时数据,并且安装了我的Web应用程序以查看其Google Analytics(分析)数据,我们将共享10000个请求。如果这样做,您将迅速耗尽用户的配额。在这种情况下,他们将无法在一天的剩余时间内请求更多数据。

假设您仅显示自己网站的实时Google Analytics(分析)数据。您应该做的是让服务在后台运行,该服务每五分钟运行一次,并获取当前计数,然后您可以将存储的计数显示给所有用户,而不是向每个用户发出请求。

您可能要考虑使用服务帐户执行此操作,因为您不必担心身份验证。注意:服务帐户无法使用JavaScript,因此您需要使用服务器端语言。

07-28 07:31