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

December 8th, 2009 // 31 Comments

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.

Article Submitted by Mike Belasco More from Mike

President While SEO and SEM strategies were still younger than his daughter (she's three), Mike began his journey towards founding…

31 Comments on the article

  1. 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.

  2. Hi Mike,

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

    Regards,

    -jeff

    Co-Founder
    Twilio.com

  3. 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

  4. 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!

  5. 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

  6. 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.

  7. 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.

  8. 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.

  9. 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.

  10. 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!

  11. 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.

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

    Thanks

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

    Thanks,

    Harry

  14. 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?

  15. 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.

  16. 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.

  17. 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

  18. 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.

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>