Sunday 24 May 2020

Tracking clicks on a button which is embedded across a website

Consider the following button:

<button id=”checklist3″ type=”button” onClick=’location.href=”http://www.weplan.com/Worksheets/worksheets.pdf”‘>Download</button>


In order to track clicks on this button via GTM, follow the steps below:

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

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

Step-3: Note down the ‘id’ attribute of the button through the Google developer console (as explained earlier). If the ‘id’ attribute is missing, then ask your developer to add one.

Step-4: Navigate to Google Tag Manager and create a new trigger with following similar configurations:
Trigger Name: Check for click on the download button
Trigger Type: Click – All Elements
This trigger fires on: Some Clicks 
Fire this trigger when an Event occurs and all of these conditions are true: 
1. Page URL equals <<enter the URL of the page where the button you want to track is embedded>> 
2. Click ID equals <<enter the ID of your button element>>

Note: In GTM, if you want to track any HTML element other than a link, then you set the ‘Trigger Type’ to ‘Click All Elements’.

Step-5: Create a new tag with following similar configuration which can send clicks on the tracked button to Google Analytics as an event:
Tag Name: Send click on the button download to GA as event
Tag Type: Universal Analytics
Track Type: Event
Category: Downloads via button
Action: <<enter the name of your event action>>
Label: {{Page Path}}
Non-Interaction Hit: True
Firing Triggers: Check for click on the download button
Step-6: Preview and publish your container.

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

The whole process of tracking clicks on the button which is embedded across a website, instead of just one particular page, is similar to tracking clicks on a button, embedded on a single page.

The only difference is that, when you create the trigger, you set the ‘Page URL’ to .* so that trigger can fire on any page of your website.

For example: