Google Analytics 4 (GA4) already tracks a bunch of events – scrolls, page views, outbound clicks, and searches. However, I personally need to track specific events like clicks on specific URL patterns, and I need to know on which pages those clicks happened, which URLs were clicked, and how many times they were clicked. To do this, you need to create custom events in GA4 with parameters and configure them in the Google Analytics dashboard. Here’s how to do it step by step using Google Tag Manager.
Step 1: Make Sure You’ve created a GA4 Module in Google Tag Manager
If you’re just getting started with GA4, the first thing to do is to create a new tag in Google Tag Manager called “Google Analytics: GA4 Configuration”. Here’s a screenshot of the configuration screen:
You can find the “Measurement ID” in the Google Analytics admin screen under the “Data Streams” section of your property. Here’s a screenshot:
Enter the measurement ID into the configuration screen, and set the tag to fire on all pageviews. With this basic setup, GA4 will now track events on your site.
Step 2: Create a Trigger Rule when Your New Event Will be Fired
Before you create a new event, you need to create a trigger in Tag Manager that will fire when your conditions are met. For example, I want to track certain URL clicks on my website WP-Tweaks.com, so I create a new trigger with the “Click – Just Links” trigger type and then use a RegEx rule to specify which URLs I want tracked as shown here:
Give your trigger a name and save your changes. So far, we haven’t created a GA4 event yet. Just the trigger for the event. Which leads us to the next step.
Step 3: Define a Custom GA4 Event
To define a custom event, create a new tag in Tag Manager called “Google Analytics: GA4” event. In the configuration screen, select the GA4 tag that you just created in Step 1, give your event a name, and at the bottom section called “Triggering”, select the trigger that you just created in Step 2:
Along with the event, I also want to know the URL that was clicked, and on which page the action happened. So under “Parameter Name”, I create two fields called “URL” and “Label” – both having the variables that define the clicked URL and the Page URL. Google Tag Manager will help you select these values from a list, so you don’t need to enter them manually.
Save your changes, publish your Google Tag Manager modifications, and you’re done!
Step 4: Specifying the Custom Parameters in GA4
Unfortunately, there’s one more step. GA4 doesn’t automatically collect the data for your custom parameters unless you explicitly tell it to. It’s dumb, but we have no choice but to play along. So under the “Configure” menu in GA4, choose “Custom definitions”. Here, click “Create custom definitions”, and create a “Dimension” with a name of your choice, choose “Event’ under the “Scope” dropdown list, and under “Event Parameter”, choose the two parameter names that you created in Google Tag Manager as shown here:
Save your changes, and you’re done!
Remember to Wait – GA4 isn’t Real-Time
The most annoying aspect of GA4 is that it’s not real-time unlike the old Google Analytics (Universal Analytics or UA). Defenders of this like to point out that even UA had no real-time guarantees, but who cares as long as it was showing up in near real-time! In all the years I’ve used UA, my events and pageviews showed up immediately. GA4 metrics have a delay of several hours. It’s absurd, and I hope it changes as it becomes more mainstream.
But for now, know that your data won’t show up immediately!
I’m a NameHero team member, and an expert on WordPress and web hosting. I’ve been in this industry since 2008. I’ve also developed apps on Android and have written extensive tutorials on managing Linux servers. You can contact me on my website WP-Tweaks.com!