I'm working to trigger Google Analytics using GTM only if page contains specific image name. For which I used User-Defined Variable as mll_banner and used custom javascript in it. And my custom javascript is as below.
function () {
var mllBanner = document.querySelectorAll('[class="p-panel p-p-b-lg position-left-top style-repeatx"]')[0].style.backgroundImage;
if (mllBanner === "url(\"/clientimg/schneider-electric/LOResource/a23d051e-55ca-4b40-88a7-90c8768e167d_coverImage.png\")") {
alert("Return is True");
return true;
}
else {
alert("Return is False");
return false;
}
}
If I run the above code as general JS with proper JS function name it works on browser console and return true as value. Where as I'm trying to use it in GTM and want to verify it for trigger I used like below,
Trigger
And this is neither triggering for true nor for false but if I make it like doesn't equal to then it triggers for both.
Can anyone please help how to use Javascript for User-Defined Variables in GTM and use that Variable for trigger? Thank you in advance!
