Search code examples
javascriptgoogle-tag-manager

Tracking multiple clicks on the same element


Looking for a way to track if an element has been clicked multiple times (for example, a user clicks "Submit" button several times to place an order).

We are doing some work redeveloping a website and in our UX research we found that people don't download PDFs from the site because the link behind the button is broken. We noticed that people tend to click the button several times before giving up, yet some still manage to download the PDF.

In order to show our changes to code have improved site performance and user experiences, we want to show that these "multiple clicks" have decreased.

Since the site uses Google Analytics, I have tried to create a variable in GTM that counts clicks on the same click element (which doesn't work):

function() {
var the_div = {{Click Element}};
var clickCount = 0;                      
return clickCount;                      
}

I expect the output to be a count of the times I've clicked on the Click Element (1, 2, 3, etc....)


Solution

  • sorry for the delay in responding. We found a solution.

    As Piertstorff pointed out, the variable sets clickCount to zero every time it is called. The solution, was to build a custom HTML tag (that runs JS) - not a variable - that fires on a Page Load Trigger and listens for multiple clicks within a 2-second timeframe. The HTML tag then passes an event to the DataLayer and stored in a variable.

    That variable (signalling multiple clicks occurred) activates a trigger for another tag that passes the {{Click Classes}} variable to GA