Search code examples
google-tag-managerevent-tracking

Obtain Click information before page changes in Google tag manager


For doing event tracking, I am using the Click variables from Google tag manager to check which ID/Text I should use to create as a trigger. I set GTM into preview mode and then go to my website to capture the gtm.click stage and see in there what the Click ID is.

enter image description here

However, when I want to track the Click ID being taken from a link that changes the page, I lose the data in the preview of GTM as a new page is loaded. Does anyone know how can I either keep this information or specifically stop the page switch once the gtm.click event is registered in the preview?


Solution

  • There are a couple of workarounds:

    1) The solution mentioned by @Eike Pierstorff for Mac. In Chrome on Windows, you can hold Ctrl and click the link

    2) Open developer console in your browser and execute this code:

    var a = document.getElementsByTagName('a');
    for (var i = 0; i < a.length; i++) {
        a[i].setAttribute('target', '_blank'); 
    }
    

    This code will set modify all links with target=_blank attribute. Then you can just click on links normally