Link click tracking for Google Tag Manager

 

1. Implement your Google Tag Manager container ID on your landing page. Implementation guide available here.
Alternatively, you can place the GTM global site tag in the Settings > HTML > Head section of the landing page.

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

Screen_Capture_on_2022-06-22_at_13-27-42.gif

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.

Screen_Capture_on_2022-06-22_at_13-30-26.gif

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

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

Screen_Capture_on_2022-06-22_at_13-43-04.gif

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

Screen_Capture_on_2022-06-22_at_14-33-29.gif

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.

For Some Links there are two options that can be used:

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.

Screen_Capture_on_2022-06-22_at_16-14-07.gif

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. 

Markup_2022-06-22_at_16.23.03.png

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

button_gif.gif

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. You will still need to set up (inside GTM) 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.