9ae3838a15f502274e50073853baeeed95be6173 max Thu Aug 19 05:47:52 2021 -0700 fixing GA button tracking not working on FF <= 78 (at least), refs diff --git src/hg/js/utils.js src/hg/js/utils.js index aed7558..cf33c34 100644 --- src/hg/js/utils.js +++ src/hg/js/utils.js @@ -6,43 +6,52 @@ /* jshint -W014 */ var debug = false; // Google Analytics helper functions to send events, see src/hg/lib/googleAnalytics.c function gaOnButtonClick(ev) { /* user clicked a button: send event to GA, then execute the old handler */ var button = ev.currentTarget; var buttonName = button.name; if (buttonName==="") buttonName = button.id; if (buttonName==="") buttonName = button.value; + // add the original label, makes logs a lot easier to read + buttonName = button.value + " / "+buttonName; ga('send', 'event', 'buttonClick', buttonName); if (button.oldOnClick) // most buttons did not have an onclick function at all (the default click is a listener) + { button.oldOnClick(ev); } +} function gaTrackButtons() { /* replace the click handler on all buttons with one the sends a GA event first, then handles the click */ if (!window.ga || ga.loaded) // When using an Adblocker, the ga object does not exist return; var buttons = document.querySelectorAll('input[type=submit],input[type=button]'); + var isFF = theClient.isFirefox(); for (var i = 0; i < buttons.length; i++) { var b = buttons[i]; + // some old Firefox versions <= 78 do not allow submit buttons to also send AJAX requests + // so Zoom/Move buttons are skipped in FF (even though newer versions allow it again, certainly FF >= 90) + if (isFF && b.name.match(/\.out|\.in|\.left|\.right/)) + continue; b.oldOnClick = b.onclick; b.onclick = gaOnButtonClick; // addEventHandler would not work here, the default click stops propagation. } } // end Google Analytics helper functions function clickIt(obj,state,force) { // calls click() for an object, and click();click() if force if (obj.checked !== state) { obj.click(); } else if (force) { obj.click(); obj.click(); //force onclick event }