How to Set up Event Tracking in Google Analytics 4

Published: 5 July 2023

How to Set up Event Tracking in Google Analytics 4

Event tracking is a powerful way to measure user behavior on your website or app. By tracking events, you can learn what actions users are taking, how they are interacting with your content, and where they are dropping off. This information can be used to improve your marketing campaigns, website performance, and user experience.

In this article, we will show you how to set up event tracking in Google Analytics 4. We will cover everything from creating events to adding parameters. By the end of this article, you will be able to track user behavior on your website or app and use this data to improve your digital marketing strategy.

Table of Contents:

  1. What are Google Analytics 4 Events?
  2. Types of Events that Google Analytics 4 Automatically Tracks by Default
  3. How Does Google Analytics 4 Event Tracking Work
  4. How to Set up Custom Event Tracking Manually in GA4
  5. How to Set up Custom Event Tracking with Custom Parameters in GA4
  6. How To Implement Custom Event Tracking By Using dataLayer.push() Method
  7. How Do You Know if Google Analytics 4 Event Tracking is Working?
  8. Final Thoughts

What are Google Analytics 4 Events?

If you are unfamiliar with GA4 events, it is basically a way to track user actions on your website. It is like a virtual detective that follows your website visitors around and takes notes on what they do. The beauty of GA4 events is that you can customize them to track the exact actions that matter to you. Whether it is button clicks, video views, or even form submissions, GA4 is the ticket to unlocking the secret to your website’s success.

Types of Events that Google Analytics 4 Automatically Tracks by Default

Google Analytics 4 (GA4) automatically tracks several events by default without any additional configuration. These events include:

  • click
  • file_download
  • form_start
  • form_submit
  • page_view
  • scroll
  • session_start
  • user_engagement
  • video_complete
  • video_progress
  • video_start
  • view_search_results

It also collects the following parameters by default:

  • page_location
  • page_referrer
  • page_title
  • screen_resolution
  • language

However, these default events and parameters may not be enough for comprehensive tracking. This is where custom event tracking comes in.

How Does Google Analytics 4 Event Tracking Work?

Google Analytics 4 event tracking allows you to measure specific interactions or occurrences on your website or app. When a user performs an action, such as clicking a link, submitting a form, or watching a video, GA4 sends a request with detailed information about the event. This information is then processed and aggregated to generate meaningful reports and insights.

There are two types of events in GA4:

  • Automatically collected events are events that GA4 tracks by default; these events include things like page views, session starts, and user engagement
  • Custom events are events that you define; you can use custom events to track any type of interaction that you want to measure

When you track an event in GA4, you provide the following information:

  • Category: This identifies the general type of event, such as “click,” “form submission,” or “video play”
  • Action: This identifies the specific event that occurred, such as “click on the ‘Contact Us’ button,” “submit the ‘Contact Us’ form,” or “watch the ‘About Us’ video”
  • Label: This provides additional information about the event, such as the value of a purchase or the number of seconds a video was watched
  • Parameters: These are optional pieces of information that you can add to an event; parameters can be used to provide more detailed information about an event, such as the user’s location or the device they are using

How to Set up Custom Event Tracking Manually in GA4

One of the most powerful features of Google Analytics 4 (GA4) is the ability to create custom events based on other events that meet certain criteria. This can be done by navigating to the Events page in GA4 and clicking the “Create Event” button in the top right corner.

Create GA4 event

In the popup dialog, you can set the criteria for when your new custom event should fire. For example, you could create a “newsletter_sign_up” event that fires when the page_view event occurs, and the page_location parameter contains “newsletter-confirmation” in the URL. This means that GA4 will track a custom event whenever a user visits a page with “newsletter-confirmation” in the URL, even if they did not actually sign up for the newsletter.

Set up criteria for new GA4 custom event

You can also turn this custom event into a conversion, which means that it will be counted as a conversion in your GA4 reports. This can be helpful for tracking the effectiveness of your marketing campaigns and identifying the pages on your website that are most likely to lead to conversions.

Creating custom events with custom parameters is another advanced technique that can be used to track more granular data in GA4. We will discuss it in detail below.

How to Set up Custom Event Tracking with Custom Parameters in GA4

In GA4, you can define as many event parameters as you want. The big advantage is that you get highly customized event tracking with lots of data. Configuring custom event tracking in Google Analytics 4 (GA4) requires several steps. To track events with custom parameters in GA4, you need to start by adding custom dimensions. And there are two ways to do that:

  • gtag
  • gtag

We will first discuss gtag-based implementation.

  1. Go to Admin > Property > Custom definitions
  2. Create custom dimensions in GA4

  3. Next, click the Create custom dimensions button and enter the dimension name and event parameter
  4. Enter dimension name and event parameter

Let’s assume that you want to track clicks on your main navigation menu. In this case, you can set the Event Category to Menu Clicks, the Event Action to the anchor link, and the Event Label to the anchor text.

An example use case for this setup is to change the anchor text of menu clicks and track which ones attract more clicks. According to GA4 documentation, you should trigger a gtag event when somebody clicks on your menu items. Please, see the example code below.

Example code 1

The “menu_clicks” event name can be anything you want, and it will have three parameters. You can use this approach if you don’t have Google Tag Manager and prefer gtag implementation.

You can use custom parameters to pass additional values to predefined events. For example, sign_up event. The GA’s documentation states that it supports only one parameter called “method”. It can be email, social login, etc.

Example code 2

Now let’s set up the same event tracking using the GTM tag.

How to Set up Event Tracking in Google Tag Manager

You will need to create a new Javascript variable in GTM that returns clicked anchor’s parent tag class name as in GTM there is no built-in way to get parent DOM element attributes.

  1. Go to Variables > User-Defined variables and click the New button; in the popup dialog, choose Custom Javascript
  2. New user-defined variables GA4

  3. Copy and paste this code into it
  4. Example code 3

    This code returns the parent class attribute of a clicked element when there is a parent with class ‘.menu-item’, or it returns an empty value if there is no such parent element.

    You can use this to ensure you only detect clicks on menu item links.

  5. Create a new trigger in GTM that fires on all clicks on elements with a parent li with a class “menu-item”
  6. Navigate to triggers and click the New button in the top right corner
  7. Select Clicks > Just Clicks from the popup dialog
  8. Just clicks GA4

  9. Select Some Link Clicks > Configure it to fire on clicks where the parent element class contains the string “menu-item”
  10. Configure menu clicks

  11. Navigate to Tags and add the GA4 Event tag
  12. Add GA4 event tag

  13. Fill in the event name “main_menu_clicks” and add custom parameters event_category, event_action, and event_label
  14. GA4 menu click

  15. Choose Click Text and Click URL variables for event action and label
  16. Click text and click URL variables

  17. Select the trigger of Menu Clicks you created before, and save the tag
  18. Select menu clicks

  19. Publish changes and debug to ensure when you click on your menu items, the event is triggering with all parameters set correctly
  20. Tag details

How To Implement Custom Event Tracking By Using dataLayer.push() Method

If you prefer custom coding and have GTM, you can use the datalayer.push() method. In this case, use the code below on your website section.

Data Layer Variable GA4

//Click event listener to menu items with the ‘.menu-item’ class
document.addEventListener(‘DOMContentLoaded’, function() {
const menuItems = document.querySelectorAll(‘.menu-item’);
menuItems.forEach(function(menuItem) {
menuItem.addEventListener(‘click’, function(event) {
//Link and anchor text of the clicked link
let link = menuItem.querySelector(‘a’).href;
let anchorText = menuItem.querySelector(‘a’).textContent;
// Trigger the custom event ‘menu_clicks’ using dataLayer.push()
‘event’: ‘menu_clicks’,
‘event_category’: ‘Menu Clicks’,
‘event_action’: link,
‘event_label’: anchorText

How Do You Know if Google Analytics 4 Event Tracking is Working?

It is also important to check if you see an event log with the same parameters in GA4 debug view. It may happen that GTM will fire, but because of misconfiguration, it will not be passed to GA4.

GA4 debug view

If you have gtag implementation, you should enable debug mode. To do that, install the Chrome extension or add one line of code to your GA4 configuration.

gtag(‘config’, ‘G-12345ABCDE’, { ‘debug_mode’:true })

Remember to always debug and make sure that all custom parameters pass as expected.

Final Thoughts

Event tracking in Google Analytics 4 opens up a whole new world of insights for your analytics journey. Of course, GA4 may have a learning curve compared to the trusty old Universal Analytics, but it’s worth the effort!

We understand that event tracking can be a bit complicated at first. That’s where we come in. Our analytics team will guide you through the event tracking adventure in GA4. Whether you need tips, implementation support, or tailored solutions, we will be happy to help you.

Reach out to us today, and let’s rock your data like never before!

Get in touch

Got a question? We'd love to hear from you. Send us a message and we'll respond as soon as possible.

    By clicking submit, you agree to our Privacy Policy

    Latest Insights

    Get the tips from our experts to optimize and scale your campaigns

    1 September 2023

    How Marketing Teams Can Take Advantage of Generative AI

    Generative AI is a game-changer for marketing. Discover how you can use this technology to create more personalized customer experiences and drive more conversions.

    Learn more

    31 July 2023

    10 Tips for Marketing Male Supplements with Social Media

    Discover the best way to promote your male supplement company with our comprehensive guide. Learn how to use social media to promote your products and generate leads.

    Learn more

    20 July 2023

    How Marketers Can Use GA4 to Improve Campaign Performance

    Study our guide to GA4 for marketers and learn how to track your marketing performance, measure your ROI, and make better decisions.

    Learn more

    14 July 2023

    Understanding Data Filters in Google Analytics 4

    Want to get more out of your Google Analytics 4 data? Learn how to use GA4 filters to see the data that matters most to you.

    Learn more

    30 June 2023

    The Ultimate GA4 Handbook: Your Complete Guide to Understanding GA4

    Discover the ultimate guide to Google Analytics 4. Seamlessly transition from Universal Analytics to GA4 and unlock its full potential. Download the free handbook now!

    Learn more

    23 June 2023

    How to Use Google Analytics 4 to Grow Your Small Business

    Want to know how to use Google Analytics 4 to grow your small business? This article will show you how to set up GA4, track your key metrics, and use the data to make informed decisions.

    Learn more

    13 June 2023

    Understanding Enhanced Measurement in GA4

    Learn how to use Enhanced Measurement in Google Analytics 4 to collect more data about your users and improve your marketing and business decisions.

    Learn more

    5 June 2023

    How to Link Google Ads and Google Analytics 4 for Better Marketing Insights

    Learn how to link your Google Ads and Google Analytics 4 accounts to get more insights into your marketing campaigns. Improve your targeting, bidding, and overall performance.

    Learn more