Set up Google Analytics 4 Events

Set up Google Analytics 4 event tracking for recommended events, ecommerce events, SaaS events, and custom events using JavaScript, the dataLayer or the Measurement Protocol.

Please select the event type

Which event do you need help with?

Please indicate the custom event name

Please select the tracking medium

Event Sample Code

How it works

Our tool generates GA4 events dynamically.
You choose what you want to track and the tool will provide you with the equivalent code. You can pick events applicable to all properties, or SaaS events, or E-commerce events, or create your own custom event.
If you're not generating a custom event, choose the event name from the dropdown list, choose the tracking medium and generate the event.
Next, simply copy the generated code and you are done!

A tracking medium is the method used to communicate the event with Google Analytics 4.
The dataLayer is used with Google Tag Manager, gtag.js is used to communicate event to Google Analytics directly, and the Measurement Protocol is used to communicate events server-to-server.
Choose your preferred method of tracking when generating events and the tool will return the equivalent code.

When generating a custom event, start by inputting the event name into the name field.
If no event parameters are needed, feel free to remove the event parameter(s) row(s) and generate the event.
If your event needs event parameter(s), add as many row(s) as needed, enter the event parameters along with their value(s) and generate the event.

Event parameters are additional information we send along with the event to give more information about the event.
For instance, we can send an event parameter with button clicks to help us determine which button was clicked and on which page.
When generating custom events, make sure to add event parameters when applicable to make your events clearer.

If you are working with the dataLayer, then you will have to add the generate inside a function to be called when the user takes the specific action.
Then you will need to create an Google Analytics: GA4 Event tag inside Google Tag Manager which will fire based on a Custom Event trigger where the event name is the same as the generate event name.
If you are working with gtag.js then you will need to insert the code inside a function which will be called when the user takes the specific action you need them to take.
In case you are using the Measurement Protocol, then you will need to send the event using the fetch API which will be used with gtag.js. The event can be sent through and HTTP POST request if you are sending it with any other method.