0

GA4 Query Examples!

Hi! 

Most of the queries which bring in report data in the GA4 can be retrieved using the same query URL. GA4 uses the POST body to determine which data to return instead of the query URL. I am penning down some examples with different scenarios. 

It is always best to create the query on GA4 query explorer and paste the POST body in the Klipfolio datasource. 

Not all the dimensions are not compatible with all the metrics. You can check them here - https://ga-dev-tools.google/ga4/dimensions-metrics-explorer/

1. Example to bring in Sessions, Uses and page views from start of the month till yesterday. 

{
"metrics": [
{
"name":"totalUsers"
},
{
"name":"Sessions"
},
{
"name":"ScreenPageViews"
}
],
"dateRanges": [
{
"startDate":'{date.startOfMonth}',
"endDate":'{date.yesterday}'
}]
}

 

Example 2 - Sessions by countries and device categories over the last full 3 months. Since there is no date dimension added here the data is consolidated as one value for the given period. 

{
"dimensions":[
{
"name":"country"
},
{
"name":"countryId"
},
{
"name":"deviceCategory"
}
],
"metrics":[
{
"name":"sessions"
}
],
"dateRanges":[
{
"startDate":"{date.addMonths(-3).startOfMonth.format()}",
"endDate":"{date.addMonths(-1).endOfMonth.format()}"
}
]
}

0 comments

Please sign in to leave a comment.