gpt4 book ai didi

api - 使用 API 嵌入 Google Analytics map View

转载 作者:行者123 更新时间:2023-12-02 03:57:07 26 4
gpt4 key购买 nike

我正在尝试在美国 map 上显示“网站上的活跃用户”计数及其位置。我们安装了 Google Analytics,我们的仪表板正在获取实时数据。我正在尝试将其插入到我们服务器上托管的网页上,以显示在我们公司大楼内的各种屏幕上。

我已通读 this documentation但我没有看到放置此代码的网页上显示任何内容。它只是一个白屏,控制台中没有错误。

看这部分,Polymer Elements ,看起来这是可能的,并且我已经插入了 HTML 元素来执行此操作。然而,什么也没有。

下面是我的代码,出于隐私原因删除了客户端 ID。

<!DOCTYPE html>
<html>
<head>
<title>Embed API Demo</title>
</head>
<body>

<!-- Step 1: Create the containing elements. -->

<section id="auth-button"></section>
<section id="view-selector"></section>
<section id="timeline"></section>

<google-analytics-chart
type="area"
metrics="ga:sessions"
dimensions="ga:date"
startDate="30daysAgo"
endDate="yesterday">
</google-analytics-chart>

<!-- Step 2: Load the library. -->

<script>
(function(w,d,s,g,js,fjs){
g=w.gapi||(w.gapi={});g.analytics={q:[],ready:function(cb){this.q.push(cb)}};
js=d.createElement(s);fjs=d.getElementsByTagName(s)[0];
js.src='https://apis.google.com/js/platform.js';
fjs.parentNode.insertBefore(js,fjs);js.onload=function(){g.load('analytics')};
}(window,document,'script'));
</script>

<script>
gapi.analytics.ready(function() {

// Step 3: Authorize the user.


var CLIENT_ID = 'REMOVED-FOR-PRIVACY';

gapi.analytics.auth.authorize({
container: 'auth-button',
clientid: CLIENT_ID,
});

// Step 4: Create the view selector.

var viewSelector = new gapi.analytics.ViewSelector({
container: 'view-selector'
});

// Step 5: Create the timeline chart.

var chart = new gapi.analytics.googleCharts.DataChart({
query: {
'dimensions': 'ga:country',
'metrics': 'ga:sessions',
'start-date': '30daysAgo',
'end-date': 'yesterday',
},
chart: {
type: 'GEO',
container: 'timeline',
options: {
region: '1', // Western Europe
displayMode: 'markers'
}
}
});

// Step 6: Hook up the components to work together.

gapi.analytics.auth.on('success', function(response) {
viewSelector.execute();
});

viewSelector.on('change', function(ids) {
var newIds = {
query: {
ids: ids
}
}
chart.set(newIds).execute();
});
});
</script>
</body>
</html>

最终,我想嵌入并显示以下两个元素:

Google Analytics Dashboard

最佳答案

我认为这些聚合物元素用于查看访问者有权访问的 GA 帐户上的数据,而不是用于向用户显示有关您网站的结果。

我建议您使用 Google Data Studio 并创建报告。然后将报告嵌入到您的网页上。 https://support.google.com/datastudio/answer/7450249?hl=en

另请注意,这不是实时数据,您可以使用 real time api为此,但我不知道有任何现成的解决方案来显示数据。

关于api - 使用 API 嵌入 Google Analytics map View ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52937085/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com