I'm using a third party script (Adobe DTM, useful to tag management purposes) on my pages, and it is causing the following problem:
I noticed that my pages are being reloaded right after being fully loaded for the first time (in the next load, it doesn't occur anymore), and the blame is on this function, present at one of the scripts loaded by the DTM tag in my HTML.
function Ne(Oe, Gc, nc, Ic) {
if (Oe.targetJSLoaded) {
return;
}
Ic.setCookie(Gc, true, nc);
window.location.reload(); //in the first page load, this line is always executed
}
It's pretty hard to figure out what is going on the script, once it has more than 5000 lines and it's obfuscated.
I need to prevent that window.location.reload() from being executed, but i have the following problems:
I've tried something with the following jQuery code, but it doesn't work:
$(window).bind("beforeunload",function(e){
e.preventDefault();
});
Is there a form to prevent that programatic reload, considering the situations described?
The key is Oe.targetJSLoaded. Find out what Oe is. Try following the call stack starting from the Ne function.
For example, the code from Harbor Freight is similar to yours:
TNT.a.ge = function (he, ie, Tb, nc, Ub) {
if (!ie.targetJSLoaded) {
Ub.setCookie(Tb, true, nc);
he.location.reload();
}
};
In your function and Harbor Freight's function, we want targetJSLoaded to be true.
Looking around, we find that TNT.a.ge is called by TNT.a.je, which is called by an anonymous function like so:
TNT.a.je(window, document, b, H, Ub);
In TNT.a.je, we deduce that ie.targetJSLoaded refers to window._AT.targetJSLoaded.
Define properties to override window._AT.targetJSLoaded to be true:
function overrideTargetJsLoaded(_AT) {
Object.defineProperty(_AT, "targetJSLoaded", {
value: true,
enumerable: true,
configurable: true
});
return _AT;
}
function override_AT() {
let _AT = overrideTargetJsLoaded({});
Object.defineProperty(window, "_AT", {
get: function get_AT() {
return _AT;
},
set: function set_AT(object) {
_AT = overrideTargetJsLoaded(object);
},
enumerable: true,
configurable: true
});
}
Now, you need to override the targetJSLoaded before any other script is executed, so you put the script, which calls the override_AT function, before all other scripts on the webpage.
Unfortunately your only solution is to modify the script and then replace the DTM tag so that it points to your own version (likely breaking it in the process), or simply stop using Adobe DTM. Any tracking that requires the page to be reloaded to work isn't very well designed.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With