Last active
March 23, 2018 17:49
-
-
Save djrosenbaum/320d458dba0bfd8820e6e801634892aa to your computer and use it in GitHub Desktop.
Detect Bad Requests network errors sent to DFP
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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