Google分析嵌入API图表是't渲染

Google Analytic Embed API chart isn't rendered

本文关键字:渲染 API Google      更新时间:2024-06-01

我正在尝试使用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>

如果有人能看一下代码并帮助我,我将不胜感激。

提前感谢

Chris

当我使用客户端ID和视图ID时,您的确切代码对我来说很好。

这让我相信您没有正确设置客户端ID,在这种情况下,您应该在开发人员控制台中收到JavaScript错误。你看了吗?最有可能的问题是你没有设置正确的原点。