58bdb6ef0be1f4f9f45157aa3b2c544ca1a92e57 max Tue Jul 6 05:33:19 2021 -0700 adding button click tracking to hgTracks, refs #27283 diff --git src/hg/js/utils.js src/hg/js/utils.js index 93f3c56..47ddf0c 100644 --- src/hg/js/utils.js +++ src/hg/js/utils.js @@ -1,24 +1,48 @@ // Utility JavaScript // "use strict"; // Don't complain about line break before '||' etc: /* 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; + ga('send', 'event', 'buttonClick', buttonName); + 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]'); + for (var i = 0; i < buttons.length; i++) { + var b = buttons[i]; + 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 } } function setCheckBoxesWithPrefix(obj, prefix, state) { // Set all checkboxes with given prefix to state boolean var list = inputArrayThatMatches("checkbox","id",prefix,""); for (var i=0;i