How do I convert my Google Analytics static date ranges to dynamic date ranges?

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

  1. Find ”startDate”: in your Query body.
  2. Delete the date that appears right after it.
  3. Replace it with the following: “{date.last30Days}”
  4. Find “endDate”: and delete the date that follows it.
  5. Replace it with the following: “{date.today}”
  6. Click Get data.
  7. 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:

Have more questions? Submit a request