My Christmas Present to You: Dynamic Phone Tracking Script

Published December 22, 2011 | Categories: Digital Marketing
I am going to preface this post with something that I really should not have to say: You need to be tracking your web-based inbound phone calls. If you are not aware of how many calls/leads your website is generating for you, then you have no idea of the true ROI of your website. Phone tracking is best done by creating a unique number that is available only on the website - this way you know that any calls to that specific number were generated by users who viewed the website. You do not need a call center or a huge phone plan to do this. You can get these unique numbers (along with increased tracking features like volume, caller length, and even caller ID) from great companies like IfByPhone that offer these services for very affordable rates.
For most of my clients, it is also critical to track not just volume, but volume by source. That is, how many calls came from organic, PPC, specific referrals, etc? The best way to do this is by using dynamic phone tracking. With dynamic phone tracking, different numbers are displayed to different web visitors depending on the source of each user. Some companies, like IfByPhone, offer this code as part of their services (others do not), but most have limitations as to how many numbers you can dynamically track on a page at one time. This does not work for me, as I often need to track local & 1-800 numbers for every page.
No worries, I have written a bit of JavaScript that solves this problem.
First, a few caveats:
1) You must have at least one trackable phone number available to you.
2) This script only works with tagged links. That means you have to put your parameter on the inbound link to your site.
3) This script is session based. This means that user will only see this number the first time they come the source (i.e. PPC) you want to track. If they come from a different source the next time (i.e. direct or organic), they will not see the same dynamically generated number that they did the first time.
4) This script will not work if the user goes to a page through a redirect.
Please note that items #2 thru #4 are not impossible to alter, just a little more complicated than the script I am giving you here. Feel free to contact Beacon or myself with any questions if you would like to delve deeper. If you doNow, without further ado...
Begin by placing the following JavaScript in either as a script in your HTML head or as a referenced external .js file.
var current_page = document.URL;
var sourceConfirm = current_page.indexOf("?source-track");var phone_num="XXX-XXX-XXXX";
if (paidConfirm != -1)
{
document.cookie = "Track this Source";
}
else
{
}var cookieCheck=document.cookie.indexOf("Track this Source");
if (cookieCheck != -1)
{
phone_num="YYY-YYY-YYYY";
}
else
{
}
Replace "?source-track" with whatever parameter you are using to tag the inbound link with. Replace XXX-XXX-XXXX with your default number. Replace YYY-YYY-YYYY with the variable number that you would like tracked.
Next, where you want the number to display, place:
<script>phone_num</script>
And that is it. Your default number will display for all users except for those who come to the site via the tagged link.
Merry Christmas!
- EW, follow me on twitter @ejwestksu
Recent Posts



