Google Analytics图表未显示

时间:2016-10-07 10:42:31

标签: javascript google-analytics google-analytics-api

我按照此演示https://ga-dev-tools.appspot.com/embed-api/basic-dashboard/

我在 CLIENT_ID 中设置了我的客户ID,并在ga中设置了属性ID ('创建',' UX-XXXXX- X',' auto');

我的代码有问题吗?个

我有一个文件 sample.php ,这是我的代码:

<!DOCTYPE html>
<html>
<body>

<!-- Step 1: Create the containing elements. -->

<section id="auth-button"></section>
<section id="view-selector"></section>
<section id="timeline"></section>

<!-- Step 2: Load the library. -->

<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() {

// Step 3: Authorize the user.

var CLIENT_ID = '123456789.apps.googleusercontent.com';

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

// Step 4: Create the view selector.

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

// Step 5: Create the timeline chart.

var timeline = new gapi.analytics.googleCharts.DataChart({
  reportType: 'ga',
  query: {
    'dimensions': 'ga:date',
    'metrics': 'ga:pageviewsPerSession',
    'start-date': '7daysAgo',
    'end-date': 'today',
  },
  chart: {
    'type': 'LINE',
    'container': 'timeline',
    'options': {
      'width': '100%'
    }
  }
});

// Step 6: Hook up the components to work together.

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>

在我的 sample.index

 <!DOCTYPE html>
 <html>
 <head>

 <script>
  (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
  (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
  m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
  })(window,document,'script','https://www.google-analytics.com/analytics.js','ga');

 ga('create', 'UX-XXXXX-X', 'auto');
 ga('send', 'pageview');

</script>

</head>
<body>


<div class="portlet box light-grey">
    <div class="portlet-title" >
        <h4 class="dropdown" dropdown>
            <i class="icon-calendar"></i>
    </div>

    <div class="portlet-body" block-ui="block_statistics">
        <?php include_once("sample.php") ?>

    </div>

</div>
</body>
</html>

0 个答案:

没有答案