Many Klips that use Google Analytics 4 data need a rolling date range that is dynamic (for example, past 30 days). In this section we're going to change a static query from a fixed date range to a dynamic one.
This example uses a Google Analytics 4 query with a URL of Query URL:
https://analyticsdata.googleapis.com/v1beta/properties/{propertyID}:runReport
- Find
”startDate”:
in your Query body. - Delete the date that appears right after it.
- Replace it with the following:
“{date.last30Days}”
- Find
“endDate”:
and delete the date that follows it. - Replace it with the following:
“{date.today}”
- Click Get data.
- Save and name your data source.
If your query returned an error, make sure it looks like this:
{
"dimensions": [
{
"name": "date"
},
{
"name": "defaultChannelGroup"
},
],
"Metrics": [
{
"name": "sessions"
},
{
"name": "totalUsers"
},
],
"dateRanges": [
{
"startDate": "{date.last30days}",
"endDate": "{date.today}"
}
]
}
Note that all dynamic references should be placed on their own line in your query body to prevent parsing errors.
Common date range expressions:
{date.today}
{date.last30Days}
{date.startOfQuarter}
- And many more...