Skip to content

Instantly share code, notes, and snippets.

@djrosenbaum
Last active March 23, 2018 17:49
Show Gist options
  • Save djrosenbaum/320d458dba0bfd8820e6e801634892aa to your computer and use it in GitHub Desktop.
Save djrosenbaum/320d458dba0bfd8820e6e801634892aa to your computer and use it in GitHub Desktop.
Detect Bad Requests network errors sent to DFP
const open = window.XMLHttpRequest.prototype.open;
function openReplacement(method, url) {
if (url.indexOf('https://securepubads.g.doubleclick.net/gampad/ads?') > -1) {
this.onreadystatechange = function() {
if (this.readyState === 4) {
if (!this.status) {
console.log('BAD REQUEST');
}
if (url.indexOf('&trunc=1') > -1) {
console.log('AD REQUEST TOO LONG');
} else {
console.log('GOOD REQUEST');
}
}
}
}
return open.apply(this, arguments);
}
window.XMLHttpRequest.prototype.open = openReplacement;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment