How to track GA4 custom events with parameters via Google Tag Manager

photo admin
December 26, 2024
In this article

Overview

The idea for this article came to me when I was struggling to figure out why custom events from my Advanced Woo Search plugin weren't being sent to the GA4 users' dashboard. There were several support requests about this problem.

After further investigation, I discovered that all those users were using the Google Tag Manager tool. I later realized that it is not enough to just send custom events via dataLayer. You also need to properly configure GTM to track those events and their parameters.

In this article, I will explain how to track such custom events with parameters sent to the data layer.

Example

For our example, we will use a WordPress search plugin. We want to track search events and the value of the search query.

Search form

To track those events, we simply execute the following JS after each user search:

dataLayer.push({
  'event': 'aws_search',
  {
    'aws_search_term': {search_val}
  }
})

We send the aws_search event with the aws_search_term parameter that contains the search query value.

Now let's dive into how to track such events inside the GA4 dashboard.

Set Up Events Inside Tag Manager

First of all, we need to track that custom event via Google Tag Manager and send it to the GA4 account.

To do this, please follow these steps:

1. Open your Tag Manager account that is currently active for the required site. Make sure the required tag code is installed.

2. Create a custom variable to track event parameters. Open the Variables tab and click the New button.

Create the following variable:

Title: aws_search_term
Variable Type: Data Layer Variable
Variable Name: eventModel.aws_search_term

New variable: aws_search_term

3. Create an event trigger. Open the Triggers tab and click the New button. Set the following trigger:
Title: aws_search
Trigger Type: Custom Event
Event Name: aws_search

Custom trigger

4. Create a tag that will send the aws_search custom event with variables to your GA4 property.

Open Tag and create the following new tag:

Title: AWS event

Tag Type: Google Analytics: GA4 Event

Measurement ID: {your GA4 Measurement ID} (can be found inside the GA4 dashboard -> Admin -> Data collection and modification -> Data streams -> {your stream})

Event Name: Choose Event variable.

Event Parameters:

Name: aws_search_term
Value: aws_search_term variable from the list

Triggering: Choose aws_search trigger.

Custom tag for aws_search event

5. Finish! Review and publish all changes for the current container.

Conclusion

We set up a custom tag for Google Tag Manager to send out the custom event aws_search with the aws_search_term parameter to our GA4 property. Next, we need to properly configure Google Analytics to catch and display these events. This will be covered in the following chapters.

Set up Events in Google Analytics

In this step, we've already set up event tracking and sent data to the GA4 property via Tag Manager.

Now it's time to configure this event within your Google Analytics account. This ensures it is properly tracked and displayed in all necessary reports.

Steps for Adding Event Tracking in GA4:

1 Open your GA4 property’s admin page, then navigate to the Events page.

Events admin page

2 Click the "Create Event" button. Then create a new event with the following parameters:

event_name -> equals -> aws_search

Make sure the checkbox Copy parameters from the source event is selected.

Create new aws_search event

Once you're done, click the Save button.

3 Now, let's create a custom definition to track the aws_search_term event parameter. First, open the Custom Definitions page.

Custom Definitions admin page

4 On this page, click the Create Custom Dimension button, then create a new dimension.

Name: aws_search_term. Scope: Event. Event parameter: aws_search_term.

Save all changes.

Creating a new custom dimension

5 That's it! Event tracking is enabled, and soon you'll be able to see the aws_search event in the GA4 dashboard. Please allow up to 24 hours for data to accumulate.

Conclusion

We've created a custom event for GA4 and set up a custom dimension for it. Events sent via Tag Manager should now be visible in the GA4 dashboard.

Build GA4 Custom Reports

The next step is to view the aws_search custom events in Google Analytics reports and create a custom report for this event and its aws_search_term parameter.

There are two ways to view this custom event. We’ll cover both.

Option 1: Events Report

Custom event tracking in GA4 can be found under EngagementEvents page.

Open this page and click on the aws_search event name to view data related to this event.

aws_search event in the Events page

On the aws_search event page, you’ll find analytics data for these events over a specified period.

Data such as the total number of events, users associated with the event, user countries, and more can be accessed here.

aws_search event page

At the bottom of the page, data about search terms (aws_search_term dimension) is displayed. This is useful for understanding user search behavior on your site.

aws_search_term dimension

While this report contains useful information, it has its limitations. For more advanced reports, explore the Custom Exploration feature.

Option 2: Custom Events Exploration

Here’s a more advanced way to track search queries by creating a custom GA4 Exploration.

1 Go to the GA4 Explore page and create a new blank report.

2 For the Dimensions field, choose the previously created aws_search_term dimension. For the Metrics field, select Event count. For Segments, create a segment that includes all aws_search events. Then, in the right-hand panel, set Rows to aws_search_term and Values to Event count.

If everything is set up correctly, you’ll see a table displaying data for each search query on your site.

GA4 search terms report