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:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
<script> if(typeof({{cookieGoogleAdwordsReferral}}) != "undefined") //When the cookieGoogleAdwordsReferral cookie variable is set { function changePhoneNumber() { var index; var a = document.getElementsByTagName("a"); //Find al links on the page for(index = 0; index < a.length; ++index) //For each link on the page { hrefLink = a[index].href; //Check if the link is a phone call link (tel:) hrefScheme = hrefLink.substring(0,4); if(hrefScheme == "tel:") //When the first 4 characters are tel: { a[index].innerHTML= "0611111111"; //Change <a href="0612345678">0612345678</a> to <a href="0612345678">0611111111</a> a[index].href= "tel:0611111111"; //Change <a href="tel:0612345678">0611111111</a> to <a href="tel:0611111111">0611111111</a> } } } output = changePhoneNumber(); } </script> |
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:
1 2 3 4 5 6 7 8 |
<script> var d = new Date(); d.setTime(d.getTime()+2592000000); //30 days expiration time (in milliseconds) var expires = "expires="+d.toUTCString(); //Convert milliseconds to UTC string document.cookie = "cookieGoogleAdwordsReferral=1; "+expires+"; path=/"; //Set cookie with name cookieGoogleAdwordsReferral </script> |
This looks like this:
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.
The allready created changePhonenumber tag uses this cookie to check if it have to change with this code: (line 3)
1 |
if(typeof({{cookieGoogleAdwordsReferral}}) != "undefined") |
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!
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 .
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?
Yes replacing an email address is possible too!
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?
Thanks!
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.
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!