google-analyticsuniversal-analyticsgoogle-analytics-4

How do I migrate universal analytic events to google analytics 4?


I have a universal analytics script in my <head/, and then throughout the program I have analytics.js events like:

onclick="ga('send', 'event', {eventCategory: 'someCategory', eventAction: 'create', eventLabel: 'big-btn'})

I am now trying to re-create these events in google analytics 4 without using the "Collect Universal Analytics events" toggle.

How would I create the events to fire in googleAnalytics4 and how would I be able to have them show up in the reports?

Thank you


Solution

  • GA4 is implemented using gtag, which you use to send events. e.g.

    gtag('event','create_click',{type:'someCategory', button: 'big-btn'});
    

    The event's name is the second parameter, and the definitions are in the object for the third parameter.

    Definitions can have any name you want (with some restrictions). To access them in reports, they need to be a built-in definition, or you can add them as custom definitions in the configuration section. This means you can use names that are more appropriate to your event.