I'm trying to get Adwords Call Conversion tracking working on my site, using GTM. Everything is set up on the Adwords side (call extensions + call from website conversion) but the replace function still isn't working.
<script type="text/javascript">
// the code from adwords, loads the _googWcmGet function
(function(a,e,c,f,g,b,d){var h={ak:"XXXXXXX",cl:"XXXXXXXX"};a[c]=a[c]||function(){(a[c].q=a[c].q||[]).push(arguments)};a[f]||(a[f]=h.ak);b=e.createElement(g);b.async=1;b.src="//www.gstatic.com/wcm/loader.js";d=e.getElementsByTagName(g)[0];d.parentNode.insertBefore(b,d);a._googWcmGet=function(b,d,e){a[c](2,b,h,d,null,new Date,e)}})(window,document,"_googWcmImpl","_googWcmAk","script");
// my callback to replace the number
var replaceNumber = function (formatted_number, unformatted_number) {
console.log("replaceNumber() called");
}
var getNumber = function () {
var links = document.getElementsByTagName("a");
var oldNumber = null;
for(var i=0; i<links.length; i++) {
if( links[i].href.indexOf("tel") > -1 ) {
var el = links[i];
var oldNumber = el.innerHTML.split("<")[0];
}
}
// console.log(oldNumber); -> 123-456-7890
return oldNumber;
}
window.onload = function() {
_googWcmGet( replaceNumber, getNumber() );
};
</script>
getNumber() is returning the correct phone number to replace (format: 123-456-7890), but replaceNumber is never being called. This looks pretty much exactly like the example, except that the phone number is retrieved by a function instead of provided statically.
Why isn't replaceNumber being called?