从Google Analytics分析获取数据

问题描述

我正在尝试使用Javascript从Google Analytics(分析)中获取数据,但是未显示登录按钮。我正在执行所有这些步骤:https://developers.google.com/analytics/devguides/reporting/core/v4/quickstart/web-js,但是什么也没做。有想法吗?

<!DOCTYPE html>
<html>
<head>
  <Meta charset="utf-8">
  <title>Hello Analytics Reporting API V4</title>
  <Meta name="google-signin-client_id" content="my_client_id">
  <Meta name="google-signin-scope" content="https://www.googleapis.com/auth/analytics.readonly">
</head>
<body>

<h1>Hello Analytics Reporting API V4</h1>

<!-- The Sign-in button. This will run `queryReports()` on success. -->
<p class="g-signin2" data-onsuccess="queryReports"></p>

<!-- The API response will be printed here. -->
<textarea cols="80" rows="20" id="query-output"></textarea>

<script>
  // Replace with your view ID.
  var VIEW_ID = 'my_view_id';

  // Query the API and print the results to the page.
  function queryReports() {
    gapi.client.request({
      path: '/v4/reports:batchGet',root: 'https://analyticsreporting.googleapis.com/',method: 'POST',body: {
        reportRequests: [
          {
            viewId: VIEW_ID,dateranges: [
              {
                startDate: '7daysAgo',endDate: 'today'
              }
            ],metrics: [
              {
                expression: 'ga:sessions'
              }
            ]
          }
        ]
      }
    }).then(displayResults,console.error.bind(console));
  }

  function displayResults(response) {
    var formattedJson = JSON.stringify(response.result,null,2);
    document.getElementById('query-output').value = formattedJson;
  }
</script>

<!-- Load the JavaScript API client and Sign-in library. -->
<script src="https://apis.google.com/js/client:platform.js"></script>

</body>
</html>

谢谢。

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)