admin管理员组文章数量:1414621
How would I go about passing multiple dimensions when executing a Google Analytics Reporting API v4 Query. For example how would I pass ga:dimension7 in addition to ga:dimension5 in my dimensions?
function queryReports() {
gapi.client.request({
path: '/v4/reports:batchGet',
root: '/',
method: 'POST',
body: {
reportRequests: [
{
viewId: VIEW_ID,
dateRanges: [
{
startDate: '7daysAgo',
endDate: 'today'
}
],
dimensions: [
{
name: 'ga:dimension5'
}
],
metrics: [
{
expression: 'ga:totalEvents',
alias: 'orderNumber'
}
],
filtersExpression: 'ga:eventCategory==xxx,ga:eventAction==xxx',
filtersExpression: 'ga:dimension5=~\^\\\[.*\\\]\$'
}
]
}
}).then(displayResults, console.error.bind(console));
}
How would I go about passing multiple dimensions when executing a Google Analytics Reporting API v4 Query. For example how would I pass ga:dimension7 in addition to ga:dimension5 in my dimensions?
function queryReports() {
gapi.client.request({
path: '/v4/reports:batchGet',
root: 'https://analyticsreporting.googleapis./',
method: 'POST',
body: {
reportRequests: [
{
viewId: VIEW_ID,
dateRanges: [
{
startDate: '7daysAgo',
endDate: 'today'
}
],
dimensions: [
{
name: 'ga:dimension5'
}
],
metrics: [
{
expression: 'ga:totalEvents',
alias: 'orderNumber'
}
],
filtersExpression: 'ga:eventCategory==xxx,ga:eventAction==xxx',
filtersExpression: 'ga:dimension5=~\^\\\[.*\\\]\$'
}
]
}
}).then(displayResults, console.error.bind(console));
}
When I separate them with ma,then I have the error below:
Any idea?
Share Improve this question edited Nov 4, 2016 at 9:21 Atzmon 1,3181 gold badge7 silver badges15 bronze badges asked Nov 4, 2016 at 3:29 PlutorsPlutors 721 silver badge9 bronze badges3 Answers
Reset to default 3I have the answer below:
POST https://analyticsreporting.googleapis./v4/reports:batchGet
{
"reportRequests":[
{
...
"dimensions": [
{
"name":"ga:dimension3"
},{
"name":"ga:dimension5"
}],
...
}]
}
see details here guide to migrate the Core Reporting API V3 to the Analytics Reporting API V4
sample_request = {
'viewId': 'xxxxxxxxx',
'dateRanges': {
'startDate': datetime.strftime(datetime.now() - timedelta(days = 30),'%Y-%m-%d'),
'endDate': datetime.strftime(datetime.now(),'%Y-%m-%d')
},
"dimensions":
[
{"name": "ga:date"},
{"name": "ga:userType"},
{"name": "ga:sessionDurationBucket"}
],
"metrics":
[
{"expression": "ga:sessions"},
{"expression": "ga:newUsers"},
{"expression": "ga:bounces"}
],
}
Easy to understand pattern here for calling multiple dimensions and metrics. Replace 'ga:' with your choice of Dimensions and Metrics. Exclude date and time if ou want. It will show specific sessions occurring on that dates
Your can use multiples dimencions like this
dimensions: "ga:date,ga:campaign"
Here share an example:
function getData() {
const response = await jwt.authorize();
const result = await google.analytics("v3").data.ga.get({
auth: jwt,
ids: "ga:" + view_id,
"start-date": "2021-05-01",
"end-date": "today",
dimensions: "ga:date,ga:campaign",
metrics: "ga:users",
sort: "ga:campaign,ga:date",
});
console.dir(result);
};
getData();
本文标签: Passing multiple dimensions to google analytics reporting API v4 with javaScriptStack Overflow
版权声明:本文标题:Passing multiple dimensions to google analytics reporting API v4 with javaScript - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745185072a2646644.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论