Google Tag Manager 101 Part 2 - Creating A Tag
18/06/2015
In Part 1, we created a Google Tag Manager (GTM) Account and Container and created a Tag that sends a Page View to Google Analytics (GA) for all page views. At this point, GTM is giving you no extra benefit over the standard GA tracking code. So now let's create a simple Tag to record all document clicks as a page view in GA.
Why do we need to do this? Well GA only records page views for HTML pages where the GA snippet can be added. Therefore there is no way to know when documents such as PDFs, Word or Excel files are viewed on your website. For many websites, this is a major issue - for example Council websites will often have much of their data in PDF documents and their success criteria may well be based on the number of the general public viewing these documents.
With Google Tag Manager we can add a trigger to record whenever someone clicks on a link to a document and then configure a Tag to send the information to Google Analytics.
TRIGGERS AND TAGS
So what is a Tag and what is a Trigger?
A Trigger is "something that happens".
A Tag is how you record the "something that happens" and the information you send about it.
So for a click on a PDF link, we examine the link that is clicked and the Trigger will be generated if the link contains "pdf".
We will fire a Tag based on the Trigger and send the details to Google Analytics. It sounds simple and with V2 of the Google Tag Manager interface, it actually is.
But before we configure the Trigger, we need to enable some Google Tag Manager Variables
GOOGLE TAG MANAGER VARIABLES
On the Variables page of the your GTM Container, ensure that all of the options under Clicks and Forms are ticked. This will make these variables available for selection in your Triggers and Tags.
CREATING THE TRIGGER
Step 1
Give your Trigger a descriptive title (this will be important when you have many triggers) and choose the Event as Click. This is the type for any mouse click on the page except for form submissions.
Step 2
Configure the trigger. Choose Just Links as we only want to trigger on links.
You can choose to Wait for Tags for a time period to ensure that they have time to fire. From experience, this is usually not necessary but this can depend on how your website performs.
Tick "Check Validation" if you do not want this trigger available on every page. You may use this option if you have a lot of documents on your website and you are not interested in tracking all of them.
Step 3
Now we decide when to Enable the Trigger. For this example the RegEx expression ".*" actually means Enable the Trigger for every page of the website. Adjust this value if, for example, you are only interested in the documents in a certain area of the website.
Step 4
Finally we add the rule on when to Fire the Trigger. What you choose will depend on what you want to track. We use the regular expression below "docx|pdf" which means record any links that contain the string "docx" or the string "pdf". If you have more document types, you will need to change this expression - or you can use a separate Trigger for each type.
Your Trigger is now created.
CREATING THE TAG
So we now have a Trigger that will fire whenever a link to a Word document or a PDF is clicked. Now we need to define a Tag that will send information back to Google Analytics about the link that was clicked.
Step 1
Give your Tag a name - it is fine to give it an identical name to the Trigger.
Google Tag Manager can send many types of tags, select the type of Google Analytics that you have. For the Tracking ID, use the variable that you defined in Part 1. This step 1 is the same for all the GA tags that you create.
Step 2
At this point you can choose to create a Page View or an Event. If you create a Page View, it means that your documents will appear in your general content reports so I always choose this option. Under More settings, select what will be recorded for the page view.
For the page, choose the Click URL - this is the full URL of the document.
For the title, choose the Click Text - this is the text on the web page itself. This may be more useful than the Click URL - see the example below of what the Click Text is on a document link (the txt shown in green).
Step 3
Finally decide when to send the Tag. Selecting Click will display all the Triggers of type Click.
Step 4
Choose the Trigger you just created and Save your Tag
So that is it, you now have a Trigger and Tag. You can Publish your GTM Container now or Google Tag Manager has a Preview function which you can use to see whether what you have set up actually fires at the correct time.
GTM PREVIEW OPTION
Assumption
If you test via Preview, you need to be filtering the traffic from your own network out of your Google Analytics data. You don't want all of your tests ending up in the live data. It is a good idea to have a test view in GA set up with no filters which you can use to check that all of your tags fire and that the correct information is being stored.
Going into Preview Mode
Under the Publish button (right hand side of the GTM Administration screen) there is the option to Preview and Debug prior to publishing.
Once you are in Preview Mode, opening your website on another browser tab will display the GTM Preview panel underneath the page.
GTM Preview
On every page of the website, you should always see one tag fired - the tag that sends every page view to Google Analytics.
Navigate to a page that has a document link (either a PDF or DOCX) on it
Click on the link - hopefully the document opens in a new tab. Stay in the same tab and you should see your Tag firing.
Spend some time in the Preview interface and click on Variables and Data Layer to see the sort of information that is available for selection in GTM.
If everything looks good with the Preview, you are now ready to Publish your Container.
PUBLISH THE CONTAINER AND TEST
From Part 1, you will know how to Publish your Container. This will push your new Trigger and Tag into your Live website.
Go to your website and click on some documents. Go to your Test View in Google Analytics and in Real Time, you should see the page views for the documents.
WHAT NEXT?
In Part 3, we will look at creating some more tags. We will track external links from your website, build special tags to capture clicks through to your social media pages, record clicks on mailto links and track submission of forms.
If you do use this guide, please provide feedback especially if you see any errors or areas which are unclear. I will then revise the article. Send comments through on this blog, on Twitter or via Email
Written by Nick Baker