AdWords
6.4K members online now
6.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

Change multiple phone numbers to one in google adwords call tracking?

[ Edited ]
H
Visitor ✭ ✭ ✭
# 1
H
Visitor ✭ ✭ ✭

I am trying to set up Google Adwords Website Call Tracking. Google only supports one tracking number. This is a problem because I have three contact numbers (local, freephone, mobile).

I would like to set it up so that when traffic comes in from organic, direct or referral, all three numbers are displayed, but when traffic comes in from adwords ONLY the tracking phone number is displayed.

This is my current code (credit goes to Tomasz_C) :

 

<script type="text/javascript">
    (function(a, e, c, f, g, b, d) {
        var h = {
            ak: "9999999999",
            cl: "rrrrrrrrrrrrrrrrrrr"
        };
        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");
</script>

<script type="text/javascript">
    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>

<body onload="_googWcmGet(replacePhone, '0121-111-1111')">

<a href="tel:01211111111" class='trackPhone'>0121-111-1111</a>

 

This will replace any phone number with a class of "trackPhone" to the google tracking number. I was wondering if it would be possible to have it replace a whole div?

So:

If traffic is from adwords - show div containing ONLY the google tracking number


If traffic is from other source - show div containing all 3 different numbers (local, freephone, mobile).

Any help is greatly appreciated!

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

Re: Change multiple phone numbers to one in google adwords call tracki

Top Contributor
# 2
Top Contributor

Hi,

You can use a simple javascript solution to show/hide the divs based on the URL.

When the URL is tagged with "utm_medium=cpc" the div with the tracking number is displayed, otherwise the div with the other three numbers.

 

Spoiler
<!DOCTYPE HTML>
<html>
<head>
<script type="text/javascript">
(function(a, e, c, f, g, b, d) {
var h = {
ak: "9999999999",
cl: "rrrrrrrrrrrrrrrrrrr"
};
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");
</script>

<script type="text/javascript">
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>
<script>
function toggleDivs() {
if (/cpc/.test(window.location.href)) {
document.getElementById('trackNr').style.display = 'block';
document.getElementById('otherNr').style.display = 'none';
}
}
</script>
<style>
#trackNr { display:none; }
</style>
</head>

<body onload="_googWcmGet(replacePhone, '0121-111-1111');toggleDivs();">

<div id="trackNr">
<a href="tel:01211111111" class='trackPhone'>0121-111-1111</a>
</div>

<div id="otherNr">
<a href="tel:01212222222">0121-222-2222</a><br>
<a href="tel:01212222222">0121-333-3333</a><br>
<a href="tel:01212222222">0121-444-4444</a>
</div>
</body>
</html>

 

Hope this helps.


Arnold Majlath, Google Analytics Top Contributor
Circle Me On Google+ | Visit me @ Redfly Digital