{"id":383,"date":"2018-03-19T17:24:42","date_gmt":"2018-03-19T17:24:42","guid":{"rendered":"https:\/\/www.searchenginewatch.com\/2018\/03\/19\/how-to-set-up-event-tracking-in-google-analytics\/"},"modified":"2019-08-07T16:28:07","modified_gmt":"2019-08-07T16:28:07","slug":"how-to-set-up-event-tracking-in-google-analytics","status":"publish","type":"post","link":"https:\/\/searchenginewatch.com\/2018\/03\/19\/how-to-set-up-event-tracking-in-google-analytics\/","title":{"rendered":"How to set up event tracking in Google Analytics"},"content":{"rendered":"<p><strong>Event tracking is one of the most useful features in <a href=\"https:\/\/searchenginewatch.com\/2019\/05\/31\/image-optimization-for-seo\/\">Google<\/a> Analytics.<\/strong><\/p>\n<p>With just a little bit of extra code, you can capture all kinds of information about how people behave on your site.<\/p>\n<p>Event tracking lets you monitor just about any action that doesn\u2019t trigger a new page to load, such as watching a video or clicking on an outbound link. This data can be invaluable in improving your site.<\/p>\n<p>There are two different ways you can set up event tracking in <a href=\"https:\/\/searchenginewatch.com\/2019\/02\/06\/using-python-to-recover-seo-site-traffic-part-one\/\">Google Analytics<\/a>. One way is to add the code manually. The other is to set up tracking through <a href=\"https:\/\/searchenginewatch.com\/2018\/03\/15\/7-google-tag-manager-courses-to-prioritize-in-2018\/\">Google Tag Manager<\/a>.<\/p>\n<p>Both methods are doable without a developer, although you may find it easier to use <a href=\"https:\/\/searchenginewatch.com\/2018\/05\/21\/no-need-for-google-12-alternative-search-engines-in-2018\/\">Google<\/a> Tag Manager if you have no <a href=\"https:\/\/searchenginewatch.com\/2019\/02\/06\/using-python-to-recover-seo-site-traffic-part-one\/\">coding<\/a> experience.<\/p>\n<h2><strong>How to set up event tracking manually<\/strong><\/h2>\n<p>What exactly is an event? Before you start tracking events, it\u2019s important to understand how they\u2019re put together. Each event is made up of four components that you define. These are category, action, label, and value.<\/p>\n<h4>Category<\/h4>\n<p>A <strong>category<\/strong> is an overall group of events. You can create more than one type of event to track in the same category \u201cbasket.\u201d<\/p>\n<p>For instance, you could create a category called Downloads to group a number of different events involving various downloads from your site.<\/p>\n<h4>Action<\/h4>\n<p>An event\u2019s <strong>action <\/strong>describes the particular action that the event is set up to track. If you\u2019re tracking downloads of a PDF file, for instance, you might call your event\u2019s action Download PDF.<\/p>\n<h4>Label<\/h4>\n<p>Your <strong>label <\/strong>provides more information about the action taken. For instance, if you have several PDFs available for download on your site, you can keep track of how many people download each one by labeling each separate event with the PDF\u2019s title.<\/p>\n<p>A label is optional, but it\u2019s almost always a good idea to use one.<\/p>\n<h4>Value<\/h4>\n<p><strong>Value<\/strong> is an optional component that lets you track a numerical value associated with an event. Unlike the first three components, which are made up of text, value is always an integer.<\/p>\n<p>For instance, if you wanted to keep track of a video\u2019s load time, you would use the value component to do so. If you don\u2019t need to keep track of anything numerical, it\u2019s fine to leave this component out of your event.<\/p>\n<p style=\"text-align: center;\"><a href=\"https:\/\/searchenginewatch.com\/wp-content\/uploads\/sites\/25\/2018\/03\/image6.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-75135 aligncenter\" src=\"https:\/\/searchenginewatch.com\/wp-content\/uploads\/sites\/25\/2018\/03\/image6.jpg\" alt=\"\" width=\"806\" height=\"191\" \/><\/a><\/p>\n<p style=\"text-align: center;\"><em>A table of the four components of an event. <a href=\"https:\/\/developers.google.com\/analytics\/devguides\/collection\/analyticsjs\/events#overview\">Source: Google Analytics<\/a><\/em><\/p>\n<h3><strong>Step one: Decide how to structure your reports<\/strong><\/h3>\n<p>Before you dive into tracking your events, come up with a plan for how you want your data to be organized. Decide which categories, actions, and labels you\u2019ll use, and choose a clear and consistent naming pattern for them.<\/p>\n<p>Remember, if you decide to change the structure of your event tracking later, your data won\u2019t be reorganized retroactively. A little thought and planning up front can save you a lot of hassle down the road.<\/p>\n<h3><strong>Step two: Connect your site to Google Analytics<\/strong><\/h3>\n<p>If you haven\u2019t done so already, set up a <a href=\"https:\/\/searchenginewatch.com\/2019\/04\/25\/whats-it-like-using-duckduckgo-in-2019\/\">Google<\/a> <a href=\"https:\/\/searchenginewatch.com\/2019\/07\/18\/how-to-set-up-google-analytics-annotations-to-show-google-updates\/\">Analytics<\/a> property and get your tracking ID. You can find your tracking ID by going to the admin section of your GA account and navigating to the property you want to track.<\/p>\n<p>Once you have your ID, add the following snippet right after the <strong>&lt;head&gt;<\/strong> tag of each page:<\/p>\n<p><code>&lt;!-- Global Site Tag (gtag.js) - Google Analytics --&gt;<br \/>\n&lt;script async src=\"https:\/\/www.googletagmanager.com\/gtag\/js?id=GA_TRACKING_ID\"&gt;&lt;\/script&gt;<br \/>\n&lt;script&gt;<br \/>\nwindow.dataLayer = window.dataLayer || [];<br \/>\nfunction gtag(){dataLayer.push(arguments);}<br \/>\ngtag('js', new Date());<\/code><\/p>\n<p><code>gtag('config', 'GA_TRACKING_ID');<br \/>\n&lt;\/script&gt;<\/code><\/p>\n<p><em>This code snippet enables <a href=\"https:\/\/searchenginewatch.com\/2019\/05\/20\/seven-reasons-why-your-rankings-dropped-and-how-to-fix-them\/\">Google<\/a> <a href=\"https:\/\/searchenginewatch.com\/2019\/07\/02\/competitive-research-insight-tools\/\">Analytics<\/a> to track events on your site. Replace GA_TRACKING_ID with your own tracking ID.\u00a0<a href=\"https:\/\/support.google.com\/analytics\/answer\/1008080\">Source: Analytics Help<\/a><\/em><\/p>\n<h3><strong>Step three: Add code snippets to elements you want to track<\/strong><\/h3>\n<p>Here is the format for an event tracking code snippet:<\/p>\n<p><code>ga('send', 'event', [<a href=\"https:\/\/developers.google.com\/analytics\/devguides\/collection\/analyticsjs\/field-reference#eventCategory\">eventCategory<\/a>], [<a href=\"https:\/\/developers.google.com\/analytics\/devguides\/collection\/analyticsjs\/field-reference#eventAction\">eventAction<\/a>], [<a href=\"https:\/\/developers.google.com\/analytics\/devguides\/collection\/analyticsjs\/field-reference#eventLabel\">eventLabel<\/a>], [<a href=\"https:\/\/developers.google.com\/analytics\/devguides\/collection\/analyticsjs\/field-reference#eventValue\">eventValue<\/a>], [fieldsObject]);<\/code><\/p>\n<p>After filling in the information that defines the event you want to track, add this snippet to the relevant element on your webpage. You\u2019ll need to use something called an event handler to do so.<\/p>\n<p>An event handler is a HTML term that triggers your tracking code to fire when a specific action is completed. For instance, if you wanted to track how many times visitors clicked on a button, you would use the onclick event handler and your code would look like this:<\/p>\n<p><code>&lt;button onclick=\"ga('send', 'event', [<a href=\"https:\/\/developers.google.com\/analytics\/devguides\/collection\/analyticsjs\/field-reference#eventCategory\">eventCategory<\/a>], [<a href=\"https:\/\/developers.google.com\/analytics\/devguides\/collection\/analyticsjs\/field-reference#eventAction\">eventAction<\/a>], [<a href=\"https:\/\/developers.google.com\/analytics\/devguides\/collection\/analyticsjs\/field-reference#eventLabel\">eventLabel<\/a>], [<a href=\"https:\/\/developers.google.com\/analytics\/devguides\/collection\/analyticsjs\/field-reference#eventValue\">eventValue<\/a>], [fieldsObject]);\"&gt;Example Button Text&lt;\/button&gt;<\/code><\/p>\n<p>You can find a list of common event handlers, as well as a more in-depth explanation on how they work, <a href=\"https:\/\/www.w3schools.com\/js\/js_events.asp\">here<\/a>.<\/p>\n<h3><strong>Step four: Verify that your code is working<\/strong><\/h3>\n<p>Once you\u2019ve added event tracking code to your page, the final step is to make sure it\u2019s working. The simplest way to do this is to trigger the event yourself. Then, check <a href=\"https:\/\/searchenginewatch.com\/2019\/05\/30\/implement-googles-how-to-schema\/\">Google<\/a> Analytics to see if the event showed up.<\/p>\n<p>You can view your tracked events by clicking \u201cBehavior\u201d in the sidebar and scrolling down to \u201cEvents.\u201d<\/p>\n<p style=\"text-align: center;\"><a href=\"https:\/\/searchenginewatch.com\/wp-content\/uploads\/sites\/25\/2018\/03\/image7.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-75136 aligncenter\" src=\"https:\/\/searchenginewatch.com\/wp-content\/uploads\/sites\/25\/2018\/03\/image7.jpg\" alt=\"\" width=\"249\" height=\"603\" \/><\/a><\/p>\n<p>Your tracked events can be found under &#8220;Behavior&#8221; in <a href=\"https:\/\/searchenginewatch.com\/2019\/06\/10\/online-reviews-powerful-seo-weapons\/\">Google<\/a> Analytics.<\/p>\n<h2><strong>How to set up event tracking with Google Tag Manager<\/strong><\/h2>\n<p><a href=\"https:\/\/searchenginewatch.com\/2019\/06\/17\/local-seo-guide\/\">Google<\/a> Tag Manager can be a little tricky to navigate if you aren\u2019t familiar with it. However, if you\u2019ve never worked with code before, you might find tracking events with GTM easier than doing it manually.<\/p>\n<p>If you have a large site or you want to track many different things, GTM can also help you scale your event tracking easily.<\/p>\n<h3><strong>Step one: Enable built-in click variables<\/strong><\/h3>\n<p>You\u2019ll need GTM\u2019s built-in click variables to create your tags and triggers, so start by making sure they are enabled. Select \u201cVariables\u201d in the sidebar and click the \u201cConfigure\u201d button.<\/p>\n<p style=\"text-align: center;\"><a href=\"https:\/\/searchenginewatch.com\/wp-content\/uploads\/sites\/25\/2018\/03\/image10.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-75129 aligncenter\" src=\"https:\/\/searchenginewatch.com\/wp-content\/uploads\/sites\/25\/2018\/03\/image10.jpg\" alt=\"\" width=\"394\" height=\"381\" \/><\/a><\/p>\n<p style=\"text-align: center;\"><em>Enabling built-in click variables, step one<\/em><\/p>\n<p>Then make sure all the click variables are checked.<\/p>\n<p style=\"text-align: center;\"><a href=\"https:\/\/searchenginewatch.com\/wp-content\/uploads\/sites\/25\/2018\/03\/image9.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-75138 aligncenter\" src=\"https:\/\/searchenginewatch.com\/wp-content\/uploads\/sites\/25\/2018\/03\/image9.jpg\" alt=\"\" width=\"612\" height=\"384\" \/><\/a><\/p>\n<p style=\"text-align: center;\"><em>Enabling built-in click variables, step two. <a href=\"https:\/\/support.google.com\/analytics\/answer\/6164470?hl=en\">Source<\/a><\/em><\/p>\n<h3><strong>Step two: Create a new tag for the event you want to track<\/strong><\/h3>\n<p>Click \u201cTags\u201d on the sidebar. Then click the \u201cNew\u201d button. You\u2019ll have the option to select your tag type. Choose \u201cUniversal Analytics.\u201d<\/p>\n<p style=\"text-align: center;\"><a href=\"https:\/\/searchenginewatch.com\/wp-content\/uploads\/sites\/25\/2018\/03\/image2.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-75131\" src=\"https:\/\/searchenginewatch.com\/wp-content\/uploads\/sites\/25\/2018\/03\/image2.jpg\" alt=\"\" width=\"752\" height=\"365\" \/><\/a><\/p>\n<p style=\"text-align: center;\"><em>Creating a new tag in Google Tag Manager<\/em><\/p>\n<h3><strong>Step three: Configure your tag<\/strong><\/h3>\n<p>Set your new tag\u2019s track type to \u201cEvent.\u201d Fill in all the relevant information \u2013 category, action, label, etc. \u2013 in the fields that appear underneath, and click \u201cContinue.\u201d<\/p>\n<p style=\"text-align: center;\"><a href=\"https:\/\/searchenginewatch.com\/wp-content\/uploads\/sites\/25\/2018\/03\/image1.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-75130 aligncenter\" src=\"https:\/\/searchenginewatch.com\/wp-content\/uploads\/sites\/25\/2018\/03\/image1.jpg\" alt=\"\" width=\"381\" height=\"765\" \/><\/a><\/p>\n<p style=\"text-align: center;\"><em>An example of how to configure a new tag in Google Tag Manager. <a href=\"https:\/\/support.google.com\/analytics\/answer\/6164470?hl=en\">Source<\/a>: Analytics Help<\/em><\/p>\n<h2><strong>Step four: Specify your trigger<\/strong><\/h2>\n<p>Specify the trigger that will make your tag fire \u2013 for instance, a click. If you are creating a new trigger (as opposed to using one you\u2019ve created in the past), you will need to configure it.<\/p>\n<p style=\"text-align: center;\"><a href=\"https:\/\/searchenginewatch.com\/wp-content\/uploads\/sites\/25\/2018\/03\/image4.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-75133\" src=\"https:\/\/searchenginewatch.com\/wp-content\/uploads\/sites\/25\/2018\/03\/image4.jpg\" alt=\"\" width=\"352\" height=\"479\" \/><\/a><\/p>\n<p style=\"text-align: center;\"><em>Types of triggers that you can choose in Google Tag Manager<\/em><\/p>\n<p style=\"text-align: center;\"><a href=\"https:\/\/searchenginewatch.com\/wp-content\/uploads\/sites\/25\/2018\/03\/image3.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-75132 aligncenter\" src=\"https:\/\/searchenginewatch.com\/wp-content\/uploads\/sites\/25\/2018\/03\/image3.jpg\" alt=\"\" width=\"921\" height=\"387\" \/><\/a><\/p>\n<p style=\"text-align: center;\"><em>An example of how to configure a trigger. This one fires when a certain URL is clicked. <a href=\"https:\/\/johannesmehlem.com\/blog\/google-analytics-event-tracking-via-google-tag-manager\/\">Source: Johannes Mehlem<\/a><\/em><\/p>\n<h2><strong>Step five: Save the finished tag<\/strong><\/h2>\n<p>After you save your trigger, it should show up in your tag. Click \u201cSave Tag\u201d to complete the process.<\/p>\n<p style=\"text-align: center;\"><a href=\"https:\/\/searchenginewatch.com\/wp-content\/uploads\/sites\/25\/2018\/03\/image5.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-75134 aligncenter\" src=\"https:\/\/searchenginewatch.com\/wp-content\/uploads\/sites\/25\/2018\/03\/image5.jpg\" alt=\"\" width=\"483\" height=\"669\" \/><\/a><\/p>\n<p style=\"text-align: center;\"><em>A tag that is ready to go. <a href=\"https:\/\/support.google.com\/analytics\/answer\/6164470?hl=en\">Source: Analytics Help<\/a><\/em><\/p>\n<h2><strong>The takeaway and extra resources<\/strong><\/h2>\n<p>Event tracking is one of the most useful and versatile analytics techniques available \u2013 you can use it to monitor nearly anything you want. While this guide will get you started, there\u2019s a lot more to know about event tracking with <a href=\"https:\/\/searchenginewatch.com\/2019\/07\/11\/seo-lead-site-migration\/\">Google Analytics<\/a>, so don\u2019t be afraid to look for resources that will help you understand event tracking.<\/p>\n<p>Courses like <a href=\"https:\/\/www.udemy.com\/the-2018-google-analytics-bootcamp\/\">the 2018 Google Analytics Bootcamp on Udemy<\/a> (which I used to help write this article) will give you a solid grounding in how to use Google Analytics and Google Tag Manager, so you\u2019ll be able to proceed with confidence.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Event tracking is one of the most useful features in Google Analytics. With just a little bit of extra code, you can capture all kinds of information about how people behave on your site. Event tracking lets you monitor just about any action on your site that doesn\u2019t trigger a new page to load, giving invaluable data for improving your site.<\/p>\n","protected":false},"author":1092,"featured_media":384,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[16],"tags":[],"content_type":[27095],"class_list":["post-383","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-analytics","content_type-news"],"acf":{"tad_independentcommercial":false,"tad_content_format":false},"post_info":{"name":"idris.nagri@blenheimchalcot.com idris.nagri@blenheimchalcot.com","title":"","thumbnail_url":"https:\/\/searchenginewatch.com\/wp-content\/uploads\/2018\/10\/GA-event-tracking-120x90.jpg","category":"Analytics","timeago":"8y"},"_links":{"self":[{"href":"https:\/\/searchenginewatch.com\/wp-json\/wp\/v2\/posts\/383","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/searchenginewatch.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/searchenginewatch.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/searchenginewatch.com\/wp-json\/wp\/v2\/users\/1092"}],"replies":[{"embeddable":true,"href":"https:\/\/searchenginewatch.com\/wp-json\/wp\/v2\/comments?post=383"}],"version-history":[{"count":0,"href":"https:\/\/searchenginewatch.com\/wp-json\/wp\/v2\/posts\/383\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/searchenginewatch.com\/wp-json\/wp\/v2\/media\/384"}],"wp:attachment":[{"href":"https:\/\/searchenginewatch.com\/wp-json\/wp\/v2\/media?parent=383"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/searchenginewatch.com\/wp-json\/wp\/v2\/categories?post=383"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/searchenginewatch.com\/wp-json\/wp\/v2\/tags?post=383"},{"taxonomy":"content_type","embeddable":true,"href":"https:\/\/searchenginewatch.com\/wp-json\/wp\/v2\/content_type?post=383"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}