gpt4 book ai didi

javascript - 来自 Google Analytics 的自定义维度值

转载 作者:行者123 更新时间:2023-11-28 07:01:09 25 4
gpt4 key购买 nike

我正在研究 Google Anlytics 报告,我想知道如何在 JavaScript 中获取或返回查询参数值(不是仪表板,而是基于过滤器查询的单个值),例如页面 View ?

相关代码:

var dataChart = new gapi.analytics.googleCharts.DataChart({
query: {
dimension: 'ga:dimension1',
metrics: 'ga:pageview'
},
chart: {
container: 'chart-container',
type: 'Table',
options: {
width: '100%'
}
}
});

最佳答案

如果您只想从 Google Analytics 查询中获取数据,则应使用 Data对象(仅运行查询)而不是 DataChart对象(运行查询并将结果转储到 Google 图表中。

DataDataChart 对象在查询并成功返回时都会发出事件,因此您只需监听这些事件并记录结果即可。

这是一个例子:

// 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']);
});

关于javascript - 来自 Google Analytics 的自定义维度值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32124909/

25 4 0
文章推荐: html -
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com