Thursday, March 28, 2024
No menu items!
HomeData Analytics and VisualizationHow to Track Custom Events with Google Analytics 4

How to Track Custom Events with Google Analytics 4

Updated: August 6th, 2021. Google Analytics 4 definitely has a steep learning curve. If you compare it to Universal Analytics, there are many differences and event tracking is one of them. In one of my previous blog posts, I explained how GA4 event tracking works in general. But if you are interested in learning just how to track custom events with Google Analytics 4, you have come to the right place.

In this blog post, I’ll explain how to do that with Google Tag Manager.

 

Table of Contents

+ Hide table of contents +

An in-depth guide about event tracking in GA4
Video tutorial
GA4 Event tracking in a nutshell
Example: Menu Link Click
IMPORTANT: Register custom definitions
Test your custom events
Where can I find custom events in GA4 reports?
“Reports → Engagement → Events” report
Exploration reports

Turning Google Analytics 4 Custom Events into Conversions
Want to learn more about event tracking in GA4?
Final Words

 

An in-depth guide about event tracking in GA4

Custom events are just a part of all possible events that you can track with Google Analytics 4. If you want to learn the full story, go to this blog post with an in-depth video.

 

Video tutorial on how to track custom events with Google Analytics 4

If you prefer video content, here’s a tutorial on my Youtube channel.

 

GA4 Event tracking in a nutshell

If you want to learn the full context of event tracking in Google Analytics 4, read this tutorial. It also includes a detailed video tutorial.

Things like event categoryactionlabel are no longer available in Google Analytics 4. Instead, GA4 introduced a very flexible data model that allows you to structure your events in any way you want.

There are 4 event types in Google Analytics 4:

Automatically collected events
Enhanced Measurement events
Recommended events
Custom events

The process of how you should plan the structure of your events (names and parameters) is by doing the following:

Check if the event that you want to track is among the automatically collected events
If not, then check if your event is mentioned among the Enhanced Measurement events (e.g. scroll or file_download)
If not, then check the recommended events and their naming convention
If none of the above categories apply to your events, create a custom event with an event that you want

In this blog post, we will focus on the 4th type, custom events.

The configuration of Custom events is pretty much identical to recommended events. The only difference is that you will need to come up with your own event names.

For example, if you want to track form submissions of a contact form, the name of the event can be any of these:

form_submission
contact_form
contact_form_submission

Or anything else.

GA4 is completely flexible here. However, there are some limitations when it comes to the maximum length of an event name.  Also, there is a limit of 500 unique event names per GA4 property. If you reach it, Google says that you won’t be able to track any other new events. And at the moment, you cannot delete unused events (which is unfortunate). Therefore, be careful about creating too many unique event names.

Maybe in the future, this situation/limitation will change. Who knows.

So, speaking of the custom event tracking, let’s look at the example where we want to measure clicks on menu links on a website.

 

Example of a Custom Event in GA4: Menu Link Click

Note: menu link click tracking trigger conditions differ on most websites (because of different click classes, IDs, etc.). Try to do your best to apply this example.

On a demo website, I have several menu links that I want to track.

First, I need to create a trigger with correct conditions that distinguish any click from a menu link click. Enable Google Tag Manager’s Preview mode and try clicking any of the menu links on a website. Once you do the first link click, you should see the Link Click event in the Preview mode’s left sidebar.

If you don’t see it, you should:

have at least one Just Links GTM trigger activated on a page
or have “File download” or “Outbound links” tracking enabled in your Enhanced Measurement Settings

Let’s say, that you don’t use Enhanced Measurement in GA4. Go to Google Tag Manager > Triggers > New > Just Links. Keep the trigger set on “All link clicks” and save the trigger.

By creating this trigger, we will enable the link-tracking functionality in Google Tag Manager.

Then go to Variables > Configure (in the “Built-in Variables” section) and enable all Click-related variables.

Refresh the preview mode (by clicking the Preview button once again).

Then go to your website and click any of the menu links. Actually, click at least two of them. Return to the preview mode and you should start seeing Link Click events in the preview mode. Click the first Link Click event and go to the Variables tab of the preview mode.

Then click on the second Link Click event. I am currently looking for some variable that I could use to distinguish a menu link click. I don’t want to fire my GA4 event tag on any link click. I want to fire it precisely on a menu link click.

After taking a closer look, I see that both links contain the same Click Classes value, site-nav__link site-nav__link–main. By the way, nav means “navigation” in this context. Great! I will use this in my Just Links trigger.

Go back to the list of triggers in your GTM container and click the previously created trigger for All Link Clicks. We’ll edit it and add a condition: Click Classes contains site-nav__link–main

Save the trigger. Now, it’s time to create a Google Analytics 4 event tag. Go to Tags > New > Google Analytics: GA4 Event. Select your existing GA 4 Configuration tag and then enter the event name. Its value is up to you. Any of the following options are perfectly fine:

menu_click
menu
menu_item_click
menu click
etc.

These are just some of the examples. Since we are working with a custom event, we can name it whatever we want (as long as we follow the limitations of name length, for example).

In my case, I used menu_click event name. But this time, sending just the event name is not very useful. You’d probably want to know which exact menu items are clicked more often. How about we also send the name of the menu item and the URL?

We could do that by sending additional event parameters. Even though you could use parameters that are already mentioned in the documentation of the Enhanced Measurement (like link_url and link_text), let’s create two custom parameters (because I just want to show you how to configure them).

I am going to pass two parameters, menu_item_url and menu_item_name. I made these parameter names up and you can do it too. That’s what the flexibility of the data model offers.

To send custom parameters, you must expand the Event Parameters section in the Google Analytics 4 event tag and then click Add Row.

Enter the name of the first parameter. In my case, that is menu_item_url. In the Value field, I will insert a variable that returns a clicked URL. Luckily, GTM already offers such a variable, it’s called Click URL. Click the Insert Variable button and then select the {{Click URL}} variable.

Let’s add another parameter, menu_item_name. For that purpose, GTM offers another built-in variable, {{Click Text}}. Insert it as well. Since visitors of your website can translate your page, {{Click Text}} value will also change, hence you will see a more diverse list of collected values in your GA4 reports.

If you want to send more parameters, you are free to do that. You can send up to 25 custom parameters with a single event.

Assign the previously created Just Links trigger to this tag. Save the tag. Refresh the GTM Preview mode and click a couple of your menu items. Go back to the Preview mode and click those Link Click events. Check if the GA4 event tags for Menu Link Clicks have fired.

Now, you will need to go to Google Analytics 4 and check the DebugView. You will learn more about that in this chapter of the blog post.

IMPORTANT: even though you will see your custom parameters in Real-time reports and DebugView in GA4, you will not be able to see them in other GA4reports. Unless you register those parameters as custom dimensions in Google Analytics. Read the next chapter of this blog post.

 

 

IMPORTANT: Register custom definitions

This applies to any custom parameter that you send to Google Analytics 4. If you want to see/use them in things like Funnel reports, Exploration, see their reporting cards in standard reports, etc., you must register custom parameters in the GA interface.

In Google Analytics 4, go to Configure > Custom Definitions. Since we sent 2 custom parameters with the menu link click, we must register them both here.

Click the Create Custom Dimensions button and then enter:

The name of the parameter. You can enter whatever you want. This is just how the dimension will be displayed in your reports. You can name it “menu_item_url”, “Menu item URL”, or anything else.
Scope. Since we want to apply this parameter only to one event (and not to all events of the same user), we need to select Event
Event parameter. This is where you have to enter its name precisely as you entered it in the GTM tag. If your parameter name is menu_item_url, you must enter it here exactly like that. Don’t worry if the autocomplete feature of that field does not show your parameter yet. Just enter it and save the dimension

Then register a second parameter (in my case, that was menu_item_name) and save it. By the way, I sometimes use the words “custom parameter” and “custom dimension” interchangeably. In general, custom metrics and custom dimensions are both grouped as custom parameters.

And now we wait. Within the next 24 hours, the custom parameters will start appearing in your Google Analytics 4 reports.

 

Test your custom events in Google Analytics 4

Once you configure your custom events, it’s time to test them. The primary feature built for debugging GA 4 data is the DebugView section. You can find it by going to Configure > DebugView.

That’s the place where your debugging should take the place. Do not mix this with the GTM Preview and Debug mode. They are two different beasts.

To enable the debug mode in GA4, you have several options (any of them will work):

Enable the GA debugger Chrome extension
Send a debug_mode parameter together with an event
Have enabled Google Tag Manager’s Preview mode on a page that you’re debugging

In the case of the first option, install the extension here, and then click its icon (so that you can see the ON ribbon). From this moment, you will start seeing your events coming into the DebugView.

The other option is to send a debug_mode parameter with every event that you wish to see in the DebugView.

In Google Tag Manager, you can do that by opening the GA4 Configuration tag and adding the following parameter:

If the debug_mode parameter is set to true, the event will be seen in DebugView. If you are using a hardcoded gtag.js, here are the instructions on how to include the debug_mode parameter.

But since we are working with Google Tag Manager, having the GTM Preview mode enabled automatically sets the debug_mode to true, thus the data will start appearing in the GA4 DebugView.

When you start seeing data in the DebugView, you can click on every individual event and then a list of parameters will be displayed.

Click on that parameter to see the value that was received by GA4. Now that is some granular debugging!

However, I have noticed some delays between the event actually happening on a website and then appearing in DebugView. Sometimes, I have to wait for several minutes until the events come in. That’s a bit unfortunate and hopefully, the team behind Google Analytics 4 will improve this in the future.

Also, make sure that you have selected the correct Debug device in the top left corner.

If multiple visitors have enabled the debug view (e.g. they all have enabled the Chrome extension), you will see multiple devices there and it might require some time to find yourself. This especially applies to my blog, when many of my readers have enabled the GA Debugger Extension and I have to guess which device (out of the other 15) is mine

Anyway, once you start seeing data in DebugView, things will look like this.

Events are marked with blue icons, conversions with green. Please ignore the fact that I treat menu_click events as conversions. This is just for demonstration purposes

If you click the event, you will see the parameters that were sent together with an event. Click on the parameter to see its value.

Once you made sure that the data is coming in and it is displayed properly, you should submit your GA4 changes in the GTM container and publish it.

You can do that by clicking the SUBMIT button in the top right corner and then complete all the other steps that the user interface asks you to do.

After that, you should soon start seeing the new data coming in your real-time reports as well.

On the left sidebar of the Google Analytics 4 interface, go to Realtime. This is where you will see the data coming into your reports. Unlike in the previous version (Universal Analytics), the new report offers you the capabilities to see the data on a much more granular level.

First, you will see a map and a bunch of cards with traffic sources, most popular events, the number of users in the last 30 minutes (by the way, Universal Analytics real-time report shows the number of users in the last 5 minutes).

You can also take a look at the snapshot of an individual user. You can do that by clicking the View user snapshot button in the top right corner.

Then, you will see a stream of all events of that particular user, you can click on them (just like in the DebugView) to see things on a more granular level. If you wish to look at another user/visitor, you can click the button here:

To exit the snapshot, simply press the Exit snapshot button in the top right corner.

 

Where can I find custom events in Google Analytics 4 reports?

This blog post focuses mainly on the tracking of custom events with Google Analytics 4. I will not dive deep into how to find insights, raise questions, answer questions, etc. However, I can show you several places where you can find the event data that you have just sent to Google Analytics 4.

Keep in mind that at the moment of writing this blog post (late 2020), the built-in reporting capabilities of Google Analytics 4 are still quite limited. Hopefully, that will change soon. Let’s take a look at what we have now. Here are some of the reports:

Configure > Events (this will show just the list of events with counts. Nothing fancy.
Reports > Engagement > Events
Explore (a.k.a. Exploration reports)

But that is not all. Since GA4 is an event-based analytics platform, every report is affected by events that you send (in one way or another). The aforementioned reports are just the most notable examples.

 

“Reports → Engagement → Events” report

This is an overview of all events that were sent to your property + a couple of charts. Below them, you will see a list of events and if you click on any of them, you will take a closer look at that event’s data.

 

Explore (a.k.a. Exploration reports, ex Analysis Hub)

This is the place where you will be able to drill-down into your data. In the Exploration, you will be able to use reports such as Free Form, Funnel Exploration, Path Exploration, etc.

Here is an example of a Free Form report. Keep in mind that you will need to wait for up to 24 hours for the data to come into your reports. So if you don’t see the data now, be patient.

Let’s say that I want to see how different device categories are interacting with the menu bar of my site. Remember, I set up the menu_click event?

So, let’s go to Explore and click on the Free Form block.

Then in the Variables column, I need to include the menu_item_url custom dimension because I want to see how many clicks did get each menu URL. Click the Plus icon and then find the menu_item_url dimension. Select it and it will be included in the list of possible dimensions in the report.

If you CANNOT see the menu_item_url (or whatever custom parameter are you looking for), you must register that custom parameter in All Events > Manage Custom Definitions. And then wait for 24 hours until the data appears in the reports. If the reports don’t work properly, wait for even longer.

Then let’s edit the Tab settings. Remove the existing dimensions in the ROWS and include the custom definition that you want to include. In my case, that’s menu_item_url.

In the COLUMNS section, I used the Device category dimension. In the VALUES section, select the metric that you wish to see. I used the Event Count.

Then you will need to filter only to those events that actually contained the menu_item_url dimension. In my case, that is just a menu_click event. That’s why at the bottom of the Tab Settings section, you should enter a filter: Event name exactly matches  menu_click.

That’s it, your report will now display how different device categories are clicking menu items; which ones are the most popular and how many times were they clicked.

Also, don’t forget to change the date range if you need it. You can do that in the top-left corner of the Exploration interface.

You can also use event data in things like funnel reports, but let’s keep it for another tutorial (hopefully) in the future.

 

Turning Google Analytics 4 Custom Events into Conversions

Not all events are equal. Some are more important for businesses. In the previous GA version, the most important interactions were called goals. Now, they are called conversions (which is a widely-known term if you have ever worked with other marketing/analytics tools).

If you want to learn how to configure conversions in Google Analytics 4 (because the process is very different compared to Universal Analytics), watch the video tutorial below or read this in-depth blog post:

 

Want to learn more about event tracking in Google Analytics 4?

Honestly, in this video, I was just scratching the surface of what you should know about event tracking. If you want to learn more, head over to this blog post. In it, you will find topics like:

How to plan your event structure
Automatic event tracking
Recommended events in Google Analytics 4
How to create custom events directly in Google Analytics 4 interface
How to modify events directly in Google Analytics 4 interface
and more!

 

Tracking Custom events with Google Analytics 4: Final Words

To sum up, here’s is the recommended process of how you should track events with Google Analytics 4 (and you can learn more about it here):

Check the automatically tracked events and what Enhanced Measurement has to offer.
If an event (that you wish to track) is not listed there, check the recommended events and try to use their naming recommend names and parameters.
If none of the recommended events match your need, then create a custom event in Google Analytics 4 (and the entire blog post was just about this part)

Here are some of the key takeaways:

No more Event Category, Event Action, Event Label fields. If you want, you can create them manually as custom parameters but that does not make sense.
You can send custom parameters (dimensions and metrics) with events (both recommend and custom).
You can send up to 25 parameters with a single event.
If you want to see a parameter in the GA4 report, you must register it as a custom definition. There is a limit of 50-registered custom dimensions and 50 registered custom metrics per property.
Use Google Analytics 4 DebugView to test the incoming events on a granular level.

Got more questions about tracking custom events with Google Analytics 4? The comments section is at your service

 

The post How to Track Custom Events with Google Analytics 4 appeared first on Analytics Mania.

Read MoreAnalytics Mania

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments