'GA4 (Google Analytics) sessions based on UTM params

I am trying to fetch sessions from GA4 which are relevant to specific UTM params.

In GA3 we were able to use segments (sessions::condition::ga:source==X;ga:medium==Y) but I can not find a way to do this on GA4.

POST https://analyticsdata.googleapis.com/v1beta/#{property}:runReport`

Payload like this:

body = {
  "metrics": [
    {
      "name": "sessions::condition::ga:source==X;ga:medium==Y"
    }
  ], 
  "dimensions": [
    {
      "name": "date" 
    }
  ],
  "dateRanges": [
    {
      "startDate": '2022-01-01',
      "endDate": '2022-01-30',
      "name": "current_year"
    }
  ]
}

Returns: Field sessions::condition::ga:source==X;ga:medium==Y is not a valid metric.. Is there a way to do this via new API?

Should I use dimension filter to achieve that? I need to query on both source&medium but it is not clear how do I do this?

  "dimensionFilter": {
      "filter": {
        "fieldName": "firstUserMedium",
        "stringFilter": {
          "value": "Y"
        }
      }
    }


Solution 1:[1]

I think you should check the dimensions and metrcis list for GA4 they dont start with ga

POST https://analyticsdata.googleapis.com/v1beta/properties/GA4_PROPERTY_ID:runReport
  {
    "dateRanges": [{ "startDate": "2020-09-01", "endDate": "2020-09-15" }],
    "dimensions": [{ "name": "country" }],
    "metrics": [{ "name": "activeUsers" }]
  }

Also at this time i don't think it supports segments.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 DaImTo