Analytics嵌入window.google.load不是一个功能

时间:2018-03-26 13:47:10

标签: javascript graph google-analytics embed

我尝试按照示例https://ga-dev-tools.appspot.com/embed-api/server-side-authorization/

在服务器端身份验证中嵌入谷歌分析图表
    <div class="bloc_card analytics_graphs" data="<?php echo $token ?>">
      <div id="chart-1-container"></div>
      <div id="chart-2-container"></div>
    </div>



    <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'));
    </script>

    <script>

    gapi.analytics.ready(function() {


        gapi.analytics.auth.authorize({
          'serverAuth': {
            'access_token': '<?php echo $token ?>'
          }
        });


        /**
         * Creates a new DataChart instance showing sessions over the past 30 days.
         * It will be rendered inside an element with the id "chart-1-container".
         */
        var dataChart1 = new gapi.analytics.googleCharts.DataChart({
          query: {
            'ids': 'ga:172003872', // <-- Replace with the ids value for your view.
            'start-date': '30daysAgo',
            'end-date': 'yesterday',
            'metrics': 'ga:sessions,ga:users',
            'dimensions': 'ga:date'
          },
          chart: {
            'container': 'chart-1-container',
            'type': 'LINE',
            'options': {
              'width': '100%'
            }
          }
        });
        dataChart1.execute();

      });
    </script>

但是我得到window.google.load不是一个函数

0 个答案:

没有答案