請教o係網站上, 顯示 ga:pageviews, (經google analytics API)

在一個 普通 Web Hosting, 整左個 web site,
join 左 Google Analytics, 有晒資料返晒去.

我想o係個網頁度, 顯示 Google Analytic 所 get 到既 瀏覽量 數據.
上網search左好多資料, 有d亂, 最後都係唔work.

請問我係咪要用 Google Analytic 個 Embed API?
我參考左下面呢度, 跟 Demo 試下做, 都唔work, 唔知邊度出錯左..
https://ga-dev-tools.appspot.com/embed-api/basic-dashboard/
https://developers.google.com/an ... g-started#client-id
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4.   <title>Embed API Demo</title>
  5. </head>
  6. <body>

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

  8. <section id="auth-button"></section>
  9. <section id="view-selector"></section>
  10. <section id="timeline"></section>

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

  12. <script>
  13. (function(w,d,s,g,js,fjs){
  14.   g=w.gapi||(w.gapi={});g.analytics={q:[],ready:function(cb){this.q.push(cb)}};
  15.   js=d.createElement(s);fjs=d.getElementsByTagName(s)[0];
  16.   js.src='https://apis.google.com/js/platform.js';
  17.   fjs.parentNode.insertBefore(js,fjs);js.onload=function(){g.load('analytics')};
  18. }(window,document,'script'));
  19. </script>

  20. <script>
  21. gapi.analytics.ready(function() {

  22.   // Step 3: Authorize the user.

  23.   var CLIENT_ID = 'xxxxxxx-xxxxxxxxxxxxxxxxx.apps.googleusercontent.com';

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

  28.   // Step 4: Create the view selector.

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

  32.   // Step 5: Create the timeline chart.

  33.   var timeline = new gapi.analytics.googleCharts.DataChart({
  34.     reportType: 'ga',
  35.     query: {
  36.       'dimensions': 'ga:date',
  37.       'metrics': 'ga:sessions',
  38.       'start-date': '30daysAgo',
  39.       'end-date': 'yesterday',
  40.     },
  41.     chart: {
  42.       type: 'LINE',
  43.       container: 'timeline'
  44.     }
  45.   });

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

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

  50.   viewSelector.on('change', function(ids) {
  51.     var newIds = {
  52.       query: {
  53.         ids: ids
  54.       }
  55.     }
  56.     timeline.set(newIds).execute();
  57.   });
  58. });
  59. </script>
  60. </body>
  61. </html>
複製代碼

相關文章