AdWords
2.4K members online now
2.4K members online now
Use AdWords conversion tracking and reporting to measure your results. Have a question about Google Analytics? Post it here, on the Google Analytics Community!
Guide Me
star_border
Reply

Website Call Tracking - Multiple Numbers

H
Visitor ✭ ✭ ✭
# 1
H
Visitor ✭ ✭ ✭

I'm having a problem getting website call tracking working.

 

I have multiple instances of the same number on a page, but google's example code uses ID, not class:

 

<a href="tel:18001234567" id="number_link">
				1-800-123-4567</a>

 

How can I code it so that it changes all instances of my phone number to the tracking phone number?

 

Any help is appreciated! 

1 Expert replyverified_user

Re: Website Call Tracking - Multiple Numbers

Top Contributor
# 2
Top Contributor

Hello,

 

Can you clarify whether you are referring to tracking multiple website call tracking using Google forwarding number here?

 

I am not a tech savvy person but as far as I know, Website call tracking (https://support.google.com/adwords/answer/6095883?hl=en) is helpful when you want to implement it for a single business number which gets replaced with Google forwarding number, so that you are measure the keyword level data and take informed decisions.

 

Pankaj

Marked as Best Answer.
Solution
Accepted by topic author H
September 2015

Re: Website Call Tracking - Multiple Numbers

[ Edited ]
Participant ✭ ✭ ☆
# 3
Participant ✭ ✭ ☆

You can do this by creating your own callback function which will replace all instances of the same number on page.

But first all phone numbers must have the same CSS class, for example:
<a href="tel:18001234567" class='trackPhone'>1-800-123-4567</a>

Put this JavaScript code into <head> section on your website:

<script>
var replacePhone = function(formatted_number, mobile_number) {
var elm = document.getElementsByClassName("trackPhone");
for(var i=0; i<elm.length; i++){
elm[i].href = "tel:" + mobile_number;
elm[i].innerHTML = "";
elm[i].appendChild(document.createTextNode(formatted_number));
}
};
</script>

And then call function _googWcmGet with function name as first parameter:
<body onload="_googWcmGet(replacePhone, '1-800-123-4567')">

Re: Website Call Tracking - Multiple Numbers

H
Visitor ✭ ✭ ✭
# 4
H
Visitor ✭ ✭ ✭
Thanks Tomasz, that's exactly what I needed! I really appreciate the help!

Another related question. Would it be possible to replace a whole div? For example, if a customer comes in through organic, direct or referral, I would like to show all 3 of my numbers (local, freephone and mobile), but if they come in through adwords I would like this section to be replaced with just the one tracking number.
Marked as Best Answer.
Solution
Accepted by topic author H
September 2015

Re: Website Call Tracking - Multiple Numbers

Participant ✭ ✭ ☆
# 5
Participant ✭ ✭ ☆

You can do this exaclty the same way but you must make some modification to the callback function and add same class to all div's you want to replace.

 

<script>

var replacePhone = function(formatted_number, mobile_number) {
    var elm = document.getElementsByClassName("replaceThis");
    for(var i=0; i<elm.length; i++){
        elm[i].innerHTML = "<a href='tel:"+mobile_number+"'>"+formatted_number+"</a>";
    } 
};
</script>

 

For example:

<div class='replaceThis'>content with phone numbers</div>

will be replaced to this:

<div class='replaceThis'><a href='tel:18001234567'>1-800-123-4567</a></div>

 

Re: Website Call Tracking - Multiple Numbers

[ Edited ]
H
Visitor ✭ ✭ ✭
# 6
H
Visitor ✭ ✭ ✭

Perfect! And if I wanted to test it could I just remove the tracking script and define formatted_number and mobile_number? Like this?

    <script>
      function _googWcmGet(formatted_number, mobile_number) {
        var formatted_number = '0121-111-111';
        var mobile_number = '0121111111';
      }
    </script>

Also could I change the formatted number to have spaces instead of dashes?

I asked the original question in its own thread here:

https://www.en.adwords-community.com/t5/Tracking-Reporting/Change-multiple-phone-numbers-to-one-in-g...

You can copy your answer there if you would like another accepted solution.

Thanks for all the help!

Marked as Best Answer.
Solution
Accepted by topic author H
September 2015

Re: Website Call Tracking - Multiple Numbers

[ Edited ]
Participant ✭ ✭ ☆
# 7
Participant ✭ ✭ ☆

If you want to test it open JavaScript console (ctrl + shift + j in Google Chrome) and run this command:
replace_phone('0121-111-111','0121111111');

And if you want to change dashes to spaces add this line to callback function before for loop:
formatted_number = formatted_number.replace(/-/g," ");

Re: Website Call Tracking - Multiple Numbers

Visitor ✭ ✭ ✭
# 8
Visitor ✭ ✭ ✭
Do I still put in the original google code, or remove it and put in this script only?

As well I'm using this version of the code because I want the numbers clickable

From googles site:
Example 3: Pass the Google forwarding number to a custom callback function on your mobile site

On mobile web pages with a clickable phone number, replace both the number that is displayed and the number that is called when clicked. This requires use of the callback function.

<head>
&lt;script type="text/javascript">
var callback = function(formatted_number, mobile_number) {
// formatted_number: number to display, in the same format as
// the number passed to _googWcmGet().
// (in this case, '1-800-123-4567')
// mobile_number: number formatted for use in a clickable link
// with tel:-URI (in this case, '+18001234567')
var e = document.getElementById("number_link");
e.href = "tel:" + mobile_number;
e.innerHTML = "";
e.appendChild(document.createTextNode(formatted_number));
};
&lt;/script&gt;
</head>
<body onload="_googWcmGet(callback, '1-800-123-4567')">
<a href="tel:18001234567" id="number_link">
1-800-123-4567</a>
</body>