我是Google Analytics新手,希望在我的网站

时间:2017-03-08 13:40:58

标签: api google-analytics-api

通过添加google docs中给出的代码,我无法在浏览器窗口中看到任何内容。我也有一个clientID(因为我在代码中没有提到)。我能够在谷歌分析的官方网站上看到我的网页分析,但无法将其嵌入我的网站。任何帮助谢谢你。



<html>
<head>
    <title>Embed API Demo</title>
</head>
<body>
    <div id="embed-api-auth-container"></div>
    <div id="chart-container"></div>
    <div id="view-selector-container"></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() {

  // Step 3: Authorize the user.

    var CLIENT_ID = 'ClientID';

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


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


  var timeline = new gapi.analytics.googleCharts.DataChart({
    reportType: 'ga',
    query: {
      'dimensions': 'ga:date',
      'metrics': 'ga:sessions',
      'start-date': '30daysAgo',
      'end-date': 'yesterday',
    },
    chart: {
      type: 'LINE',
      container: 'timeline'
    }
  });


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

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

0 个答案:

没有答案