Javascript中的Google Analytics(分析)API [英] Google Analytics API in Javascript

查看:55
本文介绍了Javascript中的Google Analytics(分析)API的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Google Analytics(分析)Javascript库来让用户查看他们所在的特定页面的GeoMap.但是,每次他们尝试这样做时,您都必须经过身份验证过程,才能在页面上显示我的数据.我如何找到替代方法.我只想通过可视化图形将我的Google Analytics(分析)数据嵌入到页面上,以便所有匿名查看者都能看到

I am using the Google Analytics Javascript library to let users view a GeoMap of the particular page they are on. However, everytime they attempt to do so, thye have to go through an authentication process only to have my data displayed on my page. How can I find an alternative to this. I only want to embed my Analytics data through a visualized graph on my page so that all anonymous viewers can see it

**我们已经在Google Analytics(分析)中创建了一个帐户. 现在,我们可以获取该站点的统计信息. 打开网站 http://Example.com 单击授权分析按钮. 在打开的窗口中提供Google帐户的凭据. 用户名:xxxx@gmail.com密码:xxx 它将重定向到 http://Example.com 页. 输入表格ID ga:61737784,然后单击绘制图表"按钮,您将获得该网站的统计信息.

**We have created an account in Google analytics. Now we are able to get the statistics of the site. Open the site http://Example.com Click on Authorize Analytics button. Provide the credentials of the Google account in the opened window. Username: xxxx@gmail.com Password: xxx It will redirect to http://Example.com page. Enter the table id ga:61737784 and click on Draw Charts Button, then u will get the statistics for the site.

我的要求是不登录Google Analytics(分析)网站,我应该获取统计信息. 因为最终用户不知道Google Analytics(分析)的凭据. 以下是html和javascript代码.**

My requirement is without login in to Google analytics site I should get the statistics. Because the end user don’t know the credentials of Google analytics. The below is the html and javascript code.**

  <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>

推荐答案

您可以使用Google Analytics(分析)superProxy与未经身份验证的用户共享数据.
您可以使用superProxy创建对Google Analytics(分析)的查询,然后使用superProxy存储的数据来构建图表.我遇到了同样的问题,这是我唯一能找到的解决方案.

You can use Google Analytics superProxy to share data with users who are not authenticated.
You can create queries to Analytics with superProxy and then use the data stored with superProxy to construct your charts. I ran into the same problem, and this was the only solution I could find.

https://developers.google.com/analytics/solutions/google-analytics-super-proxy

这篇关于Javascript中的Google Analytics(分析)API的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆