_googWcmGet callback does not work through GTM with dynamic phone number

I am trying to set up Adwords conversion tracking on my site using GTM. Everything is set up on the Adwords side (call extensions + website call), but the replace function still doesn't work.

<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 () returns the correct replacement phone number (format: 123-456-7890), but replaceNumber is never called. It looks something like in the example, except that the phone number is retrieved by the function, and not provided statically.

Why is the name replaceNumber not called?

+5
source share
1 answer

As it turned out, the callback is only performed if the visitor came from an Adwords ad, that is, you need to create a paid click to check.

In the documentation you can track the tracking:

"causes people to do from your site after clicking on your ad ..."

It is subtle, but it is. To check, you need to click on your own Adwords ad. Then save the url (with tags, etc.), to subsequently use the same url to continue testing without generating more fees per click. You may not even need to click an ad if you know what a URL is.

EDIT: The comment below from @dorian is so useful that I include it here for visibility, but please give it the top too.

It is probably a bit late, but there is an extremely useful debugging mode that you can activate by adding # google-wcc-debug to the URL of the page on which you activated call tracking. Unfortunately, this debugging mode is apparently not documented anywhere.

+10
source

Source: https://habr.com/ru/post/1209714/


All Articles