I am trying to fire conversion event if the iframe src changes as follows:
var src = document.getElementById("iframeID").src; // get the src
var url = "https://example.com/?123"
if(src.indexOf(url) !=-1){ //this will return -1 if false
document.getElementById("myid").innerHTML = "<script>gtag('event', 'conversion', {'send_to': 'AW-xyz/xyz'});<\/script>";
}else{
alert("wrong url");
}
and then
<div id="myid"></div>
All good and the script gets added to the div tag but the conversion is not firing the conversion in tag assistant.
I have also initially tried to fire the code without script like this:
var src = document.getElementById("iframeID").src; // get the src
var url = "https://example.com/?123"
if(src.indexOf(url) !=-1){ //this will return -1 if false
gtag('event', 'conversion', {'send_to': 'AW-xyz/xyz'});
}else{
alert("wrong url");
}
But I would get gtag is not defined
What am i missing?