我想通过Google Analytics(分析)嵌入api获得总结果。在下面的代码中,我正在获取会话维度的数据,并且可以选择日期范围。而且我需要获取会话总数,因此它将是动态的,更改日期范围时总数应该更改。就像在Google Analytics(分析)上一样。 有人可以帮我吗?我在文档中找不到解决方案。
gapi.analytics.ready(function () {
gapi.analytics.auth.authorize({
container: 'embed-api-auth-container',
clientid: '570331383902-p1jf7fidacfj02tjccntlr1bl3jgvoe6.apps.googleusercontent.com'
});
gapi.analytics.auth.on('signIn', function () {
document.getElementById('special').classList.add('authorized');
});
var renderSession = {
query: {
metrics: 'ga:sessions',
dimensions: 'ga:date'
},
chart: {
type: 'LINE',
options: {
width: '100%'
}
}
};
var renderUsers = {
query: {
metrics: 'ga:users',
dimensions: 'ga:date'
},
chart: {
type: 'LINE',
options: {
width: '100%'
}
}
};
var dateRange1 = {
'start-date': '14daysAgo',
'end-date': '8daysAgo'
};
var viewSelector = new gapi.analytics.ext.ViewSelector2({
container: 'view-selector-container',
}).execute();
var dateRangeSelector1 = new gapi.analytics.ext.DateRangeSelector({
container: 'date-range-selector-1-container'
})
.set(dateRange1)
.execute();
var dataChart1 = new gapi.analytics.googleCharts.DataChart(renderSession)
.set({
query: dateRange1
})
.set({
chart: {
container: 'chart-1-container'
}
});
viewSelector.on('viewChange', function (data) {
dataChart1.set({
query: {
ids: data.ids
}
}).execute();
var title = document.getElementById('view-name');
activeUsers.set(data).execute();
title.textContent = data.property.name + ' (' + data.view.name + ')';
});
dateRangeSelector1.on('change', function (data) {
dataChart1.set({
query: data
}).execute();
var datefield = document.getElementById('from-dates');
datefield.textContent = data['start-date'] + '—' + data['end-date'];
});
});