Learn business growth with Google Analytics 4 Forums Google Analytics 4 How to Create a Custom Event Report using Google Analytics 4 Report API?

  • How to Create a Custom Event Report using Google Analytics 4 Report API?

    Posted by Aiden on 19 December 2022 at 8:10 am

    “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) for customEvent: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.”

    Jose replied 11 months, 2 weeks ago 3 Members · 2 Replies
  • 2 Replies
  • Lucas

    Member
    17 June 2023 at 9:07 pm

    It appears that you’re having a hard time transitioning from Universal Analytics (UA) to Google Analytics 4 (GA4) in terms of setting up API reports to fetch data. In particular, you’re having trouble figuring out how to fetch data after setting up events in GA4, with the API report not recognizing the new parameters you’ve tried using in your Ruby code. It looks like the dimensions and metrics used in UA are not recognized by GA4, which causes a badRequest error. The GA4 query explorer didn’t offer much help either, as it didn’t recognize the custom events you set up. Unfortunately, as GA4 is quite new, many users are still figuring out its functionalities.

  • Jose

    Member
    4 July 2023 at 2:10 am

    This can be quite challenging because GA4 has changed quite a lot from UA, including how the data is structured and reported. For GA4, there is currently no public reporting API like there was for UA. As of now, GA4 only has the Data API which is in alpha phase and does not provide the complete functionality of the previous version. This might be the reason why your events and parameters are not returning the expected data. Also, custom dimensions and metrics are treated as event parameters in GA4, so there may be changes in how they are queried. For accurate implementation, it would be best to check Google’s up-to-date documentation or reach out to Google’s support network for guidance.

Log in to reply.