-
How to Create a Custom Event Report using Google Analytics 4 Report API?
“Hey, guys. So, I moved from UA analytics to GA4. Been trying to figure out how to fetch values using API report. Previously, I was using this setup for UA and it was smooth sailing:
`
Javascript Event: ga(‘set’, ‘dimension1’, artist);Ruby Report Params:
metric = Metric.new(expression: ‘ga:hits’)
dimension = Dimension.new(name: ‘ga:dimension1’)
…
You get the drift, right?
`
Hopped on to GA4 and set it up like:
`
Javascript Event: gtag(‘event’, ‘artist’, {‘artist’: artist});
`
I can see my data chilling in GA4’s Reports > Engagement > Events. My JSON credentials file is the same as before. But now, I am clueless about how to fetch this data using API report. I tried tinkering with the UA parameters. Nada.
Tried changing up my Ruby code and voila, got this lovely complaint:
Google::Apis::ClientError (badRequest: Invalid value 'eventCount' for metric parameter.)
`
Ruby Code Tweak:
metric = Metric.new(expression: ‘eventCount’)
dimension = Dimension.new(name: ‘customEvent:artist’)
…
Grr!
`
Even GA4’s query explorer didn’t help. Tried this and all I got was
(not set)
forcustomEvent:artist
:`
Metrics: eventCount
Dimensions: customEvent:artist
Order by: eventCount desc
`
Did anyone figure out how to do this yet? I’d love a nudge in the right direction.”
Log in to reply.