When I started to implement the AdWords website phone conversion script for our clients I ran into several issues. And those exist because the original script requires the client to change the HTML code in several places on his website. Every phone number on each page of the entire website needs to be wrapped into a <span> tag with a specific ID. While on some websites this might be easy because only one or two templates need to be changed there are also websites where it becomes more difficult.
Here are a few difficulties I ran into:
- The website operator is slow implementing such changes.
- The phone number needs not only to be changed on templates but across many sub pages with no central reference. (Good luck finding all phone numbers on a big site).
- More than one AdWords account is being used to advertise for distinct parts of a website that are built on the same code base (page-1.example.com, page-2.example.com, etc.)
So I started to extend the original script with functionality that would simply read a configuration and change all phone numbers on the website dynamically without having to change the HTML code. The idea was to insert the script in the <head> section of every page of the entire website. Most websites allow this by editing one template and the job is done.
But I ran into one more issue. Changing the text on a website with JavaScript can render other scripts inoperable if not done right. But I figured it out!
The result is a script that can be inserted into the <head> section of a website. It doesn’t slow down the rendering of the page and it changes the phone numbers dynamically, everywhere.
I especially like about this solution that the script can be implemented with Google Tag Manager. It is deployed very fast and several scripts for different parts of a website can be used very easily.
Does this solution have any downsides?
Yes, but not big ones. In the current version the matching and replacement will only work if the phone number is written in exactly the same format everywhere. The script will not work if the phone number is written +1 (22) 33 44 55 in one part and +1 22 33 44 55 in another part of the website.
And there is one bonus. The script works with clickable phone numbers too (those which are wrapped into an <a> tag).
Without further ado, go and grab the script in the following section.