如何让用户看到我的谷歌分析图表数据,而无需进行身份验证/登录过程

How to allow users to see my Google Analytics chart data without undergoing authentication/Sign In process

本文关键字:身份验证 过程 登录 数据 用户 我的 分析图 谷歌      更新时间:2023-09-26

我正在使用Google Analytics Javascript库让用户查看他们所在的特定页面的GeoMap。但是,每次他们尝试这样做时,他们都必须通过身份验证过程才能在我的页面上显示我的数据。我怎么能找到一个替代方案呢?我只想嵌入我的分析数据通过可视化的图形在我的页面上,以便所有匿名观众可以看到它。这是处理发生的代码。

   google.setOnLoadCallback(init); 
    /**
    * This is called once the Google Data JavaScript library has been loaded.
    * It creates a new AnalyticsService object, adds a click handler to the
    * authentication button and updates the button text depending on the status.
    */
    function init() 
    {
      myService = new google.gdata.analytics.AnalyticsService('charts_sample');
     /*
       this is essentially the line I want to replace. It anonymously 
       tries to access my viewer's account.I want to set this scope such as it 
       address the  URI of my Analytics account       
     */            
      scope = 'https://www.google.com/analytics/feeds'; 
     /*
       if the above scope is altered to my URI then the below unnecessary login
       steps will not be required at all. This is the reason why my viewers are
       taken to their analytics page which is fundamentally non-existent.
     */   
      $("authButton").onclick = function() {
        // Test if the user is not authenticated.
       if (!google.accounts.user.checkLogin(scope)) 
         {
           // Authenticate the user.
            google.accounts.user.login(scope); 
         } else 
         {
          // Log the user out.
           google.accounts.user.logout();
           getStatus();
         }
      }
     getStatus(); 
  } 
  // gets the account data and then gets the outputs of the requested query              
   function getStatus() 
   {
      getAccountFeed();
      getDataFeed();
   }

   function getAccountFeed() 
   {
      //Here agsain, I want to modify it access my account's URI  
      var myFeedUri ='https://www.google.com/analytics/feeds/accounts/default?max-results=50';
      myService.getAccountFeed(myFeedUri, handleAccountFeed, handleError);
  }
  function getDataFeed() 
  { 
   var myMapPopularityFeedUri = 'https://www.google.com/analytics/feeds/data?ids=ga%3A53482361&dimensions=ga%3ApagePath%2Cga%3Acity%2Cga%3Acountry%2Cga%3Aregion%2Cga%3Alongitude%2Cga%3Alatitude&metrics=ga%3Avisitors&start-date=2011-12-01&end-date=2011-12-25&max-results=50';
  myService.getDataFeed(myMapPopularityFeedUri, handleDataFeed, handleError);  
 }   

如果你能帮忙,我将非常感激。请不要太挑剔。这是我第一个问题。相反,让我知道,我会做出我的修改。

这是一个截图嵌入看起来像我自己的点击,即GA之后通过我的账户获取我自己的数据。geoMap位于页面底部

似乎最好的方法是在分析中创建单独的共享(公共)提要(报告)。如果提要(报告)是在个人凭据下创建的,则需要授权登录才能查看或接收数据。无论使用哪个版本的OAuth或OAuth2,如果您使用请求查看站点上的数据,您应该至少使用API密钥(用于公共报告)或OAuth凭据用于个人报告。

看这个指南:
加载API并发出请求

或从本页选择任何其他示例:
Google Analytics:核心报告API客户端库示例代码(v3)

也使用这个漂亮的工具:
OAuth 2.0 Playground

为map生成API key:
Google Maps API Family

Google Maps JS API教程:Google Maps JavaScript API V3

您是否考虑过使用oAuth2进行授权?