7

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?

mz3
  • 1,314
  • 11
  • 27
  • One problem might be the onload event handler - you do not actually need this, as you can tell GTM to fire the script on page load. – Eike Pierstorff Dec 22 '14 at 20:41
  • That was my initial thought as well. However, `_googWcmGet( replaceNumber, getNumber() );` is definitely firing, because anything I put in getNumber gets executed. Is that what you mean? – mz3 Dec 22 '14 at 20:52

1 Answers1

11

As it turns out, the callback only runs if the visitor came from an Adwords ad, meaning you need to generate a paid click in order to test.

From the documentation, call tracking can be used to track:

"calls people make from your website after clicking your ad ..."

It's subtle, but it's there. In order to test, you need to click on your own Adwords ad. Then, save the URL (with the tags and such) so that you can use the same URL later to continue testing without generating more click fees. Possibly you don't even need to click an ad if you know what the URL is.

EDIT: The comment below from @dorian is so helpful I'm including it here for visibility, but please give him an upvote as well.

Probably a bit late, but there's an extremely helpful debugging mode which you can activate by appending #google-wcc-debug to the URL of the page where you have activated call tracking. Unfortunately this debug mode seems to be documented nowhere.

mz3
  • 1,314
  • 11
  • 27
  • 21
    Probably a bit late, but there's an extremely helpful debugging mode which you can activate by appending `#google-wcc-debug` to the URL of the page where you have activated call tracking. Unfortunately this debug mode seems to be documented nowhere. – dorian Jan 28 '16 at 19:40
  • That is extremely helpful. How did you manage to stumble across that? – mz3 Jan 29 '16 at 20:29
  • 1
    We also had some trouble with a call tracking implementation. When nothing else seemed to help, I investigated the script which is loaded by the snippet. If you take a look at `http://www.gstatic.com/wcm/impl-1_22.js`, you'll find it. – dorian Jan 31 '16 at 17:59
  • 1
    @dorian you are my hero! – Maxamilian Demian May 16 '16 at 17:29
  • 1
    @dorian It's never too late. You made my life easier with that comment and it's almost a year later. #google-wcc-debug-forever – armadadrive Jan 21 '17 at 17:33
  • @dorian Thank you. A lot of time has passed since this question/answer was updated but your comments have been very helpful. I was mainly trying to investigate why the URL `https://www.gstatic.com/wcm/impl-1_22.js` always gives a 404 error on a website and that is how I landed on this page. It seems that now the URL for that script has changed to `https://www.gstatic.com/wcm/impl-1_31.js` but everything else (including the debugging method of appending `#google-wcc-debug` still remains the same). – Prayag Verma Mar 27 '19 at 03:21
  • 1
    @dorian it's been 6 years since you posted that, and it's still helping people :) – allanminium Aug 29 '22 at 23:27