Once properly installed on your website, Google Analytics (GA) can provide some pretty incredible insights without any additional configuration or setup. Identifying where the traffic to your site originates, how long users stay on your site, what content is most popular. All of these questions can be answered with just the basic Google Analytics Tracking Code (GATC) installation, pretty cool. But what happens when your thirst for data grows more intense? When you want to know more about your website traffic. Often times this requires additional set up around your analytics coding to track those further engagements.
A common request we receive from clients who want to gain more out of their data is to set up Event Tracking for certain elements of their site. If you are not familiar, Event Tracking is a technique employed through GA to capture engagements that happen on your site that do not register the typical Pageview hit. For example, a page of your website may contain a button that can be clicked, a link to another website or even an embedded video that your visitors can click to play. With the standard GA implementation, these types of on-site interactions are not recorded, however with the proper setup of Event Tracking these types of actions can be collected and sent to your Google Analytics reports.
One of the most streamlined ways to set up Event Tracking is via Google Tag Manager (GTM). Today we are going to walk through setting up outbound link clicks. Knowing exactly where visitors exit your site from can be equally as important as knowing where they enter your site from. Outbound links are any of the links you’ve placed on your site that take the user off of your domain and to another website entirely. By default Google Analytics does not track this type of activity automatically, so we will walk through how to properly set this up in GTM.
From here on, we are going to assume you have already installed the GTM container snippet on every page of your website. If you have not already installed the Google Tag Manager container, this article can help you with the setup process: https://www.morevisibility.com/blogs/analytics/how-to-add-the-gtm-container-snippet-correctly.html
Ok, so the GTM container is on the site and we are ready to track how many times the outbound links of our site are getting clicked. The first thing to do is open a New Tag and choose product type as Google Analytics.
Select tag type as Universal Analytics (as this is the latest version of the GATC and what you should be running) and then hit continue. Next, you will be prompted to enter your Tracking ID for the Google Analytics property you wish to send the outbound link hits into. For the next section, Track Type, expand the drop-down and select the option for “Event”, this will generate 5 new fields for you to fill in.
Now, up until this point in the setup, everyone will follow the same process. When it comes to filling in the event tracking parameters this is where you will have some flexibility to enter the Category, Action and Label. These are the parameters that will appear in the Google Analytics report so make sure they are intuitive and make sense. You do not have to use the same settings that we use, but feel free to if you like.
• Category = Outbound Links
• Action = Link Clicked
• Label = {{Click URL}}
The {{Click URL}} is a system-defined variable in GTM that allows you to dynamically collect the URL being clicked, regardless of which one it is (this is great when your site has multiple outbound links, so you don’t have to re-do this process multiple times. Using dynamic variables like this is a huge time saver!) For the most part, the next two fields can be left as they are, Value is for when you want to assign a monetary amount to your event and Non-Interaction Hit impacts the way your Bounce Rate is defined. Choose Continue to move on to the next step. In order to set up our Trigger, which defines when we want our Outbound Link Tag to fire, we are actually going to take a slight detour and navigate over to the Variables section of the GTM interface.
Our outbound link tag is going to be triggered any time a link on our site has a domain name that does not equal our websites domain. In order to do this, best practice is to build out an Auto-Event Variable, navigate to Variables and select New under the User-Defined Variables section. Select Auto-Event Variable from the options, under Variable type select Element URL from the drop down and select Host Name from the drop down under Component Type. From here name your Auto-Event, something clear and intuitive, “Click URL Hostname” is what we generally use.
Now that this is complete we can hop back over to our Tag and create our Trigger which is responsible for defining when the tag should be fired. Expand the Fire On section and select the trigger type as Click.
Select “New” from the pop-up window and under the Configure Trigger section change the target from All Elements to Just Links (since we only want our trigger to fire on link clicks). The next step, Fire On, is where we define the parameters that will fire the tag. We are going to build out a single rule that states when the Click URL Hostname + does not contain + YourDomain.com then fire the Outbound Link Click tag. To do this, in the first drop down look for the new Auto-Event variable we just created and select “Click URL Hostname” (or whatever name you gave it). Then we can change the operator to “does not contain” and finally you need to input your website’s hostname in the last field. Save the trigger and then save your newly built tag!
Best practice is always to Preview your tags before publishing them so you can QA your setup and make sure everything is working as intended. Once this is done, your tag and trigger should now be properly configured to fire an event into your GA reports any time a link on your site is clicked that does not contain your website’s domain name.