4

I am using Python API to retrieve information to generate analytics report for an app. We are using the new GA4.

Sending the event parameter : Event Category, Event Action, Event Label and Event Value through the gtag.js while triggering the event.

The parameters are labelled as follows: Category, Action, Label, Value

Now, once the events are triggered, I need to collect all the information about the events from GA4 and make a my own report using Python API calls. I need the information of all the Event Label and Event Value which was passed through gtag.js

I am using:

request = RunReportRequest(
        property=f"properties/{property_id}",
        dimensions=[Dimension(name="eventName")],
        metrics=[Metric(name="eventCount")],
        date_ranges=[DateRange(start_date= sdate, end_date= edate)],
    )
client = BetaAnalyticsDataClient()
response = client.run_report(request)

This will just give the Event Name and the count of the events that occurred. I read that in GA3, eventLabel, eventCategory and eventAction are treated as dimensions and eventValue as a metric. But seems like that's not the case in GA4. I tried eventLabel as the dimension in the dimension field in the request payload. It threw me error saying its not a valid dimension. I tried eventValue in metrics field and that would provide me the summation of all the Event Value for each event.

But I need the individual Values of each Event and also the Label corresponding to it. Is there any way that I can retrieve this information? Am I missing anything? Happy to share more info if required.

Any help is appreciated. Thanks in advance :)

oguz ismail
  • 1
  • 16
  • 47
  • 69

2 Answers2

1

Google Analytics 4 (GA4) has different data model than that of Universal Analytics (UA).

In UA data model is based on hits where event is a type of hit in which you can pass the parameters (Category, Action, Label and Value), which are removed in GA4. GA4 has data model based on events in which event name and custom parameters needs to be passed.

Here are the links on how to send events in GA4 and available columns through API.

dikesh
  • 2,977
  • 2
  • 16
  • 26
  • Thanks for response. But can you please elaborate on how I can retrieve the custom dimension and metric values using python API. Do you have a code snippet that you can share with? Thank again :) – Chandana Srinivasa May 09 '21 at 06:02
  • 1
    @ChandanaSrinivasa . Have the look at the documentations for [custom dimensions](https://developers.google.com/analytics/devguides/reporting/data/v1/api-schema#custom_dimensions) and [custom metrics](https://developers.google.com/analytics/devguides/reporting/data/v1/api-schema#custom_metrics) – dikesh May 11 '21 at 04:52
  • Can we obtain data similar to UA , on an individual level ?https://support.google.com/analytics/thread/108800211/how-do-i-retrieve-the-event-label-and-event-value-parameters-in-ga4-using-python-api-call?hl=en – Sade Aug 10 '23 at 07:12
  • @ChandanaSrinivasa - did you obtain the data on a lower level? Therefore. not aggregated. If so would you be kind enough to share more information/code on it. Im also using python – Sade Aug 10 '23 at 07:14
1

Here you can find how to instrument Universal Analytics events as Google Analytics 4 events: https://developers.google.com/analytics/devguides/collection/ga4/translate-events

GA4 events have no notion of Category, Action, and Label and, unlike in UA properties, GA4 reports do not display Category, Action, and Label. Therefore, it’s better to rethink your data collection in terms of the GA4 model rather than port your existing event structure to GA4.

Michele Pisani
  • 13,567
  • 3
  • 25
  • 42
  • Hello Michele Pisani, Thanks for your response. I tried sending events as mentioned in the link. It appears in the GA4 last 30 min report. However, I need to collect these events and its parameter values using python and generate my own reports. I tried customEvent:parameter and value. It does seem to show the dimensions but not the actual value. Is there a way to retrieve the value I sent using gtag.js. Eg: `gtag('event','eventname',{ event_category: 'categoryname', event_label: 'custom_dim', value: 12 }` How do I collect the value 12? – Chandana Srinivasa May 09 '21 at 06:10