Home Blog Service Analytics

How to Set up Event Tracking in Google Analytics 4

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

    20 June 2024

    The Importance of Using Analytics in Advertising

    Nowadays, businesses face the challenge of constantly refining their advertising campaigns to optimize performance. Given the complexity of the modern consumer’s journey, with its numerous touchpoints and channels, leveraging analytics in advertising plays a crucial role for businesses in achieving their desired outcomes. In 2022, Gartner reported that 53% of marketing decisions were driven by […]

    Learn more

    13 June 2024

    Prevent Data Loss: Set Up BigQuery Error Notifications

    BigQuery has gained significant popularity and is increasingly utilized in numerous projects. Google’s cloud-based data warehouse solution is known for its scalability, speed, and ability to handle large datasets efficiently. As more organizations integrate BigQuery into their data processing and analytics workflows, robust monitoring and alerting mechanisms are essential. Implementing alerts for jobs that encounter […]

    Learn more

    30 May 2024

    How To Create A Meaningful Ecommerce Analytics Dashboard: A Step-by-step Guide

    Are you drowning in a huge amount of e-commerce data? There’s no other way to escape it if you want your e-commerce store to succeed. However, you can make analyzing your data much more enjoyable and effective. The key is to present e-commerce data analytics visually. Data visualization plays a big role in data-driven decision-making. […]

    Learn more

    28 March 2024

    Navigating the Data Deluge: Prioritizing Key Metrics in the Age of Google Analytics 4

    With the advent of Google Analytics 4 (GA4), the key business challenge becomes not collecting data but discerning what truly matters in the sea of data. 64% of marketing executives believe data-driven marketing is crucial to success in a hyper-competitive global economy. By prioritizing key metrics and avoiding the trap of tracking everything, businesses can […]

    Learn more

    3 January 2024

    How to Create a Viable First-Party Data Strategy in 2024?

    Discover the 9 key steps to build a first-party data strategy that maximizes customer data and enhances your marketing efforts.

    Learn more

    27 December 2023

    How To Create a Seamless Customer Experience to Win More Returning Clients

    Want customers hitting a repeat button? Learn the secrets to building a seamless customer experience that keeps them coming back for more.

    Learn more

    30 November 2023

    Maximize Your Data Retention in Google Analytics 4 (GA4) 

    Learn how to manage data storage and protect privacy with GA4 data retention settings.

    Learn more

    24 November 2023

    How to Read and Interpret Google Analytics 4 Reports to Drive Business Success

    Get to know how to read Google Analytics 4 reports to uncover customer insights, optimize marketing strategies, and drive business growth.

    Learn more