Last active
March 22, 2018 09:01
-
-
Save kdzwinel/3484ff354440ea4df82ff40bdd90a3ff to your computer and use it in GitHub Desktop.
TrackJS custom onError callback that tries to filter out noise from ads
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
// ES5 for compat | |
window._trackJs.onError = function(error) { | |
try { | |
var fileURL = new URL(error.file); | |
if (fileURL) { | |
// safelist includes current domain + some third-parties we want to track | |
var safe = domainSafelist.some(function (domain) { | |
return fileURL.host.endsWith(domain); | |
}); | |
if (!safe) { | |
// block | |
return false; | |
} | |
} | |
} catch(e) { | |
// if somethings goes wrong, don't block the request | |
} | |
return true; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment