Skip to content

Instantly share code, notes, and snippets.

@kdzwinel
Last active March 22, 2018 09:01
Show Gist options
  • Save kdzwinel/3484ff354440ea4df82ff40bdd90a3ff to your computer and use it in GitHub Desktop.
Save kdzwinel/3484ff354440ea4df82ff40bdd90a3ff to your computer and use it in GitHub Desktop.
TrackJS custom onError callback that tries to filter out noise from ads
// 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