How to change multiple phone numbers to one number in google adwords call tracking? (javascript)

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:

<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>

Open in new window


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!
Chris WyattAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

nap0leonCommented:
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)
It sounds like you have 4 phone numbers total and want to show either number "1" or numbers "2-4".  But I may be misunderstanding your labels and you actually only have 3 total numbers.

I propose a structure such as the following:
<div id="phoneAdwords" class="phonenr">123-456-7890</div><div id="phoneLocal" class="phonenr">123-456-7890</div><div id="phoneFreephone" class="phonenr">123-456-7890</div><div id="phoneMobile" class="phonenr">123-456-7890</div>

Open in new window


To prevent the wrong phone numbers showing up to the wrong users, in your CSS, default each of these hidden using like:
.phonenr {display:none;}

Open in new window


To make the correct numbers display on the page, you can use:
Presuming you have your adwords URLs configured to pass in a specific parameter for your tracking:
window.location.search.indexOf('yourParamHere')>-1

Open in new window


If you need to use the referring URL:
document.referrer.indexOf('google.com')>-1

Open in new window


Whichever "true" condition you decide on, show the appropriate numbers like this:
if (window.location.search.indexOf('yourParamHere')>-1) {
  $('#phoneAdwords').show();
} else {
  $('#phoneLocal, #phoneFreephone, #phoneMobile').show();
}

Open in new window

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
JavaScript

From novice to tech pro — start learning today.