Track calls from Google Adwords or other sources with GTM

There are severall tools on the internet that gives you the possibility to track phone calls from visitors that are entered via Google Adwords or other channels. The disadvantage is that they are generally not free. You could use the Google Tag manager to serve a different phone number to vistors from a specific source. Each call made to this phone number is dirived from Google Adwords. With this technique you could manually track Adwords phone calls.

The way we could fix this is, is editing all the phonenumbers on your site. We will replace them with a new phonenumber. It is necessary that each phone number has the tel: prefix in the href attribute. For example: <a href="tel:0612345678">0612345678</a>.

First create a new Custom Html tag and support document.write.


The code:

We have to trigger this tag on every page, so choose All pages as trigger. A cookie will check if we have to change our phone numbers.

If the visitor has Google Adwords as origin. We could save their origin in a cookie. The given example checks if the cookie is set. The value between the {{ and }} is the name of the cookie variable that saves if the user have clicked on an Adwords ad.

If an user has Google Adwords as origin we have to set our cookie. Google Adwords gives your Ad url an additional parameter called gclid. If this parameter is in the url, the referral is Google Adwords.

Create a Trigger when the Page URL contains the gclid parameter.


We are going to use this trigger to set our cookie.

Create a new Custom HTML tag with this code:

This looks like this:

setCookie Adwords referral

I have chosen 30 days as time expiration period. You could chose your own length. The desired format is in milliseconds.

Choose isGoogleAdwordsReferrer as trigger.

setCookie Adwords referral2

The allready created changePhonenumber tag uses this cookie to check if it have to change with this code: (line 3)

To read out the cookie value in GTM we have to create a 1st Party Cookie variable. The name of the variabele has to be the same as the name between the {{ and }}. At step 2 we have to enter the name of the cookie.


Next step is testing. Change te value of the cookie manually with this extension, to check if the phonenumbers on each page are changing. Also important to test is if the cookie is set after a Google Adwords referral.

If you need different phone numbers, you can try Voip Analytics. I have good experiences with this provider!

Was it interesting? Share it, so someone else can read this too!Share on FacebookShare on Google+Tweet about this on TwitterShare on LinkedIn

6 thoughts on “Track calls from Google Adwords or other sources with GTM”

  1. I just want to say that I like your posting. In fact I am using your site regularly. Your articles are very effective and i am very thankful to you for sharing this site with knowledgeable content .

  2. Very good tutorials.

    I have managed to change phone number according to adwords.

    Can this apply to change email address on the website according to different traffic source?

  3. Hi!
    Great post.
    I have one question: this is working for me, but only when I refresh the page. I mean, the cookie is working, but the telephones and emails only get replaced once I refresh the page. Do you know why could this be happenning?


    1. Think I solved it. It was because the tags fired in the incorrect order.
      Hint for those with the same problem: using Tag Sequencing won’t help you with this problem because it overrides the triggers. Just use the normal tag priorities in GTM.

  4. Hi!
    thanks for great post.

    but when i publish. changephonenumber tag is error
    My google tag manager return this: line 5
    “functions can only be declared at top level or immediately within another function in ES5 strict mode”

    my code is:

    if(typeof({{cookieGoogleAdwordsReferral}}) != “undefined”)
    function changePhoneNumber()
    var index;
    var a = document.getElementsByTagName(“a”);

    for(index = 0; index < a.length; ++index)
    hrefLink = a[index].href;
    hrefScheme = hrefLink.substring(0,4);

    if(hrefScheme == "tel:")
    a[index].innerHTML= "0611111111";
    a[index].href= "tel:0611111111";

    output = changePhoneNumber();

    pls help!
    many thanks!

Leave a Reply

Your e-mail address will not be published. Required fields are marked *