Google 分析嵌入 API 图表未呈现
Google Analytic Embed API chart isn't rendered
我正在尝试使用 Google 分析嵌入 API (https://developers.google.com/analytics/devguides/reporting/embed/v1/component-reference#datachart) 创建图表。身份验证工作正常,但未呈现图表。
这是我的代码:
<html>
...
<body>
<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() {
var CLIENT_ID = '[client id, which I removed for this purpose]';
gapi.analytics.auth.authorize({
container: 'auth-button',
clientid: CLIENT_ID,
});
var chart = new gapi.analytics.googleCharts.DataChart({
query: {
'ids': 'ga: [profile id, removed]',
'metrics': 'ga:sessions',
'dimensions': 'ga:date',
'start-date': '30daysAgo',
'end-date': 'yesterday',
},
chart: {
'type': 'LINE',
'container': 'line-chart',
'options': {
'title': 'Test report',
}
}
});
chart.on('success', function(response) {
response.chart
});
chart.execute();
});
</script>
<div id="auth-button"></div>
<div id="line-chart" style='width:100%;height:300px;'></div>
</body>
</html>
如果有人能看一下代码并帮助我,我将不胜感激。
提前致谢
克里斯
当我使用我的客户端 ID 和视图 ID 时,您的确切代码对我来说工作得很好。
这让我相信您没有正确设置客户端 ID,在这种情况下,您应该会在开发人员控制台中收到 JavaScript 错误。你看那里了吗?最有可能的问题是你没有设置正确的来源。
我正在尝试使用 Google 分析嵌入 API (https://developers.google.com/analytics/devguides/reporting/embed/v1/component-reference#datachart) 创建图表。身份验证工作正常,但未呈现图表。
这是我的代码:
<html>
...
<body>
<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() {
var CLIENT_ID = '[client id, which I removed for this purpose]';
gapi.analytics.auth.authorize({
container: 'auth-button',
clientid: CLIENT_ID,
});
var chart = new gapi.analytics.googleCharts.DataChart({
query: {
'ids': 'ga: [profile id, removed]',
'metrics': 'ga:sessions',
'dimensions': 'ga:date',
'start-date': '30daysAgo',
'end-date': 'yesterday',
},
chart: {
'type': 'LINE',
'container': 'line-chart',
'options': {
'title': 'Test report',
}
}
});
chart.on('success', function(response) {
response.chart
});
chart.execute();
});
</script>
<div id="auth-button"></div>
<div id="line-chart" style='width:100%;height:300px;'></div>
</body>
</html>
如果有人能看一下代码并帮助我,我将不胜感激。
提前致谢
克里斯
当我使用我的客户端 ID 和视图 ID 时,您的确切代码对我来说工作得很好。
这让我相信您没有正确设置客户端 ID,在这种情况下,您应该会在开发人员控制台中收到 JavaScript 错误。你看那里了吗?最有可能的问题是你没有设置正确的来源。