Search code examples
google-analyticsevent-tracking

GA event tracking mousewheel URL clicks


I have a webshop and would like to track when customers click-out on an URL (which refers to another website). I can only track these click-outs when people open the URL with a left click. If for instance, someone opens the link with a new page i.e. mouse wheel button click, then GA does not fire an event, thus no URL click is registered. As you can see the data for URL clicks is off since mouse-wheel interaction / right click actions are not monitored. Is there a way to monitor URL clicks which are opened in a new page?


Solution

  • The default mousedown event fires for all three mouse clicks in base JavaScript (and the on.click event in jQuery). The below code should fire for any click.

    document.getElementById("foo").onmousedown = function(event) {
      // Send GA Event
      ga('send', 'event', {
        'eventCategory': 'Category',
        'eventAction': 'Action',
        'eventLabel': 'Label'
      });
    };
    

    Here is a fiddle with this tracking all three mouse clicks separately: https://jsfiddle.net/doctaj/fn0L2tbz/