【发布时间】:2016-10-24 23:57:49
【问题描述】:
我有这个 js 使用ga-ez-dash library 从下面的 Google Analytics 数据中呈现图表,以显示用户访问历史、浏览器历史等。 我可以渲染图表,但问题是我不希望我的所有客户都使用我们的 Google Analytics 帐户登录。有没有办法通过 jquery post/curl php 等自动登录,或者我可以制作 Google Analytics数据公开。任何人都可以提出实现这一目标的最佳方法。任何帮助将不胜感激!
var API_KEY = 'Enter Your API Key Here';
var CLIENT_ID = 'Enter Your Client ID Here';
var TABLE_ID = 'Enter your Table ID here';
// Format of table ID is ga:xxx where xxx is the profile ID.
gadash.configKeys({
'apiKey': API_KEY,
'clientId': CLIENT_ID
});
// Create a new Chart that queries visitors for the last 30 days and plots
// visualizes in a line chart.
var chart1 = new gadash.Chart({
'type': 'LineChart',
'divContainer': 'line-chart-example',
'last-n-days':30,
'query': {
'ids': TABLE_ID,
'metrics': 'ga:visitors',
'dimensions': 'ga:date'
},
'chartOptions': {
height:600,
title: 'Visits in January 2011',
hAxis: {title:'Date'},
vAxis: {title:'Visits'},
curveType: 'function'
}
}).render();
【问题讨论】:
-
如果同一数据被多次访问,则在本地存储/缓存它。序列化 API 返回的 dict 并将其放入某个本地存储中是相当容易的。
-
要让 API 返回数据,用户必须经过身份验证,这就是问题所在,我可以自动登录用户并公开谷歌分析数据吗??!
-
官方没有办法自动登录和拉取数据,也没有办法让它“公开”。
-
尝试Google Apps script,然后您可以将其输出嵌入到页面中。他们提供了一个 GA 连接器。
-
其中一个部署选项允许匿名用户访问。
标签: jquery curl oauth google-analytics google-analytics-api