1-877-660-3735

Blog email subscribe

  • This field is for validation purposes and should be left unchanged.

‘Roll Your Own’ Phone Call Tracking Program – It Is Easy!

Posted by Mike Belasco on December 8th, 2009

Filed Under:

Share This Post:

So you wanna track phone calls eh? Easy enough my friend. There are some excellent call tracking platforms out in the world including IfByPhone, Mongoose Metrics, VoiceStar and more. We’ve researched a ton of them and while they all had their upsides, each had a downside as well that was hard for either seOverflow or our clients to stomach. In order to solve most of these issues, we went and developed our own phone call tracking program based on the Twilio Web Service API for phone applications. Features that were important to us that were hard to find together in a single call tracking application were:

  • affordable for most clients
  • ability to port numbers in and out
  • integration with Google Analytics for conversion tracking
  • call recording
  • email alerts when a call was made
  • showing the ‘real’ phone number in the code to help with local search
  • easy to implement
  • ability to track only non-branded organic search traffic
  • and more!

In this post we are going to show you EXACTLY how to build your own phone call tracking platform you can put in use TODAY for you or your clients. You’ll need to at least understand a teeny bit of JavaScript, PHP, XML, HTML, and Google Analytics. You’ll also need PHP and Google Analytics installed on the website for which you intend to track phone calls. For the example, we are going to build a call tracking program that tracks phone calls as a result of a non-branded organic search from one of the big three search engines (Google, Yahoo, or Bing).

Building The ‘Back End’

Step 1: Register for a Twilio account. An account with Twilio is free! Phone numbers are only $5.00 per number per month, and calls cost only 3 cents per minute for ‘local’ calls or 5 cents per minute for toll-free calls. You can start by using numbers for free from the Twilio sandbox. You also get $30.00 worth of credit for free to get started!

Register For Twilio

Step 2: Buy three ‘local’ phone numbers in your account. You can search by area code for the phone numbers you want. When you find a number you want, Twilio will request a URL to associate with this number. A default URL will be filled in. Leave this default in place for now. You should now have a table with three numbers.

Buy A Phone Call Tracking Number

Step 3: Download our phone call tracking code sample zip file here. Once the file is downloaded, open up calls/twiml.php in your favorite editor. Once the file is open, replace XXXXXXXXXX with the phone number where you would like Twilio to forward your calls. Save the file.

Replace Phone Number

Step 4: Open calls/handler.php in your favorite editor. Replace UA-XXXXXX-1 with your Google Analytics profile ID. Also replace youremail@domain.com with the email address where you wish to get notices when a call is logged including a link to the recording of the call. Save the file.

Replace GA ID

Replace Phone Number

Step 5: Upload twiml.php, handler.php, and Galavanize.php to a directory called/calls on your website.

Step: 6: Go back to Twilio. Decide which number you are going to use for Google visitors and click on the number in the table. Edit the description of the number (currently contains the number itself) to Google. Edit the URL to be http://www.yourdomain.com/calls/twiml.php?callsource=Google (replace yourdomain with the domain you are working with). Hit Save.

Edit Phone Number

Step 7: Now it is time to test and make sure the phone numbers work, forward to your phone, send an email, hit your Google Analytics account, record the call, and finally send you an email. All that in seven steps.  All you need to do to test is call the number you assigned to Google (don’t call from the phone to which you are forwarding calls). If the destination phone rang, you had a conversation, and you received an email telling you  a call from Google just came in with a link to the recording of your call, then it worked! If not, check the Debugging link in Twilio and see if your program generated an error message. It can take a couple of hours, but a page view will also show up in your Google Analytics profile for the URL/calls/Google.

Building The Front End

Now that the back end of our call tracking application is working, we need to build the logic that controls which phone number to display. Rather than reinventing the wheel and coming up with our own code to detect the referrer and other information about the visitor, let’s use what Google Analytics already knows! The code we use to read the Google Analytics cookie is based on the code written by EpikOne and published in their blog post “Integrating Google Analytics With A CRM“.

Step 1: Open displaynumbers.js in your favorite editor. Enter your phone numbers as values for the appropriate variables. Enter them formatted how you would like them displayed on your web page. Enter your ‘real’ or default phone number in the value for defaultNum. Enter a list of comma separated branded search terms for which you are not interested in tracking phone calls as the value for brandedTerms. Enter the name of the class used for the SPAN or DIV containing your phone number on your HTML page. (Hint: you may need to create SPAN element around your phone number for this. I did and named it ‘tele‘.)

JS For Call Tracking

Step 2: Paste this JS code at the footer of your HTML page, and underneath the Google Analytics tracking code snippet. Make sure and update the path to where this file will be stored.

<script type="text/javascript" src="your/path/to/displaynumbers.js"></script>
<script language="javascript">
    displayTextNumber();
</script>

Step 3: Upload displaynumbers.js to your server. Also upload the HTML file you just edited to include the JS as well.

THAT’S IT! You are all done!! Congratulations!!!! Go to a search engine, type in a non-branded term for which you rank, click the search result and you should see your designated phone number for that search engine on your web page! This JS script can also easily be configured to swap out images and images used as backgrounds of a CSS class. The JS script could also be configured to work with PPC and other referrer types as well farily easily.

I hope you enjoyed creating your own phone call tracking application and that it brings you a wealth of knowledge about your phone call conversions.

Bonus Tip: You may want to configure conversion tracking for calls/* in  Google Analytics. This way you can see as a conversion goal how many phone calls you received as a result of non-branded organic search.

About 

Mike has been honing his internet skills since the early 90s, in both corporate and start up environments. Today, Mike’s companies, Inflow and its sister company, ConversionIQ, make Search Engine and Conversion Optimization available and affordable to companies of all sizes.

Share This Post:

61 Comments on “‘Roll Your Own’ Phone Call Tracking Program – It Is Easy!


    Mike,

    Thank you for recognizing Ifbyphone as one of the excellent Call Tracking platforms out there. We’re glad to see your firm is continuing to push the call tracking envelope!

    I’d certainly be interested in hearing your thoughts on my recent blog post about “7 Phone Call Tracking Tools Every Online Marketer Must Know”: http://public.ifbyphone.com/blog/7-phone-call-tracking-tools-every-online-marketer-must-know

    Best,

    Elan
    Ifbyphone, Inc.


    Hi Mike,

    Great writeup, and thanks on behalf of the Twilio community for open sourcing the whole thing!

    Regards,

    -jeff

    Co-Founder
    Twilio.com


    Thanks for posting this “how to” for call tracking. It looks like it will be very useful to a number of our clients.
    Tom Fabian
    Frontera Interactive


    Awesome article, thanks for sharing that. It’s a pity Twilio is limited to US phone numbers – does anyone know of a similar service that works internationally?

    @Jeff – or are you planning to expand to more countries? Would love to use your service!


    Our company, CallSource, invented the call tracking industry nearly 20 years ago. These days, tracking and recording calls is easier than ever. For most businesses, though, the challenge is analyzing the data and reacting to it in a way that improves their marketing, sales, and customer service. Our business is built on metrics, but emphasizes the tools and knowledge to help clients get the financial results they are after. Your do-it-yourselfers could pick up some useful ideas for free at our Website, http://www.callsource.com.

    Thanks!

    Elliot


    I use Vonage already, so I would be more likely to use Vonage.com features, including click-to-talk and a call log. Their toll-free numbers are $4.99/month, and I imagine you would be able to see who called from what number.

    It’s nowhere near as complex an offering as Twilio, which seems very robust, but it’s simple.


      @zack That would be cool, but keep in mind this solution also records the calls, sends you an email and records a conversion in analytics. Can’t really do all that with Vonage, but basic call tracking would be possible. Still could use our front end code provided here.


    You can also do a virtual phone number to be able to receive local calls from anywhere in the world for the same cost as an 888 number.


    Hi Mike -

    I just wanted to thank you fro a great couple of sessions at the local search summit in chicago. You were one of the few presenters that were absolutely commited to “giving us something we could take home” … if only ALL presenters were as focused and committed on that goal!!

    Unfortunately, your presentation, like many I attended, was not available online. And even if it was, I’m sure it wouldn’t have included the necessary amount of detail.

    I was particularly interested in your presentation on how to track local results listings in google analytics using their new campaign URL builder. I wrote like hell to try and capture the procedure, but failed miserably.

    Is there any way you can post that procedure online or provide a link to the detailed procedure?

    It would be greatly appreciated!

    Thanks, again, and GREAT JOB.


    This is such a great resource that you are providing and you give it away for free. I love seeing websites that understand the value of providing a quality resource for free. It?s the old what goes around comes around routine.


    I love seeing these advances in call tracking! One company I know that has taken this basic technology to the next level is Phonalytics, LLC. Unique phone numbers are assigned to each marketing campaign to dynamically change the phone number, but all tracking is reviewed in an easy to use web-based interface that does not need to be integrated with Google Analytics. You can listen to all calls and run state-of-the-art speech analytics to monitor staff and customer moods, tone, enthusiasm, etc. A URL generator and reporting is built into the same interface, so everything is in one place. AND they’re giving away free 90 day trials like hot cakes. I can’t wait to see the effects dynamic call tracking has on the industry!


    Is there a way to apply variables for PPC google, msn, and yahoo. Maybe trigger it with a URL variable like “?tr=MSN”. I need to track PPC traffic and differentiate it from natural search and original phone number.


      Hi Randy,
      The best way to customize this for PPC is to add variables to your destination URLs. With that you can edit the displayNumbers JS and other functions to not only pull numbers for various PPC search engines, but different numbers on the campaign level too. This used to be expensive with Twilio however, numbers have now been reduced to $1 each per month.


    Mike, would you be able to post specifics on how to do this?

    Thanks


    Downloaded the zip file and extracted the file, but could not find the file, Galavanize.php. Please advise.

    Thanks,

    Harry


    Thanks Mike. Works great!


    Mike,

    I’m curious what drawback you found in Mongoose Metrics (except price). We’re currently using Mongoose Metrics for our clients and are extremely happy with them.

    I’ve been throwing around jacking their concept, and just using the Google analytics API for displaying the numbers, but I think it’ll be too complicated.

    There’s one thing I’d like to see before I start adding phone calls as a goal in Google analytics, and that is to get the clients browser to actually call the URL instead of having the server call the thank you page whenever a call is made.

    This can be done using one of the google analytics hacks that refreshes the javascript call every 10 seconds – http://padicode.com/blog/analytics/the-real-bounce-rate/

    If we can have it call the API (mongoose or Twilio), the clients browser can then call the URL, allowing you to pass it into Google analytics on the adwords cookie, and ultimately back to adwords as an action.

    That would be really cool and dumb for my clients ;)


      Hi David,
      Basically Mongoose’s pricing structure (buying blocks of minutes) combined with their price, combined with the fact that everytime I spoke with them they wanted to chat about PPC (most of our clients do organic) made me want to go another direction.

      Very cool idea with your API and recording the session from the user vs the server. Would you like to spend a few minutes brainstorming this sometime with me?


    Hi Mike,
    It’s funny that I returned to this article just a few months later and read it with a completely different attitude.

    I’m looking into different services, and I am definitely intrigued by the article. Thanks for providing the source code, too – I’m going to try it out.


      cool Zack, as you may have read in the comments, it is now even cheaper as numbers are only $1 each down from $5 each. Good luck, and let us know if you need help.


    Is there a way to make the analytics customizable for each twilio number. Basically if you have multiple numbers tracking different KWs with an individual number per word or group, to show up in google as different calls.

    Like if I am tracking flooring and contractors. I tried the following unsuccessfully:

    http://www.mywebsite.com/calls/twiml.php?callsource=GoogleFlooring for one number
    http://www.mywebsite.com/calls/twiml.php?callsource=GoogleContractors for another.

    Both showed as page hits to calls/0

    Any ideas?

    Thanks for the great post!

    Chris


      Chris,
      Check that your variable for source is getting passed correctly. The URL should be diffferent and is auto created from the call source. Should be no problem. Also of course when you take this live you’ll need to modify the rules in the JS so that you are changing the number based on keyword (which is available already in the code) rather than just source.


    Yea it isn’t getting passed at all. I am getting the “0″ from the $num = 0; in twiml.php

    Also, I noticed the javascript isn’t working at all in IE…I don’t use it so it took me a while to find…lol but any idea as to why?

    Thanks for the help,

    Chris


      Chris if you want you can email me your code and I will take a look, I haven’t had those problems with IE or not passing variables….. mike at seoverflow dot com


    I’m loving this tutorial I have to tell you and can’t wait to implement. I was all but giving up on the call tracking because of cost issues and then came across this. Fantastic!
    Thanks in advance Mike.


    galvanize is now at http://sourceforge.net/projects/galvanize/


    Thank you, Brad. What do you mean, please? They’re on the phone … and … ?

    (Keeping in mind that asking marketing questions while they are on the phone results in a 10%-35% chance of losing the client. They are paranoid enough, when they call. We’re a criminal defense law firm.)


    Hi Mike,
    this is an excellent post. Twilio also told me about a similar openVBX version which I have running – albeit not very well at this stage. But I will keep messing with it until it works smoothly.

    Just wondering: are you able to track down to the keyword level and actually know what keyword is resulting in a conversion? If I am bidding on a few hundred keywords for PPC could it tell me which keyword led to a phone call?


      You could in theory, but you would need a different number for each keyword, and a lot more lines of code in your JS which would slow it down tremendously.


    Hey Mike!
    Your article just save me a lot of time and headaches…
    I’m glad to have found it.
    The details you gave are perfect and they work as expected except for the email part.

    In your screenshots you show what seems to be an older version of Twilio’s interface.
    I’m not sure but right now They have the option for Post and Get when you enter the URL (step 6) of the tracked information.
    http://snapplr.com/c3w5

    In the handler.php PHP file it’s set to Post.

    Right now everything for me works except the email.
    I’ve tried different emails too…
    Would you happen to know if this php code still works with this new update in the admin of Twilio’s? Or if it would need some kind of tweaking?

    Thanks for your help and for sharing your code here…
    David


      Hi David,
      The email functionality does not have anything to do with Twilio. I would check with your hosting company.


    Mike,

    First, thanks for creating this and sharing it. Quite a resource!

    Now a question, shouldn’t Step 3 above for twiml.php also have us replace “goinflow.wpengine.com” with our domain?

    Thanks!

    Jon


      So I just made this change to the twiml.php file as mentioned above and that fixed the issue with the emails not coming through. The only other issue I was having was the goals tracking in Analytics. I think this should fix that too. I’ll have to wait a few hours though and check Analytics to be sure.


        awesome john, glad you got it working. I’ve been trying to schedule a big blog post update on a slightly modified version of this we are now using. Should be out soon!


    Mike,

    Thanks for this quite useful piece of code. Before I can implement it, however, I would like you to please answer a nagging question I have dancing in my mind. Here it goes:

    MANY LOCAL SEO experts (including you, of course) recommend consistency in the basic listing info, INCLUDING the phone number. As you wrote elsewhere, “Use only ONE phone number in all references to your business, ONLINE and OFF-LINE”

    Well, the tracking system you describe here seems to go against this advice for Local SEO by offering different numbers to same business, so the question is…

    Can someone interested in Local SEO use this system safely, or will it take away from its ranking?

    TIA!


    Cool. I look forward to seeing that!

    Also, the current version for us isn’t working for the branded keywords. It only filters out the first branded keyword in the list. For example:

    brandabc,brandxyz,brandrst

    In that scenario, it will identify the first as branded and thus use the default number, but for the second and third its treating them like non-branded organic search referrals. Any thoughts?


    FYI, I also tried with spaces and commas in addition to just commas (as the comments specify). Basically its doing this:

    if the first branded kw: doesn’t do any sub, shows the number in the code (CORRECT)

    if the second or other branded kw: subs out the number with the non-branded search number even though this is a branded kw (ERROR)

    if a non-branded kw: subs out the number with the non-branded search number (CORRECT)

    if referral: subs out the number with the “default” number (CORRECT)

    By the way I’m being way rude here too. Thanks so much for doing all the work on this and providing it at no cost. I shall be hooking you up with some links which is the least I can do :) I realize you owe us nothing here and have already provided a great value at no cost to those of us who are implementing this.


    Okay I figured it out. My keywords were 2-3 words so they had spaces in them. When you input your branded keywords into the displaynumbers.js file you need to put %20 for each space. Once I did that, it started working correctly. Makes sense to me.


    Thanks for this great resource guys. This post has really been helpful.

    I am running into a bit of a problem however with your code as the callsource is not passing through.

    I quadruple checked the code based off what you mentioned above.

    I even tried this on multiple domains, a Drupal site and a WP site, no luck.

    Both are returning 0 as the callsource.

    I actually just tried moving:

    $callsrc = $_GET['callsource'];

    from the handler.php to the twiml.php file and it seems to work now.


    I’m building basic web sites based on WordPress themes for local businesses in Canada. I’m looking for someone to make it easy for my clients to implement call tracking as described in the article above.

    I’d be willing to pay a small fee for someone who can help us implement call tracking.

    email me your name and phone if interested.

    send it to my yahoo address:

    yahoo username: jfmlists


    This is a fantastic tutorial, but for those who prefer not to roll their own system, we’ve launched CallRail (http://www.callrail.com). We offer instant phone number setup, javascript-based dynamic number insertion and Google Analytics integration. It’s priced right for small businesses and independent marketing consultants.


      very cool andy. Is this based on Twilio as well?


        Yes, CallRail is built on the Twilio platform. We may consider adding more providers down the road, but Twilio has been a robust and responsive telephony provider with an excellent inventory of available numbers.


    Great article. I’ve really been wanting to do this but BLOWN away at the cost of commercial solutions.

    If possible, could you clarify the ‘branded keyword’ part? What is that & and what is it for, exactly? … I assume it is either to restrict tracking to ‘branded’ terms or eliminate tracking on ‘branded’ terms. I can imagine people not wanting to track people who searched for the full domain name, for example. … Thanks for any mroe info you can provide.

    Also, I think it would be handy to have an additional ‘catch all’ phone number. In other words, something that would register calls if they were anything other than the main variables (google, bing, etc). Do you know a simple way to accomplish this?

    Thanks!

    Ry


      since we are an seo company we are focused on getting ‘new’ potential customers to our clients. Typically if a potential customer searches with a ‘branded’ term like a company name or key person’s name, they already know of our client and we wouldn’t want the “credit”


    How can we implement “call whisper” into this script? So, that when the call is forwarded the person answering the phone hears a quick customer greeting?

    Thanks


      check the twilio documentation. I believe this is possible.


        That is of course possible. You need to add a Play verb at the top of the script. If you want to use a pre-recorded audio or a Say verb if you want to use default twilio machine voice.

        Actually, more sophisticated calling app is possible with twilio/tropo. if you need any help feel free to ask.


    Hi, I am really interested in this, but maybe I am missing something here, how can the cookie be read in the js file if it has just been set for the first time by the google tracking script on the same page.


      just make sure the Google call happens before the call tracking JS and you should be fine


    First of all great resource Mike… Second, not sure what I may have done wrong but the call source does not show up in my emails it just says “0″ does anyone know how to correct this??? Thanks in advance for your help!


    Mike,

    This is pretty awesome. I’ve been using Voicestar (Marchex) and it gets pricey at $25 a number so this is a great solution. Thanks for this post.

    Mike


    By setting up multiple phone numbers, doesn’t this hurt your local rankings? Google Places looks for consistency in NAP (name, address, and phone number). So you need to be very careful not to diminish your ROI in those other channels that depend on a phone number being consistent.


    Hi- a dental client of mine is looking to implement this tracking strategy. Do you know if this is HIPAA compliant?

    Thanks!


    thanks to the author for taking his time on this one.


    Hello,

    It seems the file in step 3 is no longer available for download. Can you please update the link? Thank You for your time!


      Hi Joseph,
      We don’t utilize this script anymore and recommend that you check out CallRail instead. Hope that helps.

Leave Your Comment, or Contact Mike Belasco Directly