使用Google Analytics API的区域图-未采集类型错误无法读取'库'的未定义

Area Charts Using Google Analytics API - Uncaught TypeError Cannot Read 'libraries' of undefined

本文关键字:错误 读取 类型 未定义 API Analytics Google 区域 使用      更新时间:2023-09-26

我正在使用Google Analytics Embed API在我们的网站上放置自定义分析。我已经成功地在我们的网站上授权了API,并创建了许多折线图和饼图。我现在正试图制作一个面积图来显示一些数据,但我一直收到同样的错误,我不知道为什么。我得到的错误是:

Uncaught TypeError: Cannot read property 'libraries' of undefined

根据我的理解,通常未定义意味着缺少某些东西,在这种情况下,我认为。然而,我不确定如何或为什么。

我正在加载API使用:

<script async src="https://www.google-analytics.com/analytics.js"></script>

我创建面积图的脚本如下:

<script>
(function(w,d,s,g,js,fs){
  g=w.gapi||(w.gapi={});g.analytics={q:[],ready:function(f){this.q.push(f);}};
  js=d.createElement(s);fs=d.getElementsByTagName(s)[0];
  js.src='https://apis.google.com/js/platform.js';
  fs.parentNode.insertBefore(js,fs);js.onload=function(){g.load('analytics');};
}(window,document,'script'));
gapi.analytics.ready(function() {
  /**
   * Authorize the user with an access token obtained server side.
   */
  gapi.analytics.auth.authorize({
    'serverAuth': {
      'access_token': '##############################################'
    }
  });

var primaryChart = new gapi.analytics.googleCharts.DataChart({
    query: {
      ids: 'ga:79361233',
      metrics: 'ga:sessions',
      dimensions: 'ga:browser',
      'start-date': '2016-04-04',
      'end-date': '2016-05-03'
    },
    chart: {
      container: 'primaryChart',
      type: 'AREA',
      options: {
        isStacked: true,
        width: '100%',
        height: '200',
        tooltip: {
            trigger: 'focus'
        }
      }
    }
  });
  primaryChart.execute();
});
</script>

我对Line和Pie图表使用相同的设置,它们只是分别使用Line或Pie作为图表部分中的类型参数。然而,这些都奏效了。我已经搜索过了,除了Google的Chart API上的信息之外,我很难找到任何东西,因为我直接查询Analytics API,这与我使用的设置有点不同。

感谢您的帮助。

根据:内置组件参考CCD_ 1唯一支持的值是:行、列、栏、表和GEO请注意,这些值区分大小写,即使拼写正确。