Search
Close this search box.

How to Set up GA4 Custom Events Using Google Tag Manager

Last Modified on December 22, 2023

What are custom events in Google Analytics 4?

GA4 Custom events are personalized events with unique names and parameters.

GA4 For Beginners

Master the basics with our FREE GA4 Course for Beginners

They allow tracking user actions that are not automatically collected by Analytics and don’t belong to recommended events.

Google Analytics 4 provides four categories of events that can be tracked: 

  1. Automatically collected events
  2. Enhanced statistics
  3. Recommended events
  4. Custom events

Tracking custom events in Google Analytics 4 (GA4) is increasingly important for businesses, to deeper understand their audience’s behavior on their website or app.

The lack of visibility into specific users’ actions makes optimizing marketing strategies difficult. 

Custom events allow businesses to track user interactions unique to their business, such as button clicks, form submissions, popups, or registrations.

In this article, we will explore GA4 custom events in detail and describe how to configure them:

How To Set Up GA4 Custom Events With Google Tag Manager

First, we have to ensure that we need to install custom events and that there are no events collected by default.

We will take as an example clicking on the buttons on the landing page that opens a popup for login or sign-in.

We will also add a custom button name parameter to understand which button on the page has the most efficiency.

Step 1: Create a Tag

1. Go to your Google Tag Manager account. Click on the Create New Tag button:

Creating a new tag within Google Tag Manager

2. On the pop-up window, in the list of tag templates, select GA4 event:

Choosing GA4 Event tag type in Google Tag Manager

3. Add the name of your event

Adding a tag name of the custom event in Google Tag Manager

4. In the settings drop-down menu, select your GA4. 

If you didn’t create it earlier, select manually set ID.

You can find this ID in the Admin section of the Data Streams tab in your GA4 view.

GA4 Tracking ID

We recommend using variables, as they allow for quick account-wide changes.

5. Add a title for our events.

For example, “btn_click”. Avoid the default and automatically collected event names

Choosing the unique event name in tag configuration

6. If we need to add some custom parameters like button click texts, use the parameter row and add a value.

Adding custom parameter of the event

If you don’t see the necessary variable, click on Built-ins.

Choosing a variable among built-ins

7. Enable the Click Text variable.

Enable a variable among built-ins
Adding a custom parameter of button names and click text

Step 2: Create a Trigger

Setting up a trigger is no different from setting it up in Universal Analytics. 

In our case, clicking on the specified “buttons” is triggered by clicking on some site click elements.

Configuring triggering of the custom event tag

1. Choose the trigger type All Elements.

Choosing All Elements trigger type

2. Let’s name our trigger, and choose when the trigger should fire, under Some clicks.

3. Choose from the drop-down menu Click Element matches CSS selector.

Trigger Configuration based on Click Element

To find the CSS selector of the element on the page,

4. Go to your site and open the dev console by clicking on the right button.

5. Choose View code, click on the button, find Copy selector and put this code in our trigger.

Copying CSS selector on the landing page

6. Click Save tag.

Step 3: Debug and Publish Container

Let’s debug our tag and ensure that it is displayed correctly. We can do debugging in 3 ways:

  1. Real-time reports
  2. Debug View
  3. Google Chrome extensions like Google Analytics Debugger or any analog.

We chose the 2nd option. 

1. Click Preview on the Workspace in Google Tag Manager.

Preview mode turning on for debugging via Google Tag Manager

2. Enter your website link or the landing page where your element is located.

Entering URL of the Website for debugging via Google Tag Manager

3. Then, you’ll see your site with a tag assistant notification in the opened new window.

tag assistant connected notification

4. After clicking on your button back to the Google Tag Manager debug view, you should see your tag fired. 

Debug View of Google Tag Manager where tags are fired

5. You can also click on the fired tag, and check whether your custom parameter is displayed.

displayed custom parameter

6. Then, go to GA4 and check if it displays there. Go to Admin, then Debug View.

Debug View mode of GA4
Fired custom event of button clicks in Debug View of GA4

7. Let’s click on the event and see how our parameters are displayed.

Displaying of custom button names parameters within Debug View of GA4

8. Going back to our Google Tag Manager, click Publish container.

Publishing Google Tag Manager container

How to Set Up GA4 Custom Events Directly to the Code

From a web analytics point of view, a button click is an event.

Unlike goals that are set directly in the Google Analytics interface, events are configured both in the interface and using a special construct that must be added to the code of your site. 

This is not an easy process since it requires you to know programming and understand the principles of building such construction for events in Universal Analytics or for the Global Site Tag counter.

When can it be reasonable to track custom GA4 events directly through code without GTM?

We prefer using on-page tracking when we want to ensure the highest level of accuracy and reliability in our tracking data, or when we need to track events that are not easily captured through GTM, such as events that occur before the GTM container loads.

Additionally, tracking events directly through code can be beneficial if you want to minimize the number of third-party tools and scripts on your site for performance or security reasons.

To track the transmission of event data, we need to:

  1. Find the desired button on the page
  2. Manually add an additional event code to it

Use the event command and the following constructs based on the library you use:

For the analytics.js library, use below code template for tracking a button click custom event.

onclick="ga('send', 'event', 'button', 'click');"

For gtag.js the following template:

onclick="gtag('event', 'click', {'event_category': 'button'});"

In GA4, there are no such components as in Universal Analytics (Category, Action, Label, Value). So, for all the same buttons, it can be reduced like this:

onclick="gtag('event', 'buttonClick');"

Tracking custom GA4 events directly through code changes can provide more accurate and reliable data than using GTM, as it ensures that no events are missed due to latency or other tracking issues. 

This can help you gain a more complete understanding of your users’ behavior and make more informed decisions to improve your website’s performance.

However, configuring custom GA4 events directly through code can be challenging for those who are not familiar with programming, as it requires a good understanding of JavaScript and the GA4 measurement protocol. 

Coding errors, missing or incorrect parameters, and compatibility issues with other scripts or plugins on the site are common issues that can occur with this method. 

Additionally, it can be time-consuming to update the code manually each time you want to track a new event or change an existing one.

How To View Custom Events In GA4

Compared to Universal Analytics, GA4 is a relatively new version of analytics, which means that not everyone is yet accustomed to the system settings and interface.

Let’s find out where we can configure custom events within GA4 in order to display them.

In order to see the custom parameter of button_names, we need to add it as custom definition here.

Adding Custom Definitions to GA4
Adding event parameter name to GA4

The parameter name here should be equal to those we put into the Google Tag Manager parameter name.

Event parameter name within Google Tag Manager

Here you can read more regarding how to set up custom dimensions in detail.

So, let’s build our report.

Go to the Explore section within your GA4. Create a new exploration.

Exploration section in GA4

Select the following Dimensions and Metrics:

  • Event Name
  • Event Count
  • Button Name
Choosing the list of dimensions within the exploration section (GA4) to build the custom events report

Choosing the list of dimensions within the exploration section (GA4) to build the custom events report

Selecting dimensions within exploration reports

Add filter by the event name and wait until the data is displayed.

Building reports of buttons’ clicks by using the event name filter (GA4)

FAQ

How can I set up GA4 custom events using Google Tag Manager?

Here are the steps to set up GA4 custom events using Google Tag Manager:

1. Create a Tag: In Google Tag Manager, create a new tag and select the GA4 event tag template. Add the name of your event, select your GA4 configuration, and add a title for your event. You can also add custom parameters if needed.
2. Create a Trigger: Configure a trigger for the custom event tag. Choose the trigger type (e.g., All Elements), name the trigger, and specify when the trigger should fire. Use the Click Element matches CSS selector option to define the element on the page that triggers the event.
3. Debug and Publish Container: Use the debugging options in Google Tag Manager to ensure that the tag is firing correctly. Preview the tag, enter your website link, and verify if the tag fires and the custom parameters are displayed correctly. Finally, publish the container.

How can I view custom events in GA4?

To view custom events in GA4, you need to configure custom definitions in the GA4 interface. Add the custom parameter names as custom definitions in GA4, matching the names used in Google Tag Manager. Once the custom definitions are set, you can create a new exploration in the Explore section of GA4. Select the relevant dimensions (e.g., Event Name, Event Count, Button Name) and apply filters to build custom events reports.

Can I set up GA4 custom events directly in the code?

Yes, it is possible to set up GA4 custom events directly in the code. However, this method requires knowledge of programming and understanding of event tracking principles. It involves manually adding event code to the desired button on the page using constructs specific to the library you are using (e.g., analytics.js or gtag.js). Directly tracking events through code can provide more accurate and reliable data but can be challenging for non-programmers.

Summary

Let’s summarize. A custom event in Google Analytics 4 is an event that is neither among the automatic nor among the recommended events. You create it yourself for your tasks, come up with an arbitrary name for it and, if necessary, set a set of additional parameters.

In this post, we reviewed how to configure custom events via Google Tag Manager or directly with the help of code changes. 

We also described how to build the reports with custom events in the Exploration section in GA4. Here you also can read more about building custom exploration reports to get more marketing insights.

By tracking custom events within GA4, businesses can gain valuable insights into how users engage with their website or app and identify areas for improvement. 

This can ultimately lead to better user experiences, increased engagement, and improved conversion rates. 

Share in comments what specific user actions have you found most valuable to track with custom events in GA4, and how have they impacted your business decisions?