Sunday, 24 May 2020

Tracking clicks on a link via Google Tag Manager

Consider the following link on a web page:

<a id=”checklist” href=”http://www.weplan.com/Worksheets/worksheets.pdf”>Download Wedding Planning Checklist</a>

In order to track clicks on this link, follow the steps below:

Step-1: Navigate to the web page (in Google Chrome browser) which contains the link you want to track via GTM

Step-2: Note down the URL of the web page where the link is embedded.

Step-3: Right-click on the link and select ‘Inspect‘ from the drop-down menu:
You will now see the Google developer console window at the bottom of the page:
Step-4: Note down the value of the ‘id’ attribute of the anchor tag (<a>). In our case, it is ‘checklist’. You will need this ‘id’ later on while setting up triggers in GTM.

Note: If you do not find any ‘id’ attribute for the link, you want to track, then look for the unique class name. If you can’t find a unique class name then ask your developer to add the ‘ID’ attribute with a unique value. Without the ID attribute, you can’t easily track clicks on a link via GTM.

Step-5: Navigate to Google Tag Manager and create a new trigger with following similar configurations:
Trigger Name: Check for click on the download link
Trigger Type: Click – Just links 
Check Validation1. Enable this trigger when: Page URL equals <<enter the URL of the page where the link you want to track is embedded>>
2. This trigger fires on: Click ID equals <<enter the ID of your <a> element>>

Note(1):Check Validation‘ ensures that the trigger fires on a successful link click and not just when a user tries to click the link.
Note(2): ‘Page URL’ is a built-in variable of GTM which returns the URL of a web page.
Note(3): ‘Click ID’ is a built-in variable in GTM which returns the ‘id’ attribute of the link clicked.

Step-6: Create a new tag with following similar configuration which can send clicks on the tracked link to Google Analytics as an event:


Tag Name: Send click on the download link to GA as event
Tag Type: Universal Analytics
Track Type: Event
Category: Downloads via link
Action: <<enter the name of your event action>>
Label: {{Page Path}}
Non-Interaction Hit: True
Firing Triggers: Check for click on the download link
Non-Interaction Hit – Set non-interaction Hit to ‘True’, so that event tracking does not affect the bounce rate of your website.

Step-7: Preview your container to make sure that the new tag fires and it fires only when you click on the targeted link.

Step-8: If everything is working as intended then publish the new version of your container.

Step-9: Click on the link and test whether the event data is being sent to Google Analytics, via real-time reports: