JavaScript How can you remove or block event listeners from third party JavaScript tracking & analytics?

I run an e-commerce website and we have various third-party JavaScript that add click handlers to links and forms and then insert a delay to make sure the tracking goes through. The delay is inserted by burning CPU and running a for or while loop until a certain date is passed either 350 ms later (Marketo / Munchkin) or 500ms for Visual Website Optimizer. Combined this is almost 1 second!

Sometimes, maybe the delay is nice so tracking can be more reliable. However, we don't want this to happen when you click most links on our site because it adds up to 1 second of delay for the user. With that big a delay, there goes all the other performance optimizations we've done!

Unfortunately, we need a lot of the functionality of these scripts (like Visual Website Optimizer and Marketo) so we can't remove them.

Is it possible to remove the handlers they've added or prevent them from firing, given that I don't have references to them?

Answer:1

You can use unbind to remove events.

If you need know the event name or type, you can see with Chrome Dev Tools

Another method is capture the event and stop the propagation.

EDIT: If the event if not launched with jQuery, you can use removeEventListener or set null the property event.

Answer:2

You cannot remove the event listener without the reference to the handler function, but what you can do do is to clone the element.

var elements = document.getElementsByTagName('a');
for(var i =0 ; i < elements.length; i++){
    var cloned = elements[i].cloneNode(true);
    elements[i].parentNode.replaceChild(cloned, elements[i])
}
Answer:3

Well an alternative workaround might be to change the setTimeout functionality to work without or with smaller delay

window.oldSetTimeout = window.setTimeout;
window.setTimeout = function(func, delay) {
   //change the delay value here
   return window.oldSetTimeout(function() {
       func();
   }, delay);
};
Answer:4

I'm trying to write a solution to a problem that requires three possible different return values depending on the result of two values. The possibilities are greater than, less than, or equal to. An ...

I'm trying to write a solution to a problem that requires three possible different return values depending on the result of two values. The possibilities are greater than, less than, or equal to. An ...

I want to build my website using Javascript for front end and PHP for backend. I want to know how can I keep header & footer same on all pages if I am using javascript for client side. I can do it ...

I want to build my website using Javascript for front end and PHP for backend. I want to know how can I keep header & footer same on all pages if I am using javascript for client side. I can do it ...

  1. freeze header footer
  2. keep header and footer on first page only
  3. keep header and footer on all pages in word
  4. keep header remove footer
  5. excel remove header keep footer
  6. word remove header keep footer

response is JSON Edge: sometimes inserts response property value into DOM briefly then removes it, sometimes logs error "SCRIPT5: access denied" (indicating CORS), response fully accessible from ...

response is JSON Edge: sometimes inserts response property value into DOM briefly then removes it, sometimes logs error "SCRIPT5: access denied" (indicating CORS), response fully accessible from ...

  1. xmlhttprequest access response

I am making a digital clock. I made a button and this button changes clock's format(between AM/PM System and 24 hours system). But the problem is when i switch Intervals, both intervals working at the ...

I am making a digital clock. I made a button and this button changes clock's format(between AM/PM System and 24 hours system). But the problem is when i switch Intervals, both intervals working at the ...