Skip to main content


Tracking call details with Bandwidth


November 10, 2015


July 9, 2021

graphic of computer screen with code

Keeping call analytics with Bandwidth is incredibly easy.

The business of tracking where an incoming sales call originated historically been an incredibly pricey (but necessary) add on. In fact, if you have used Google on your smart phone to call any business in the past years, your call was probably tracked.

Call tracking helps businesses know what ads and searches are effective, pretty straightforward stuff.

Basic Call Tracking Flow

Bandwidth XML (BXML) Basics

<?xml version="1.0" encoding="UTF-8"?>
	<SpeakSentence gender="male" locale="en_US" voice="paul">Thank you for calling Tom's Tire Shop</SpeakSentence>
	<Transfer transferCallerId="+19198281234">
		<PhoneNumber>sip:[email protected]</PhoneNumber>

Bandwidth XML (BXML for short) makes call control incredibly simple. The above example does a deceivingly large amount of work for us.

  1. Speaks the sentence specified to the original caller.
  2. Creates an outbound call with the specified callerId to each phone number specified in the <PhoneNumber> tag as well as the SIP address.
  3. When the first phone number or SIP Phone (can be softphone or SIP Phone) answers it will connect that endpoint to the original caller.

NodeJS SDK Basics

var xml = require('node-bandwidth').xml;
/// Start the XML response
var response = new xml.Response();
// Create the sentence
var speakSentence = new xml.SpeakSentence({sentence: "Thank you for calling, please wait while we connect you.",
	voice: "paul", gender: "male", locale: "en_US"});
var transfer = new xml.Transfer({
	transferTo: "+19198281234"
//Push all the XML to the response
// Create the xml to send
var bxml = response.toXml();

Bandwidth provides a SDK for NodeJS to build up XML to send back when an event happens.

Putting it all together

Putting all this together with a small Express app with SocketIO gives us a very basic demo that will keep track of how many times a number was called along with the latest incoming call number and call duration.

Get the code

Download the source code from the github link.

Set up ngrok

Download ngrok if you have not already. Ngrok is a handy tool that provides an external URL to map to localhost:port.

ngrok running on OSX

The application defaults to port 5000, so launch ngrok http mapping to port 5000:

ngrok http 5000

Be sure to copy the forwarding ngrok url, we’ll need that later to configure the application

Modify bandwidth.json

User creds and baseURL and specified in a json file <bandwidth.json>. Be sure to update the values provided by Bandwidth and ngrok.

  1. userId — UserID from Bandwidth
  2. apiToken — API Token from Bandwidth
  3. apiSecret — API Secret from Bandwidth
  4. baseUrl — ngrok url (from above)
	"userId": "u-yourUserID",
	"apiToken": "t-yourToken",
	"apiSecret": "yourSecret",
	"baseUrl": "" 

Install and Run

The app is written in node, so following normal conventions just run:

npm install
npm start

Then visit ‘localhost:5000’ and call the number on the screen to see some basic call tracking!

Live Demo

Check out a live demo at

Subscribe to Bandwidth

If for some reason you don’t already have an account, get started with the Bandwidth Platform by filling out the form here. One of our awesome support staff will get you setup in no time!