Search code examples
google-analyticsgoogle-analytics-apigoogle-analytics-4

Get specific event count, Google Analytics 4 in Google Analytics Data API (GA4)


How can I get a specific event count ex. eventName "video_start" and "Form"

I get total event count with "metrics":[{"name":"eventCount"}], but want only two events

POST https://analyticsdata.googleapis.com/v1alpha:runReport BODY JSON:

{
"entity":{"propertyId":"IDIDID"},
"metrics":[{"name":"sessions"}],
"metrics":[{"name":"conversions"}],
"metrics":[{"name":"eventCount"}],
"dimensions":[{"name":"sessionDefaultChannelGrouping"}],
"dateRanges":[{"startDate":"2021-01-01","endDate":"today"}]
}

DOC: https://developers.google.com/analytics/devguides/reporting/data/v1/api-schema


Solution

  • To only get a report on two events, you'll need to add a dimension filter for the specific events reference.

      "dimensionFilter": {
        "filter": {
          "fieldName": "eventName",
          "inListFilter": {
            "values": [
              "video_start",
              "Form"
            ]
          }
        }
      },