Created
October 10, 2019 13:10
-
-
Save coffee-mug/81b0e7c3f301a2333374a64916963354 to your computer and use it in GitHub Desktop.
Find Pageload/Direct Call DTM rule name throguh js file id
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
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