|
  
|
請教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- <!DOCTYPE html>
- <html>
- <head>
- <title>Embed API Demo</title>
- </head>
- <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 = 'xxxxxxx-xxxxxxxxxxxxxxxxx.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:sessions',
- 'start-date': '30daysAgo',
- 'end-date': 'yesterday',
- },
- chart: {
- type: 'LINE',
- container: 'timeline'
- }
- });
- // 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>
複製代碼 |
|
|
|