3

Google AdWords gives you the possibility to track incoming phone calls from your website. You can do that by implementing javascript code on your website that dynamically changes your phone number for google's forwarding number.

Problem with their code snippets is that they require you to either have you number in {span} tag with their class, or have certain id (which means only one occurence). I have responsive website with 3 phone number occurences, all of them {a href}'s - 2 with number anchor, 1 with "Call us" anchor. Could any of you tell me how to change their code so that it swapped every single occurence of my number on a website? I don't know javascript at all but know it's possible as other call tracking companies can do it (ie. callrail).

Google code snippets - in Part III

jukooz
  • 75
  • 1
  • 1
  • 8

1 Answers1

0

Use the callback option in the code:

_googWcmGet(function(formattedNumber, rawNumber) {
  // put `formattedNumber` in the right elements.
  // for example, to change a link:
  [].forEach.call(document.getElementsByClassName('your class'),
    function(el) {
      el.href = 'tel:' + rawNumber;
      el.textContent = el.innerText = formattedNumber;
      // use the above line to make the link’s text be the phone number.
      // If you don’t want that behavior, delete the line.
  });
  // and replace `your class` with the class you want.
}, 'your number', {
  timeout: 1000, // optional; how long before giving up and
                //    never calling the above function
  cache: false // optional; set to disable saving the number in a cookie.    
});

Note that you need to put this after the code that they have you copy-paste in.

Jed Fox
  • 2,979
  • 5
  • 28
  • 38