0

I have a script I wrote to track conversions for Google Ads, and I've written it to execute whenever a specific href is clicked. For some reason though, when I click the link with any button, it just treats it as a left mouse click.

Some other users who have visited the site for the first time claim that it's working as intended, but that's not the case for me or anyone else on my team.

Here is the script below:

jQuery(document).ready(function ($) {
    $("[href='https://website.com']").on("mousedown", function () {
        console.log("The JS is working");
        return gtag_report_conversion('https://website.com');
        });
    });
Mance Rah
  • 111
  • 9
  • It is not defaulting, it just triggers for any button. You have to detect the button inside the callback. See https://stackoverflow.com/questions/9521519/how-can-i-detect-a-rightmouse-button-event-on-mousedown – elclanrs Mar 30 '21 at 20:39
  • Your code is working correctly. An event is fired when a mouse button is pressed on the element. If you want it to work only when the link is clicked (by mouse or keyboard) change it to a "click" event instead of a "mousedown" event. – Gil Mar 30 '21 at 21:21

1 Answers1

0

So it turns out that the return part automatically launches the website URL and so there's no easy way to track conversions for middle and right clicks.

I spoke with my manager and he said it was fine to just track left clicks, and so I followed @Gil's advice and changed the "mousedown" to a "click".

Mance Rah
  • 111
  • 9