Skip to content

Instantly share code, notes, and snippets.

@coffee-mug
Created October 10, 2019 13:10
Show Gist options
  • Save coffee-mug/81b0e7c3f301a2333374a64916963354 to your computer and use it in GitHub Desktop.
Save coffee-mug/81b0e7c3f301a2333374a64916963354 to your computer and use it in GitHub Desktop.
Find Pageload/Direct Call DTM rule name throguh js file id
var exists = (collection, property) => collection[property] && collection[property].length > 0;
var debugMode = true
// rule Finder - Find the name of a _satellite direct call rules by script id
// TODO:
// - Refactor
// - Make it recursive
// USAGE:
// _satellite.directCallRules.filter(rule => check(rule, 'satellite-5b17df3764746d22d100349b.js'))
// also works with pageLoadRules
// _satellite.directCallRules.filter(rule => check(rule, 'satellite-5b17df3764746d22d100349b.js'))
function check(dc, otherDc) {
var result;
if (exists(dc, "trigger")) {
dc.trigger.map(trigger => {
if (exists(trigger, "arguments")) {
trigger.arguments.map(arg => {
if (exists(arg, "scripts")) {
arg.scripts.map(script => {
if (exists(script, "src")) {
if (debugMode) {
console.log("checking rule", script.src, otherDc)
}
if (script.src.trim() === otherDc.trim()) {
console.log(`Found a match, rule name: ${dc.name}`)
result = dc.name
}
}
})
}
})
}
})
}
return result
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment