如何解决从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 举报,一经查实,本站将立刻删除。