Google Tag Manager Doesn’t Track Right-Clicks, Here’s a Way to Track It

person holding apple magic mouse

Did you know Google Tag Manager doesn’t track right-clicks? If it matters for your content type, here’s how to track it.

Google Tag Manager’s built-in Click trigger doesn’t track right-clicks. In many cases, it might not be a big deal. But some content types encourage right-clicks. The reader might want to open an interesting link in a new tab to be read later, while continue reading the original article. In these cases, not tracking right-clicks might portrait a skewed analytics picture.

To fix it, we need to use custom JavaScript. There are many use-cases and considerations, but here’s a basic implementation for sending right-click events to Google Tag Manager using the contextmenu event:

$('a').on('contextmenu', function () { if (typeof dataLayer !== 'undefined') { dataLayer.push({ 'event': 'right_click', 'linkUrl': $(this).attr('href') }); } });
Code language: JavaScript (javascript)

The code also pushes the href of the clicked link as a variable. Now, on Google Tag Manager you should use the Custom Event trigger type with Event name set to right_click.

graphical user interface, text, application, email
Capture the custom Right-Click event with Google Tag Manager Custom Event trigger type

Was the post helpful?

Leave a Reply

Your email address will not be published. Required fields are marked *

%d bloggers like this: