如何显示谷歌分析嵌入式报告,而无需登录到谷歌 [英] How to display google analytics embeded reports without being logged in into google

查看:224
本文介绍了如何显示谷歌分析嵌入式报告,而无需登录到谷歌的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下代码,它工作得很好:

I have following code and it works just fine:

<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() {


 var CLIENT_ID = 'my client id goes here';

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


  /**
   * Creates a new DataChart instance showing sessions over the past 30 days.
   * It will be rendered inside an element with the id "chart-1-container".
   */
  var dataChart1 = new gapi.analytics.googleCharts.DataChart({
    query: {
      'ids': 'ga:105112893', // The Demos & Tools website view.
      'start-date': '30daysAgo',
      'end-date': 'yesterday',
      'metrics': 'ga:sessions,ga:users',
      'dimensions': 'ga:date'
    },
    chart: {
      'container': 'chart-1-container',
      'type': 'LINE',
      'options': {
        'width': '100%'
      }
    }
  });
  dataChart1.execute();

</script>

只有当我登录到Google时才有效。但是我想要的是即使我没有登录也能工作。如何实现它?
您可以提供一个一步一步的方法来处理这个问题吗?

It works only if I'm logged in into google. But what I want is this to be working even if I'm not logged in. How to implement that? Could you please provide a step by step approach on how to handle that?

推荐答案

Google Analytics(分析)演示& Tools站点提供了如何在Embed API的服务器端授权演示中按部就班的方法:

https://ga-dev-tools.appspot.com/embed-api/server-side-authorization/

The Google Analytics Demos & Tools site provides a step-by-step approach on how to do that in the Embed API's server-side authorization demo:
https://ga-dev-tools.appspot.com/embed-api/server-side-authorization/

这篇关于如何显示谷歌分析嵌入式报告,而无需登录到谷歌的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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