您好我如何按照此列表的设备类型获取指标?我正在使用Javascript api
但我还没有找到那里 https://ga-dev-tools.appspot.com/query-explorer/
这是我的简单查询:
gapi.client.analytics.data.ga.get({
'ids': 'ga:' + profileId,
'start-date': '2015-09-06',
'end-date': '2015-09-08',
//'metrics': 'ga:sessions'
'metrics':'ga:visits,ga:sessions,ga:pageviews,ga:browser'
}).
then(function(response) {
答案 0 :(得分:0)
您的查询的“指标”部分中存在错误的参数(ga:浏览器不是指标),并且您不查询任何维度。虽然仅查询指标在技术上是有效的,但您正在关注的是维度,特别是ga:deviceCategory
。这将返回按设备类别细分的维度,该类别有三个可能的值,桌面,移动设备和平板电脑。所以这应该看起来像:
gapi.client.analytics.data.ga.get({
'ids': 'ga:' + profileId,
'start-date': '2015-09-06',
'end-date': '2015-09-08',
'metrics':'ga:visits,ga:sessions,ga:pageviews',
'dimensions':'ga:deviceCategory'
}).
答案 1 :(得分:0)
先谢谢,我发现解决方案是我的代码:
gapi.client.analytics.data.ga.get({
'ids': 'ga:' + profileId,
'start-date': '31daysAgo',
'end-date': 'today',
'dimensions': 'ga:pageTitle,ga:deviceCategory',
'metrics':'ga:visits,ga:sessions,ga:pageviews'
}).then(function(response) {
var formattedJson = JSON.stringify(response.result, null, 2);
//send the values to some label
$("#visitasReport").text(response.result.totalsForAllResults["ga:visits"]);
$("#duracionReport").text(response.result.totalsForAllResults["ga:sessions"]);
var arregloPaginas = [],arregloDevices = [];
var totalTablet=0,totalMobil=0,totalDesktop=0;
function Array(t, a, l) {
this.titulo = t;
this.a = a;
}
for(var x=0;x<response.result.rows.length;x++){
if(response.result.rows[x][2]!=0){
var a = new Array(response.result.rows[x][0],response.result.rows[x][2]);
arregloPaginas.push(a);
//calculate the numbers of visits view the console.log(response.result)
if(response.result.rows[x][1]=="mobile"){totalMobil+=parseInt(response.result.rows[x][2]);}
if(response.result.rows[x][1]=="desktop"){totalDesktop+=parseInt(response.result.rows[x][2]);}
if(response.result.rows[x][1]=="tablet"){totalTablet+=parseInt(response.result.rows[x][2]);}
}
}
$("#reportDesktop").text(totalDesktop);
$("#reportMobile").text((totalTablet+totalMobil));
var totalVisits=response.result.totalsForAllResults["ga:visits"];
//send data to Charts
Morris.Bar({
element: 'morris-bar-chart',
data:arregloPaginas,
xkey: 'titulo',
ykeys: ['a'],
labels: ['Visitas'],
hideHover: 'auto',
resize: true
});
Morris.Donut({
element: 'morris-donut-chart',
data: [
{label: "Celulares",value: Math.round((totalMobil*100)/totalVisits)},
{label: "Escritorio",value: Math.round((totalDesktop*100)/totalVisits)},
{label: "Tablets",value: Math.round((totalTablet*100)/totalVisits)}
],
resize: true
});
/********************************/
}).then(null, function(err) {
// Log any errors.
console.log(err);
});
这是信息中心