{"id":17779,"date":"2023-05-09T02:47:11","date_gmt":"2023-05-09T02:47:11","guid":{"rendered":"https:\/\/www.searchenginejournal.com\/google-analytics-event-tracking\/484607\/"},"modified":"2023-05-09T02:47:11","modified_gmt":"2023-05-09T02:47:11","slug":"google-analytics-event-tracking-how-to-get-set-up-via-sejournal-vahandev","status":"publish","type":"post","link":"https:\/\/marketingnewsbox.com\/?p=17779","title":{"rendered":"Google Analytics Event Tracking: How To Get Set Up via @sejournal, @vahandev"},"content":{"rendered":"<p>Universal Analytics is being sunset, and everyone is rushing to migrate from UA to <a href=\"https:\/\/www.searchenginejournal.com\/google-analytics-4-guide\/407452\/\">Google Analytics 4<\/a> (GA4).<\/p>\n<p>In this guide, we\u2019ll help you migrate your custom events and walk you through how to set up GA4 custom events.<\/p>\n<h2>Types Of Events That GA4 Automatically Tracks By Default<\/h2>\n<p>Google Analytics 4 <a href=\"https:\/\/support.google.com\/analytics\/answer\/9234069?hl=en\" target=\"_blank\" rel=\"noopener noreferrer\">automatically tracks<\/a> several events by default, without any additional configuration. Some of these events relevant to web property tracking include:<\/p>\n<ul>\n<li>click.<\/li>\n<li>file_download.<\/li>\n<li>form_start.<\/li>\n<li>form_submit.<\/li>\n<li>page_view.<\/li>\n<li>scroll.<\/li>\n<li>session_start.<\/li>\n<li>user_engagement.<\/li>\n<li>video_complete.<\/li>\n<li>video_progress.<\/li>\n<li>video_start.<\/li>\n<li>view_search_results.<\/li>\n<\/ul>\n<p>It also collects the following parameters by default:<\/p>\n<ul>\n<li>page_location.<\/li>\n<li>page_referrer.<\/li>\n<li>page_title.<\/li>\n<li>screen_resolution.<\/li>\n<li>language.<\/li>\n<\/ul>\n<p>But in most cases, it is not enough for comprehensive tracking, and here is where custom event tracking comes into help.<\/p>\n<p>Let\u2019s look at how to set up custom event tracking in GA4.<\/p>\n<h2>How Does Google Analytics Event Tracking Work?<\/h2>\n<p>When you perform an action on a website or in the app, GA4 sends requests with detailed information about your activity, called <a href=\"https:\/\/support.google.com\/analytics\/answer\/9964640?hl=en#zippy=%2Cin-this-article\" target=\"_blank\" rel=\"noopener noreferrer\">events<\/a> (formerly \u201chits\u201d in Universal Analytics).<\/p>\n<p>After receiving those requests, GA4 processes the submitted data, aggregating and <a href=\"https:\/\/support.google.com\/analytics\/answer\/7029846?hl=en\" target=\"_blank\" rel=\"noopener noreferrer\">organizing<\/a> it to generate meaningful reports and insights.<\/p>\n<h2>How To Set up Custom Event Tracking Manually In GA4<\/h2>\n<p>First, I would like to share one of the most powerful sides of GA4: You can create custom events by using other events which meet certain criteria.<\/p>\n<p>Navigate to Events in GA4 and click the <em>Create Event<\/em> blue button in the top right corner.<\/p>\n<div>\n<dl id=\"attachment_484867\">\n<dt>\n<div class=\"wp-caption aligncenter\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/marketingnewsbox.com\/wp-content\/uploads\/2023\/05\/google-analytics-event-tracking-how-to-get-set-up-via-sejournal-vahandev.png\" alt=\"Create event\" width=\"1808\" height=\"806\" class=\" b-lazy pcimg\"><span class=\"wp-caption-text\">Screenshot from GA4, April 2023<\/span><img decoding=\"async\" src=\"https:\/\/marketingnewsbox.com\/wp-content\/uploads\/2023\/05\/google-analytics-event-tracking-how-to-get-set-up-via-sejournal-vahandev.png\" alt=\"Create event\"><\/div>\n<\/dt>\n<\/dl>\n<\/div>\n<p>In the popup dialog, click <em>Create<\/em>.<\/p>\n<p>In the dialog, you can set criteria for when your new custom event should fire.<\/p>\n<p>Here, we created a \u201cnewsletter_sign_up\u201d event on the page_view event when the page_location parameter contains \u201cnewsletter-confirmation\u201d in the URL (as you read above, GA4 tracks these by default).<\/p>\n<p>Based on your newsletter thank you page URL specifics, it can be different.<\/p>\n<div>\n<dl id=\"attachment_484870\">\n<dt>\n<div class=\"wp-caption aligncenter\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/marketingnewsbox.com\/wp-content\/uploads\/2023\/05\/google-analytics-event-tracking-how-to-get-set-up-via-sejournal-vahandev-1.png\" alt=\"Create custom event\" width=\"1479\" height=\"738\" class=\" b-lazy pcimg\"><span class=\"wp-caption-text\">Screenshot from GA4, April 2023<\/span><img decoding=\"async\" src=\"https:\/\/marketingnewsbox.com\/wp-content\/uploads\/2023\/05\/google-analytics-event-tracking-how-to-get-set-up-via-sejournal-vahandev-1.png\" alt=\"Create custom event\"><\/div>\n<\/dt>\n<\/dl>\n<\/div>\n<p>And what is even cooler: you can turn that event into a conversion and track sign-ups as conversions.<\/p>\n<p>Pretty easy, isn\u2019t it? This is one of the wonders GA4 brings with it; no coding skills are needed to make this magic happen.<\/p>\n<p>You can use this feature in a bunch of different scenarios. But if you run into a situation where this is still not enough to meet your needs, you might need to set up events with custom parameters.<\/p>\n<p>Below we will discuss advanced techniques for setting up custom events.<\/p>\n<h2>How To Set Up Custom Event Tracking With Custom Parameters In GA4<\/h2>\n<p>In Universal Analytics, there are four parameters for events you can track, and there is no option to add more parameters:<\/p>\n<ul>\n<li>Event Category.<\/li>\n<li>Event Action.<\/li>\n<li>Event Label.<\/li>\n<li>Event Value.<\/li>\n<\/ul>\n<p>In GA4, there is no longer such a structure, but it comes with more flexibility, as you can define as many event parameters as you want.<\/p>\n<p>The advantage is that you get highly customized event tracking with lots of data, but the downside is that it\u2019s no longer a plug-in-and-play like UA.<\/p>\n<p>Configuring custom event tracking in Google Analytics 4 (GA4) requires several steps.<\/p>\n<p>In order to track events with custom parameters in GA4, you have to start by adding custom dimensions, and there are two ways of doing that: <a href=\"https:\/\/developers.google.com\/analytics\/devguides\/collection\/ga4\/tag-options\" target=\"_blank\" rel=\"noopener noreferrer\">gtag and GTM-<\/a>based.<\/p>\n<p>First, we\u2019ll discuss gtag-based implementation. If you prefer GTM-based, you can skip this first section and read that part <a href=\"https:\/\/www.searchenginejournal.com\/google-analytics-event-tracking\/484607\/#gtmsetup\">below<\/a>.<\/p>\n<p>For implementation, follow the step-by-step guide below.<\/p>\n<h3><span id=\"customdimension\">How To Add Custom Dimension In GA4<\/span><\/h3>\n<p>Navigate to <em>Admin <\/em>&gt; <em>Property <\/em>&gt; <em>Custom definitions.<\/em><\/p>\n<div>\n<dl id=\"attachment_484701\">\n<dt>\n<div class=\"wp-caption aligncenter\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/marketingnewsbox.com\/wp-content\/uploads\/2023\/05\/google-analytics-event-tracking-how-to-get-set-up-via-sejournal-vahandev-2.png\" alt=\"Custom definitions in GA4\" width=\"1804\" height=\"804\" class=\" b-lazy pcimg\"><span class=\"wp-caption-text\">Screenshot from GA4, April 2023<\/span><img decoding=\"async\" src=\"https:\/\/marketingnewsbox.com\/wp-content\/uploads\/2023\/05\/google-analytics-event-tracking-how-to-get-set-up-via-sejournal-vahandev-2.png\" alt=\"Custom definitions in GA4\"><\/div>\n<\/dt>\n<\/dl>\n<\/div>\n<p>Click the <em>Create custom dimensions<\/em> blue button and create an event-scoped custom dimension by entering the dimension name and event parameter.<\/p>\n<div>\n<dl id=\"attachment_484702\">\n<dt>\n<div class=\"wp-caption aligncenter\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/marketingnewsbox.com\/wp-content\/uploads\/2023\/05\/google-analytics-event-tracking-how-to-get-set-up-via-sejournal-vahandev-3.png\" alt=\"Event scoped custom dimension\" width=\"801\" height=\"617\" class=\" b-lazy pcimg\"><span class=\"wp-caption-text\">Screenshot from GA4, April 2023<\/span><img decoding=\"async\" src=\"https:\/\/marketingnewsbox.com\/wp-content\/uploads\/2023\/05\/google-analytics-event-tracking-how-to-get-set-up-via-sejournal-vahandev-3.png\" alt=\"Event scoped custom dimension\"><\/div>\n<\/dt>\n<\/dl>\n<\/div>\n<p>For our guide, let\u2019s start with custom events tracking analogical to Universal Analytics with custom parameters.<\/p>\n<ul>\n<li>Event Category.<\/li>\n<li>Event Action.<\/li>\n<li>Event Label.<\/li>\n<\/ul>\n<p>Suppose you want to track clicks on your main navigation menu.<\/p>\n<p>In this case, you could set the <em>Event Category<\/em>&nbsp;to <em>Menu Clicks<\/em>, the <em>Event Action<\/em> to the anchor link, and the <em>Event Label<\/em> to the anchor text.<\/p>\n<p>An example use case for this setup is to change the anchor text of menu items and track which ones attract more clicks, allowing you to optimize your navigation menu for better user engagement and conversion rates.<\/p>\n<p>Per GA4 <a href=\"https:\/\/developers.google.com\/analytics\/devguides\/collection\/ga4\/events\" rel=\"nofollow noopener noreferrer\" target=\"_blank\">documentation<\/a>, you should trigger a gtag event when one clicks on your menu items (we assume links are inside the &lt;li&gt; html tag, which have .menu-item class).&nbsp; You can see the example code below.<\/p>\n<pre>&lt;script&gt;\ndocument.addEventListener('DOMContentLoaded', function() { var menu_anchors = document.querySelectorAll('.menu-items a'); \/\/Click event listener to each anchor element menu_anchors.forEach((anchor) =&gt; { anchor.addEventListener('click', (event) =&gt; {\n&nbsp; &nbsp; gtag('event', 'menu_clicks', {\n&nbsp; &nbsp; &nbsp; 'event_category': 'Menu Clicks',\n&nbsp; &nbsp; &nbsp; 'event_action': anchor.href,\n&nbsp; &nbsp; &nbsp; 'event_label': anchor.textContent\n&nbsp; &nbsp; });\n&nbsp; }); });\n});\n&lt;\/script&gt;<\/pre>\n<p>The event name \u201cmenu_clicks\u201d can be anything you want, and it will have three parameters you provide. This is one approach if you don\u2019t have Google Tag Manager and prefer gtag implementation.<\/p>\n<p>You can use custom parameters to pass additional values to predefined events, for example, <a href=\"https:\/\/developers.google.com\/analytics\/devguides\/collection\/ga4\/reference\/events?client_type=gtag#sign_up\" target=\"_blank\" rel=\"noopener noreferrer\">sign_up<\/a> event. Per GA\u2019s documentation, it supports only one parameter called \u201cmethod\u201d ( which can be anything, e.g., social login, email, etc. )<\/p>\n<pre>gtag(\"event\", \"sign_up\", {\nmethod: \"Google\"\n});<\/pre>\n<p>By adding custom dimensions, you can also pass additional information such as sign-up subscription plan (for example, \u201cfree trial,\u201d \u201cbasic,\u201d \u201cpremium.\u201d)<\/p>\n<p>You can add custom dimension\u201dsign_up_plan\u201d and pass along with \u201cmethod.\u201d<\/p>\n<pre>gtag(\"event\", \"sign_up\", {\nmethod: \"Google\",\nsign_up_plan: \"basic\",\n});<\/pre>\n<p>To implement all these, you need basic JS programmer skills, which you can quickly learn by <a href=\"https:\/\/www.searchenginejournal.com\/chatgpt-examples\/474937\/\">using ChatGPT<\/a>. You can now test the prompt:<\/p>\n<blockquote>\n<p>JavaScript code that triggers a gtag custom event with the name \u2018menu_clicks\u2019 when a user clicks on a menu item with a parent li tag that has class \u2018.menu-item\u2019. Pass the following custom event parameters: \u2018event_category\u2019 should be set to \u2018Menu Clicks\u2019, \u2018event_action\u2019 should be set to the link of the clicked item, and \u2018event_label\u2019 should be set to the anchor text of the clicked item.<\/p>\n<\/blockquote>\n<p>Try this prompt, and you will see the magic happening.<\/p>\n<p>You can copy and paste that code into your CMS code editor, and voila!<\/p>\n<p>Now, let\u2019s set up the same event tracking using the GTM tag.<\/p>\n<p>I assume you\u2019ve already installed <a href=\"https:\/\/www.searchenginejournal.com\/google-tag-manager-ga4-guide\/396169\/\">GA4 via Google Tag Manager<\/a> and will proceed with the steps from there.<\/p>\n<p>You would need to add custom dimensions per the steps explained in the <a href=\"https:\/\/www.searchenginejournal.com\/google-analytics-event-tracking\/484607\/#customdimension\">section above.<\/a><\/p>\n<h3><span id=\"gtmsetup\">How To Set Up Event Tracking In Google Tag Manager<\/span><\/h3>\n<p>Create a new a new JavaScript variable in GTM that returns clicked anchor\u2019s parent tag class name \u2013 because, in GTM, there is no built-in way to get parent DOM element attributes.<\/p>\n<p>Navigate to <em>Variables<\/em> &gt; <em>User-Defined Variables<\/em> and click the <em>New <\/em>button on the top right corner. In the popup dialog, select <em>Custom Javascript.<\/em><\/p>\n<div>\n<dl id=\"attachment_484719\">\n<dt>\n<div class=\"wp-caption aligncenter\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/marketingnewsbox.com\/wp-content\/uploads\/2023\/05\/google-analytics-event-tracking-how-to-get-set-up-via-sejournal-vahandev-4.png\" alt=\"Custom javascript variable in GTM\" width=\"1920\" height=\"820\" class=\" b-lazy pcimg\"><span class=\"wp-caption-text\">Screenshot from GA4, April 2023<\/span><img decoding=\"async\" src=\"https:\/\/marketingnewsbox.com\/wp-content\/uploads\/2023\/05\/google-analytics-event-tracking-how-to-get-set-up-via-sejournal-vahandev-4.png\" alt=\"Custom javascript variable in GTM\"><\/div>\n<\/dt>\n<\/dl>\n<\/div>\n<p>Copy and paste this code into it.<\/p>\n<pre>function() {\n&nbsp;'use strict';\n&nbsp;try {\n&nbsp; &nbsp; &nbsp; &nbsp;var clickElement = {{Click Element}}; \/\/ clickable element DOM object\n&nbsp; &nbsp; &nbsp; &nbsp;var clickParent = clickElement.closest('.menu-item'); \/\/clickable element DOM object parent with class .menu-item\n&nbsp; &nbsp; &nbsp; &nbsp;if (!clickParent) return '';&nbsp;\n&nbsp; &nbsp; &nbsp; &nbsp;return clickParent.getAttribute('class'); \/\/ if element exist return class attribute\n&nbsp;} catch (err) {\n&nbsp; &nbsp; &nbsp; &nbsp;return '';\n&nbsp;}\n}<\/pre>\n<div>\n<dl id=\"attachment_484721\">\n<dt>\n<div class=\"wp-caption aligncenter\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/marketingnewsbox.com\/wp-content\/uploads\/2023\/05\/google-analytics-event-tracking-how-to-get-set-up-via-sejournal-vahandev-5.png\" alt=\"Custom JavaScript variable which returns class name of parent tag\" width=\"1920\" height=\"820\" class=\" b-lazy pcimg\"><span class=\"wp-caption-text\">Screenshot from GA4, April 2023<\/span><img decoding=\"async\" src=\"https:\/\/marketingnewsbox.com\/wp-content\/uploads\/2023\/05\/google-analytics-event-tracking-how-to-get-set-up-via-sejournal-vahandev-5.png\" alt=\"Custom JavaScript variable which returns class name of parent tag\"><\/div>\n<\/dt>\n<\/dl>\n<\/div>\n<p>This code returns the parent class attribute of a clicked element when there is a parent with class \u2018.menu-item\u2019, or it returns an empty value if there is no such parent element.<\/p>\n<p>We can use this to ensure that we only detect clicks on menu item links, not other links elsewhere on the page.<\/p>\n<p>Create a new trigger in GTM that fires on all clicks on elements with a parent &lt;li&gt; that has class of \u201cmenu-item\u201d.<\/p>\n<p>Navigate to Triggers and click the <em>New<\/em> button in the top right corner.<\/p>\n<p>From the popup dialog, select <em>Click \u2013 Just Links.<\/em><\/p>\n<div>\n<dl id=\"attachment_484722\">\n<dt>\n<div class=\"wp-caption aligncenter\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/marketingnewsbox.com\/wp-content\/uploads\/2023\/05\/google-analytics-event-tracking-how-to-get-set-up-via-sejournal-vahandev-6.png\" alt=\"Add new click event GTM dialog\" width=\"1920\" height=\"820\" class=\" b-lazy pcimg\"><span class=\"wp-caption-text\">Screenshot from GA4, April 2023<\/span><img decoding=\"async\" src=\"https:\/\/marketingnewsbox.com\/wp-content\/uploads\/2023\/05\/google-analytics-event-tracking-how-to-get-set-up-via-sejournal-vahandev-6.png\" alt=\"Add new click event GTM dialog\"><\/div>\n<\/dt>\n<dd><\/dd>\n<dd>Add new click event GTM dialog<\/dd>\n<\/dl>\n<\/div>\n<p>Choose <em>Some Link Clicks<\/em>&nbsp;&gt; <em>Configure<\/em> it to fire on clicks where the parent element class contains the string \u201cmenu-item.\u201d<\/p>\n<div>\n<dl id=\"attachment_484723\">\n<dt>\n<div class=\"wp-caption aligncenter\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/marketingnewsbox.com\/wp-content\/uploads\/2023\/05\/google-analytics-event-tracking-how-to-get-set-up-via-sejournal-vahandev-7.png\" alt=\"Some Link Clicks\" width=\"1920\" height=\"893\" class=\" b-lazy pcimg\"><span class=\"wp-caption-text\">Screenshot from GA4, April 2023<\/span><img decoding=\"async\" src=\"https:\/\/marketingnewsbox.com\/wp-content\/uploads\/2023\/05\/google-analytics-event-tracking-how-to-get-set-up-via-sejournal-vahandev-7.png\" alt=\"Some Link Clicks\"><\/div>\n<\/dt>\n<\/dl>\n<\/div>\n<p>Navigate to Tags and add the GA4 Event tag.<\/p>\n<div class=\"wp-caption aligncenter\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/marketingnewsbox.com\/wp-content\/uploads\/2023\/05\/google-analytics-event-tracking-how-to-get-set-up-via-sejournal-vahandev-8.png\" alt=\"Choose tag type\" width=\"1920\" height=\"820\" class=\" b-lazy pcimg\"><span class=\"wp-caption-text\">Screenshot from GA4, April 2023<\/span><img decoding=\"async\" src=\"https:\/\/marketingnewsbox.com\/wp-content\/uploads\/2023\/05\/google-analytics-event-tracking-how-to-get-set-up-via-sejournal-vahandev-8.png\" alt=\"Choose tag type\"><\/div>\n<p>Fill in as event name \u201cmain_menu_clicks\u201d or whatever you want to name the event, and add custom parameters event_category, event_action, and event_label.<\/p>\n<div class=\"wp-caption aligncenter\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/marketingnewsbox.com\/wp-content\/uploads\/2023\/05\/google-analytics-event-tracking-how-to-get-set-up-via-sejournal-vahandev-9.png\" alt=\"GA4 - Menu Click\" width=\"1531\" height=\"800\" class=\" b-lazy pcimg\"><span class=\"wp-caption-text\">Screenshot from GA4, April 2023<\/span><img decoding=\"async\" src=\"https:\/\/marketingnewsbox.com\/wp-content\/uploads\/2023\/05\/google-analytics-event-tracking-how-to-get-set-up-via-sejournal-vahandev-9.png\" alt=\"GA4 - Menu Click\"><\/div>\n<p>For event action and label, choose <em>Click Text<\/em> and <em>Click URL<\/em> build-in variables.<\/p>\n<div class=\"wp-caption aligncenter\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/marketingnewsbox.com\/wp-content\/uploads\/2023\/05\/google-analytics-event-tracking-how-to-get-set-up-via-sejournal-vahandev-10.png\" alt=\"Choose a service\" width=\"1920\" height=\"893\" class=\" b-lazy pcimg\"><span class=\"wp-caption-text\">Screenshot from GA4, April 2023<\/span><img decoding=\"async\" src=\"https:\/\/marketingnewsbox.com\/wp-content\/uploads\/2023\/05\/google-analytics-event-tracking-how-to-get-set-up-via-sejournal-vahandev-10.png\" alt=\"Choose a service\"><\/div>\n<p>Choose the trigger of Menu Clicks we created before, and save the tag.<\/p>\n<div>\n<dl id=\"attachment_484728\">\n<dt>\n<div class=\"wp-caption aligncenter\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/marketingnewsbox.com\/wp-content\/uploads\/2023\/05\/google-analytics-event-tracking-how-to-get-set-up-via-sejournal-vahandev-11.png\" alt=\"Add trigger\" width=\"1433\" height=\"749\" class=\" b-lazy pcimg\"><span class=\"wp-caption-text\">Screenshot from GA4, April 2023<\/span><img decoding=\"async\" src=\"https:\/\/marketingnewsbox.com\/wp-content\/uploads\/2023\/05\/google-analytics-event-tracking-how-to-get-set-up-via-sejournal-vahandev-11.png\" alt=\"Add trigger\"><\/div>\n<\/dt>\n<\/dl>\n<\/div>\n<p>Publish changes and <a href=\"https:\/\/www.searchenginejournal.com\/google-analytics-event-tracking\/484607\/#debugga4\">debug<\/a> to ensure when you click on your menu items, the event is triggering with all parameters set correctly.<\/p>\n<div>\n<dl id=\"attachment_484732\">\n<dt>\n<div class=\"wp-caption aligncenter\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/marketingnewsbox.com\/wp-content\/uploads\/2023\/05\/google-analytics-event-tracking-how-to-get-set-up-via-sejournal-vahandev-12.png\" alt=\"GTM preview mode\" width=\"1921\" height=\"893\" class=\" b-lazy pcimg\"><span class=\"wp-caption-text\">Screenshot from GA4, April 2023<\/span><img decoding=\"async\" src=\"https:\/\/marketingnewsbox.com\/wp-content\/uploads\/2023\/05\/google-analytics-event-tracking-how-to-get-set-up-via-sejournal-vahandev-12.png\" alt=\"GTM preview mode\"><\/div>\n<\/dt>\n<\/dl>\n<\/div>\n<h2>How To Implement Custom Event Tracking By Using dataLayer.push() Method<\/h2>\n<p>If you still prefer custom coding and have GTM, you can use the datalayer.push() method.<\/p>\n<p>In that case, you would need to add event_category, event_action, and event_label parameters in GTM as dataLayer variables.<\/p>\n<div>\n<dl id=\"attachment_484850\">\n<dt>\n<div class=\"wp-caption aligncenter\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/marketingnewsbox.com\/wp-content\/uploads\/2023\/05\/google-analytics-event-tracking-how-to-get-set-up-via-sejournal-vahandev-13.png\" alt=\"GTM datalayer variable\" width=\"1920\" height=\"893\" class=\" b-lazy pcimg\"><span class=\"wp-caption-text\">Screenshot from GA4, April 2023<\/span><img decoding=\"async\" src=\"https:\/\/marketingnewsbox.com\/wp-content\/uploads\/2023\/05\/google-analytics-event-tracking-how-to-get-set-up-via-sejournal-vahandev-13.png\" alt=\"GTM datalayer variable\"><\/div>\n<\/dt>\n<\/dl>\n<\/div>\n<p>And on your website &lt;head&gt; section, you should use the code below.<\/p>\n<pre>&lt;script&gt;\n\/\/Click event listener to menu items with the '.menu-item' class\ndocument.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() dataLayer.push({ 'event': 'menu_clicks', 'event_category': 'Menu Clicks', 'event_action': link, 'event_label': anchorText }); }); });\n});\n&lt;\/script&gt;<\/pre>\n<h2><span id=\"#debugga4\">How Do I Know If Google Analytics Event Tracking Is Working?<\/span><\/h2>\n<p>It is also important to check if you see an event log with the same parameters in GA4 <a href=\"https:\/\/support.google.com\/tagmanager\/answer\/6107056?hl=en\" target=\"_blank\" rel=\"noopener noreferrer\">debug<\/a> view. It may happen that GTM will fire, but because of misconfiguration, it will not be passed to GA4.<\/p>\n<div>\n<dl id=\"attachment_484733\">\n<dt>\n<div class=\"wp-caption aligncenter\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/marketingnewsbox.com\/wp-content\/uploads\/2023\/05\/google-analytics-event-tracking-how-to-get-set-up-via-sejournal-vahandev-14.png\" alt=\"GA4 debug view\" width=\"1428\" height=\"771\" class=\" b-lazy pcimg\"><span class=\"wp-caption-text\">Screenshot from GA4, April 2023<\/span><img decoding=\"async\" src=\"https:\/\/marketingnewsbox.com\/wp-content\/uploads\/2023\/05\/google-analytics-event-tracking-how-to-get-set-up-via-sejournal-vahandev-14.png\" alt=\"GA4 debug view\"><\/div>\n<\/dt>\n<\/dl>\n<\/div>\n<p>In case you have gtag implementation, you should enable debug mode by installing the Chrome <a href=\"https:\/\/chrome.google.com\/webstore\/detail\/google-analytics-debugger\/jnkmfdileelhofjcijamephohjechhna?sjid=16320802629324660385-EU\" target=\"_blank\" rel=\"noopener noreferrer\">extension<\/a> or by adding one line of code to your GA4 <a href=\"https:\/\/support.google.com\/analytics\/answer\/7201382?hl=en#zippy=%2Cgoogle-tag-gtagjs\" target=\"_blank\" rel=\"noopener noreferrer\">configuration<\/a>.<\/p>\n<pre>gtag('config', 'G-12345ABCDE', { 'debug_mode':true });<\/pre>\n<p>Always debug and make sure that all custom parameters pass as expected.<\/p>\n<h2>Conclusion<\/h2>\n<p>GA4 is quite challenging and not a plug-and-play analytics tool like Universal Analytics; you need to spend a good amount of time learning it.<\/p>\n<p>On the other hand, it comes with plenty of new features you can use and enhance your analytics to an unprecedented level.<\/p>\n<p>By being able to customize the event tracking, you get a powerful skill that even can help you work around some of the attribution models that Google Analytics is <a href=\"https:\/\/www.searchenginejournal.com\/google-is-removing-4-attribution-models-for-advertisers\/484264\/\">sunsetting<\/a> by tracking users\u2019 first visit source in a custom dimension.<\/p>\n<p>With this in mind, I will be publishing a step-by-step guide on how to (partially) restore the first attribution model using custom event parameters.<\/p>\n<p><strong>More resources:<\/strong><\/p>\n<hr>\n<p><em>Featured Image: Andrey_Popov\/Shutterstock<\/em><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Universal Analytics is being sunset, and everyone is rushing to migrate from UA to Google Analytics 4 (GA4). In this guide, we\u2019ll help you migrate your custom events and walk you through how to set up GA4 custom events. Types Of Events That GA4 Automatically Tracks By Default Google Analytics 4 automatically tracks several events&#8230; <\/p>\n","protected":false},"author":1,"featured_media":17780,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[103],"tags":[],"class_list":["post-17779","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-search-engine-marketing"],"_links":{"self":[{"href":"https:\/\/marketingnewsbox.com\/index.php?rest_route=\/wp\/v2\/posts\/17779","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/marketingnewsbox.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/marketingnewsbox.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/marketingnewsbox.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/marketingnewsbox.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=17779"}],"version-history":[{"count":0,"href":"https:\/\/marketingnewsbox.com\/index.php?rest_route=\/wp\/v2\/posts\/17779\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/marketingnewsbox.com\/index.php?rest_route=\/wp\/v2\/posts\/17780"}],"wp:attachment":[{"href":"https:\/\/marketingnewsbox.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=17779"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/marketingnewsbox.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=17779"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/marketingnewsbox.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=17779"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}