[英]custom dimension value from Google Analytics
I was working on Google Anlytics Report and I was wondering how to get or return a query parameter value (not a dashboard, a single value based on the filter query) in JavaScript, like page view? 我正在研究Google Anlytics报表,我想知道如何在JavaScript(如页面视图)中获取或返回查询参数值(而不是仪表板,即基于过滤查询的单个值)?
Relevant code: 相关代码:
var dataChart = new gapi.analytics.googleCharts.DataChart({
query: {
dimension: 'ga:dimension1',
metrics: 'ga:pageview'
},
chart: {
container: 'chart-container',
type: 'Table',
options: {
width: '100%'
}
}
});
If you just want to get data from a Google Analytics query, you should use the Data
object (which just runs a query) instead of the DataChart
object (which runs a query and dumps the results into a Google Chart. 如果您只想从Google Analytics(分析)查询中获取数据,则应使用
Data
对象(仅运行查询)而不是DataChart
对象(运行查询并将结果转储到Google Chart中)。
Both Data
and DataChart
objects emit events when their queries and come back successfully, so you just have to listen for those events, and log the results. Data
和DataChart
对象在查询时都会发出事件并成功返回,因此您只需要侦听这些事件并记录结果即可。
Here's an example: 这是一个例子:
// Creates a new report object.
var report = new gapi.analytics.report.Data({
query: {
'ids': 'ga:XXXXXX',
'metrics': 'ga:pageviews',
'dimensions': 'ga:dimension1',
'start-date': '7daysAgo',
'end-date': 'yesterday',
}
});
// Runs the query.
report.execute();
// Specifies the callback function to be run when the query succeeds.
report.on('success', function(response) {
// Logs the entire response object.
console.log(response);
// Logs just the total pageviews.
console.log(response.totalsForAllResults['ga:pageviews']);
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.