我正在使用这个例子https://developers.google.com/analytics/devguides/reporting/core/v4/quickstart/web-js 我想在gapi.client.request的正文中插入一个过滤器。
这是我的示例代码
function queryReports() {
gapi.client.request({
path: '/v4/reports:batchGet',
root: 'https://analyticsreporting.googleapis.com/',
method: 'POST',
body: {
reportRequests: [
{
viewId: VIEW_ID,
dateRanges: [
{
startDate: '7daysAgo',
endDate: 'yesterday'
}
],
metrics: [
{
expression: 'ga:pageviews'
}
],
dimensions: [
{
name: 'ga:date'
}
]
// filters: [
// {
// name: 'ga:pagePath=~/mypath/'
// }
// ]
}
]
}
}).then(displayResults, console.error.bind(console));
}
reportRequest 中过滤器的格式是什么?
最佳答案
根据the documentation ,没有名为 filters
的字段。但是,有一个 filtersExpression
字符串字段:
Dimension or metric filters that restrict the data returned for your request. To use the
filtersExpression
, supply a dimension or metric on which to filter, followed by the filter expression. For example, the following expression selectsga:browser
dimension which starts with Firefox;ga:browser=~^Firefox
. For more information on dimensions and metric filters, see Filters reference.
因此您应该能够将以下内容添加到请求正文中:
filtersExpression: 'ga:pagePath=~/mypath/'
关于javascript - Google Analytics 报告 v4(过滤器),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39992579/