2012-07-07 107 views
3

我使用Google Analytics Javascript库让用户查看他们所在页面的地理地图。但是,他们每次尝试这样做时,都必须经过身份验证过程才能将我的数据显示在我的页面上。我如何找到替代方案?我只是想通过我的页面上的可视化图表嵌入我的分析数据,以便所有匿名观众可以看到它Javascript中的Google Analytics API


**我们已经创建了谷歌Analytics(分析)帐户。 现在我们可以得到该网站的统计数据。 打开网站http://Example.com 点击授权分析按钮。 在打开的窗口中提供Google帐户的凭据。 用户名:[email protected]密码:xxx 它会重定向到http://Example.com页面。 输入表格编号ga:61737784并点击绘制图表按钮,然后你将得到该网站的统计数据。

我的要求是没有登录到谷歌分析网站我应该得到的统计数据。 因为最终用户不知道Google分析的凭据。 下面是HTML和JavaScript代码。**

<script src="http://apis.google.com/js/client.js?onload=gadashInit" type="text/javascript"></script> 
    <script src="http://analytics-api-samples.googlecode.com/svn/trunk/src/reporting/javascript/ez-ga-dash/gadash-1.0.js" type="text/javascript"></script> 
    <script src="http://www.google.com/jsapi" type="text/javascript"></script> 
    <script src="http://www.google-analytics.com/ga.js" type="text/javascript"></script> 

    <script type="text/javascript"> 
     gadash.configKeys({ 
     'apiKey': xxxxx', 
     'clientId':xxxxx' 
     }); 
     var dataOverTime = new gadash.Chart(); 
     var scoreCard = new gadash.Chart(); 
     var sourceMediumTable = new gadash.Chart(); 
     var baseConfig = { 
     'last-n-days': 30, 
     'query': { 
      'metrics': 'ga:visitors, ga:visits, ga:pageviews', 
     }, 
     'chartOptions': { 
      width: 400 
     } 
     }; 
     var dataOverTimeConfig = { 
     'divContainer': 'dataOverTimeConfig', 
     'type': 'LineChart', 
     'query': { 
      'dimensions': 'ga:date', 
      'sort': 'ga:date' 
     }, 
     'chartOptions': { 
      height: 250, 
      legend: {position: 'bottom'}, 
      hAxis: {title:'Date'}, 
      curveType: 'function' 
     } 
     }; 
     var scoreCardConfig = { 
     'divContainer': 'scorecard', 
     }; 
     var sourceMediumTableConfig = { 
     'divContainer': 'sourceMediumTableConfig', 
     'query': { 
      'dimensions': 'ga:source,ga:medium', 
      'sort': '-ga:visitors', 
      'max-results': 100 
     } 
     }; 
     function renderGraph() { 

     baseConfig.query.ids = document.getElementById('tableId').value; 

     dataOverTime.set(baseConfig).set(dataOverTimeConfig).render(); 

     scoreCard.set(baseConfig).set(scoreCardConfig).render(); 
    sourceMediumTable.set(baseConfig).set(sourceMediumTableConfig).render(); 

     document.getElementById('ui').style.display = 'block'; 

    return false; 
     } 
     </script> 
    <script type="text/javascript"> 

     var _gaq = _gaq || []; 
     _gaq.push(['_setAccount', 'UA-33166458-1']); 
     _gaq.push(['_trackPageview']); 

     (function() { 
     var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true; 
     ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js'; 
     var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s); 
     })(); 

    </script> 
    <script type="text/javascript"> 

     var _gaq = _gaq || []; 
     _gaq.push(['_setAccount', 'UA-32934024-1']); 
     _gaq.push(['_trackPageview']); 

     (function() { 
     var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true; 
     ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google.com/jsapi'; 
     var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s); 
     })(); 

    </script> 
     <script type="text/javascript"> 

      var _gaq = _gaq || []; 
      _gaq.push(['_setAccount', 'UA-32934024-1']); 
      _gaq.push(['_trackPageview']); 

      (function() { 
      var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true; 
      ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://') + 'analytics-api-samples.googlecode.com/svn/trunk/src/reporting/javascript/ez-ga-dash/gadash-1.0.js'; 
      var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s); 
      })(); 

     </script> 
     <script type="text/javascript"> 

      var _gaq = _gaq || []; 
      _gaq.push(['_setAccount', 'UA-32934024-1']); 
      _gaq.push(['_trackPageview']); 

      (function() { 
      var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true; 
      ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://') + 'apis.google.com/js/client.js?onload=gadashInit'; 
      var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s); 
      })(); 

     </script> 
     <button id="Button1" style="visibility: hidden;"> 
     Authorize Analytics</button> 
     <hr /> 
     <p> 
     Enter your Table ID: 
     <input type="text" id="tableId" /> 
     <button onclick="return renderGraph()"> 
     Draw Charts</button></p> 
     <hr /> 
     <div id="ui" style="display: none;"> 
     <h4> 
     Data Over Time</h4> 
     <div id="dataOverTimeConfig"> 
     </div> 
     <h5> 
     Totals for each metric</h5> 
     <div id="scorecard"> 
     </div> 
     <h5> 
     Source and Mediums by Visitor</h5> 
     <div id="sourceMediumTableConfig"> 
     </div> 
+0

这样做你有没有成功?我试图做同样的事情,为客户建立一些报告,并希望避免登录过程,因为他们感到困惑! – 2012-07-16 10:48:41

回答