Voximplant. Blog

Call Tracking

Calltracking

Call tracking lets you analyze the effectiveness of marketing channels and optimize your campaigns accordingly. It’s easy to implement call tracking using VoxImplant and get all information about calls going via the system, including dialed number, time of day it was dialed, call duration, number where it was forwarded, call record and much more. You can get phone numbers either from VoxImplant directly, or connect your own phone numbers using SIP trunk.

Let’s create our VoxImplat call tracking application:

  • Login into VoxImplant control panel
  • Create new application in the Applications section and call it calltracking
  • Create new scenario in the Scenarios section with the following code:
    1. var outbound_call,
    2. dialed_number,
    3. agent_number,
    4. record_url,
    5. call_date,
    6. call_length = 0,
    7. failure_code,
    8. failure_reason,
    9. wsURL = "http://demos.zingaya.com/calltracking/call.php", // let's assume we will receive the number for forwarding there, don't forget to change this to something real
    10. connected = false;
    11.  
    12. // Inbound call arrived
    13. VoxEngine.addEventListener(AppEvents.CallAlerting, function (e) {
    14. call_date = new Date().toUTCString();
    15. dialed_number = e.destination;
    16. wsURL += "?dialed_number=" + encodeURIComponent(dialed_number);
    17. // make http request to get the corresponding number(s) for call forwarding
    18. Net.httpRequest(wsURL, function (res) {
    19. if (res.code == 200) {
    20. // received phone number(s) for forwarding
    21. agent_number = res.text;
    22. outbound_call = VoxEngine.callPSTN(agent_number, dialed_number);
    23. VoxEngine.easyProcess(e.call, outbound_call, handleCallsConnected);
    24. outbound_call.removeEventListener(CallEvents.Disconnected);
    25. outbound_call.addEventListener(CallEvents.Disconnected, handleCallDisconnected);
    26. outbound_call.removeEventListener(CallEvents.Failed);
    27. outbound_call.addEventListener(CallEvents.Failed, handleCallFailed);
    28. } else {
    29. // webservice unavailable - reject the call
    30. e.call.reject();
    31. }
    32. });
    33. });
    34.  
    35. VoxEngine.addEventListener(AppEvents.Terminating, function (e) {
    36. if (connected) {
    37. Logger.write("Dialed number: " + dialed_number +
    38. " Agent number: " + agent_number +
    39. " Date: " + call_date +
    40. " Length: " + call_length +
    41. " Record URL: " + record_url);
    42. // notify webservice about successful call, use Net.httpRequest
    43. } else {
    44. Logger.write("Call failed. Code: " + failure_code + " Reason: " + failure_reason);
    45. // notify webservice about failed call, use Net.httpRequest
    46. }
    47. });
    48.  
    49. function handleCallFailed(e) {
    50. failure_code = e.code;
    51. failure_reason = e.reason;
    52. VoxEngine.terminate();
    53. }
    54.  
    55. function handleCallDisconnected(e) {
    56. call_length = e.duration;
    57. VoxEngine.terminate();
    58. }
    59.  
    60. function handleCallsConnected(call1, call2) {
    61. connected = true;
    62. outbound_call.addEventListener(CallEvents.RecordStarted, function (e) {
    63. record_url = e.url;
    64. });
    65. outbound_call.record(); // start call recording
    66. }
  • Edit your application at https://manage.voximplant.com/#editApplication and add app rule to forward inbound calls to the created scenario. You can call it InboundTracking, no need to change default Pattern, don’t forget to drag’n’drop the scenario to Assigned list before pressing Add button.
  • Buy phone number(s) in Phone numbers section of the control panel and then assigned it to calltracking app.
  • If you didn’t forget to change wsURL in the scenario to something that returns phone number for call forwarding then you can make a call to the number you’ve bought and see the tracking in action.

It’s a very simple example of the call tracking app. You can modify it to let the scenario forward the call to a few numbers simultaneously or try to call them one-by-one till somebody answers. If the call wasn’t forwarded correctly you can always make a callback to the customer (you don’t want to loose your customers, do you?).

Comments