Link click tracking for Google Tag Manager

In this guide, you will learn how to track specific links on your page inside of GTM.

1. The first step is to ensure that your Google Tag Manager container ID is added to your landing page as shown here: 
Alternatively, you can place the GTM Google tag in the Settings > HTML > Head section of the landing page.

2. Create a new custom variable and use the type Custom JavaScript


3. Name the variable something descriptive, such as Instapage element-ID so that you can easily identify it. We will use this variable inside triggers in GTM.


4. Paste the following code inside the variable. Make sure that you Save after.

function () {
  if ({{Click Element}} !== '') {
    return {{Click Element}};
  else if ({{Click Element}} !== '') {
    return {{Click Element}};
  else if ({{Click Element}} !== '') {
    return {{Click Element}};
  else if ({{Click Element}} !== '')
    return {{Click Element}};


5. Now you need to create a trigger for link clicks. Click on Triggers > New and pick the type Just links as shown in the GIF below.


The trigger can be set to All Links if one needs to track any type of link or Some Links to customize which specific link on the page needs to be tracked.

Using 'Some Links'

1. Using the built-in Click URL variable from GTM, then the 'contains' operator, you can activate the trigger when a page visitor clicks on any instance of the specific URL that you include.

The event will fire regardless of what type of element or how many elements this URL is placed on in your landing page.


2. Combining the Click URL variable and the custom one we created, you can set the event to fire only when a specific instance of that URL is clicked; the one attached to the specific element ID. 


Here is how you can get the element ID of any element on your landing page by clicking on CSS style editor:


By using the second option, the event will fire only when both conditions are met: the element ID matches and the URL on that element is the one you specified.

NOTE: The instructions above show you how to create a trigger for link clicks. Inside GTM you will still need to set up the tags that you need, meaning what will actually happen when the action is triggered - what is going to be tracked and in what platform. Here is an example tag: