任何人都可以帮我解决这个问题吗?我需要使用GA api返回多个目标网页的数据。页面浏览量,跳出率,页面平均时间等数据
到目前为止,我已设法在过滤器中设置了1页的数据。无论如何在1个请求中为多个页面执行此操作?
// Google API Library
(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'));
gapi.analytics.ready(function() {
var CLIENT_ID = clientID
var VIEW_ID = viewID;
gapi.analytics.auth.authorize({
container: 'auth-button',
clientid: CLIENT_ID
});
var query = {
ids: VIEW_ID,
metrics: 'ga:sessions,ga:pageviews,ga:avgTimeOnPage,ga:bounceRate',
dimensions: 'ga:date',
filters: 'ga:pagePath=@page1' //<-- page name to search for
}
var report = new gapi.analytics.report.Data({ query });
report.on('success', function(response) {
console.log(response);
});
report.execute();
});
答案 0 :(得分:1)
在过滤器中添加,ga:pagePath=@page2
以获取第二页的数据,并在维度中添加ga:pagePath
,以便将结果中的两个页面分开。
var query = {
ids: VIEW_ID,
metrics: 'ga:sessions,ga:pageviews,ga:avgTimeOnPage,ga:bounceRate',
dimensions: 'ga:date,ga:pagePath',
filters: 'ga:pagePath=@page1,ga:pagePath=@page2' //<-- page name to search for
}