As of November 2022, Twilio no longer provides support for Authy SMS/Voice-only customers. Customers who were also using Authy TOTP or Push prior to March 1, 2023 are still supported. The Authy API is now closed to new customers and will be fully deprecated in the future.
For new development, we encourage you to use the Verify v2 API.
Existing customers will not be impacted at this time until Authy API has reached End of Life. For more information about migration, see Migrating from Authy to Verify for SMS.
This Flask sample application is an example of typical login flow. To run this sample app yourself, download the code and follow the instructions on GitHub.
Adding two-factor authentication (2FA) to your web application increases the security of your user's data. Multi-factor authentication determines the identity of a user by validating once by logging into the app, and then a second time with their mobile device using Authy.
For the second factor, we will validate that the user has their mobile phone by either:
See how VMware uses Authy 2FA to secure their enterprise mobility management solution.
If you haven't already, now is the time to sign up for Authy. Create your first application, naming it whatever you wish. After you create your application, your production API key will be visible on your dashboard:
Once we have an Authy API key, we store it in our .env
file, which helps us set the environment variables for our app.
You'll also want to set a callback URL for your application in the OneTouch section of the Authy dashboard. See the project README for more details.
authy2fa-flask/.env_example
1# Environment variables for authy2fa-flask23# Secret key (used for sessions)4SECRET_KEY=not-so-secret56# Authy API Key7# Found at https://dashboard.authy.com under your application8AUTHY_API_KEY=XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX9
Now that we've configured our Flask app, let's take a look at how we register a user with Authy.
When a new user signs up for our website we call this helper function, which handles storing the user in the database as well as registering the user with Authy.
In order to get a user set up for your application you will need their email, phone number and country code. We have fields for each of these on our sign up form.
Once we register the user with Authy we can get the user's Authy id off the response. This is very important — it's how we will verify the identity of our user with Authy.
twofa/utils.py
1from authy.api import AuthyApiClient2from flask import current_app3from authy import AuthyApiException456def get_authy_client():7""" Return a configured Authy client. """8return AuthyApiClient(current_app.config['AUTHY_API_KEY'])91011def create_user(form):12"""Creates an Authy user and then creates a database User"""13client = get_authy_client()1415# Create a new Authy user with the data from our form16authy_user = client.users.create(17form.email.data, form.phone_number.data, form.country_code.data18)1920# If the Authy user was created successfully, create a local User21# with the same information + the Authy user's id22if authy_user.ok():23return form.create_user(authy_user.id)24else:25raise AuthyApiException('', '', authy_user.errors()['message'])262728def send_authy_token_request(authy_user_id):29"""30Sends a request to Authy to send a SMS verification code to a user's phone31"""32client = get_authy_client()3334client.users.request_sms(authy_user_id)353637def send_authy_one_touch_request(authy_user_id, email=None):38"""Initiates an Authy OneTouch request for a user"""39client = get_authy_client()4041details = {}4243if email:44details['Email'] = email4546response = client.one_touch.send_request(47authy_user_id, 'Request to log in to Twilio demo app', details=details48)4950if response.ok():51return response.content525354def verify_authy_token(authy_user_id, user_entered_code):55"""Verifies a user-entered token with Authy"""56client = get_authy_client()5758return client.tokens.verify(authy_user_id, user_entered_code)596061def authy_user_has_app(authy_user_id):62"""Verifies a user has the Authy app installed"""63client = get_authy_client()64authy_user = client.users.status(authy_user_id)65try:66return authy_user.content['status']['registered']67except KeyError:68return False69
Next up, let's take a look at the login.
When a user attempts to log in to our website, we will ask them for a second form of identification. Let's take a look at OneTouch verification first.
OneTouch works like so:
success
message backPOST
request to our app with an approved
statustwofa/auth/views.py
1from authy import AuthyApiException2from flask import flash, jsonify, redirect, render_template, request, session, url_for34from . import auth5from .forms import LoginForm, SignUpForm, VerifyForm6from ..database import db7from ..decorators import login_required, verify_authy_request8from ..models import User9from ..utils import create_user, send_authy_token_request, verify_authy_token101112@auth.route('/sign-up', methods=['GET', 'POST'])13def sign_up():14"""Powers the new user form"""15form = SignUpForm(request.form)1617if form.validate_on_submit():18try:19user = create_user(form)20session['user_id'] = user.id2122return redirect(url_for('main.account'))2324except AuthyApiException as e:25form.errors['Authy API'] = [26'There was an error creating the Authy user',27e.msg,28]2930return render_template('signup.html', form=form)313233@auth.route('/login', methods=['GET', 'POST'])34def log_in():35"""36Powers the main login form.3738- GET requests render the username / password form39- POST requests process the form data via an AJAX request triggered in the40user's browser41"""42form = LoginForm(request.form)4344if form.validate_on_submit():45user = User.query.filter_by(email=form.email.data).first()46if user is not None and user.verify_password(form.password.data):47session['user_id'] = user.id4849if user.has_authy_app:50# Send a request to verify this user's login with OneTouch51one_touch_response = user.send_one_touch_request()52return jsonify(one_touch_response)53else:54return jsonify({'success': False})55else:56# The username and password weren't valid57form.email.errors.append(58'The username and password combination you entered are invalid'59)6061if request.method == 'POST':62# This was an AJAX request, and we should return any errors as JSON63return jsonify(64{'error': render_template('_login_error.html', form=form)}65) # noqa: E50166else:67return render_template('login.html', form=form)686970@auth.route('/authy/callback', methods=['POST'])71@verify_authy_request72def authy_callback():73"""Authy uses this endpoint to tell us the result of a OneTouch request"""74authy_id = request.json.get('authy_id')75# When you're configuring your Endpoint/URL under OneTouch settings '1234'76# is the preset 'authy_id'77if authy_id != 1234:78user = User.query.filter_by(authy_id=authy_id).one()7980if not user:81return ('', 404)8283user.authy_status = request.json.get('status')84db.session.add(user)85db.session.commit()8687return ('', 200)888990@auth.route('/login/status')91def login_status():92"""93Used by AJAX requests to check the OneTouch verification status of a user94"""95user = User.query.get(session['user_id'])96return user.authy_status979899@auth.route('/verify', methods=['GET', 'POST'])100@login_required101def verify():102"""Powers token validation (not using OneTouch)"""103form = VerifyForm(request.form)104user = User.query.get(session['user_id'])105106# Send a token to our user when they GET this page107if request.method == 'GET':108send_authy_token_request(user.authy_id)109110if form.validate_on_submit():111user_entered_code = form.verification_code.data112113verified = verify_authy_token(user.authy_id, str(user_entered_code))114if verified.ok():115user.authy_status = 'approved'116db.session.add(user)117db.session.commit()118119flash(120"You're logged in! Thanks for using two factor verification.", 'success'121) # noqa: E501122return redirect(url_for('main.account'))123else:124form.errors['verification_code'] = ['Code invalid - please try again.']125126return render_template('verify.html', form=form)127128129@auth.route('/resend', methods=['POST'])130@login_required131def resend():132"""Resends a verification token to a user"""133user = User.query.get(session.get('user_id'))134send_authy_token_request(user.authy_id)135flash('I just re-sent your verification code - enter it below.', 'info')136return redirect(url_for('auth.verify'))137138139@auth.route('/logout')140def log_out():141"""Log out a user, clearing their session variables"""142user_id = session.pop('user_id', None)143user = User.query.get(user_id)144user.authy_status = 'unverified'145db.session.add(user)146db.session.commit()147148flash("You're now logged out! Thanks for visiting.", 'info')149return redirect(url_for('main.home'))
When our user logs in we immediately attempt to verify their identity with OneTouch. We will fall back gracefully if they don't have a OneTouch device, but we don't know until we try.
Authy lets us pass extra details with our OneTouch request including a message, a logo, and any other details we want to send. We could send any number of details by appending details[some_detail]
to our POST
request. You could imagine a scenario where we send a OneTouch request to approve a money transfer:
1data = {2'api_key': client.api_key,3'message': "Request to send money to Jarod's vault",4'details[Request From]': 'Jarod',5'details[Amount Requested]': '1,000,000',6'details[Currency]': 'Galleons'7}
twofa/models.py
1from werkzeug.security import generate_password_hash, check_password_hash23from . import db4from .utils import authy_user_has_app, send_authy_one_touch_request567class User(db.Model):8"""9Represents a single user in the system.10"""1112__tablename__ = 'users'1314AUTHY_STATUSES = ('unverified', 'onetouch', 'sms', 'token', 'approved', 'denied')1516id = db.Column(db.Integer, primary_key=True)17email = db.Column(db.String(64), unique=True, index=True)18password_hash = db.Column(db.String(128))19full_name = db.Column(db.String(256))20country_code = db.Column(db.Integer)21phone = db.Column(db.String(30))22authy_id = db.Column(db.Integer)23authy_status = db.Column(db.Enum(*AUTHY_STATUSES, name='authy_statuses'))2425def __init__(26self,27email,28password,29full_name,30country_code,31phone,32authy_id,33authy_status='approved',34):35self.email = email36self.password = password37self.full_name = full_name38self.country_code = country_code39self.phone = phone40self.authy_id = authy_id41self.authy_status = authy_status4243def __repr__(self):44return '<User %r>' % self.email4546@property47def password(self):48raise AttributeError('password is not readable')4950@property51def has_authy_app(self):52return authy_user_has_app(self.authy_id)5354@password.setter55def password(self, password):56self.password_hash = generate_password_hash(password)5758def verify_password(self, password):59return check_password_hash(self.password_hash, password)6061def send_one_touch_request(self):62return send_authy_one_touch_request(self.authy_id, self.email)
Once we send the request we update our user's authy_status
based on the response. This lets us know which method Authy will try first to verify this request with our user. But first we have to register a OneTouch callback endpoint.
In order for our app to know what the user did after we sent the OneTouch request, we need to register a callback endpoint with Authy.
Note: In order to verify that the request is coming from Authy we've written a decorator, @verify_authy_request,
that will halt the request if we cannot verify that it actually came from Authy*.*
Here in our callback, we look up the user using the authy_id
sent with the Authy POST
request. In a production application we might use a websocket to let our client know that we received a response from Authy. For this version, we update the authy_status
on the user. Our client-side code will check that field before completing the login.
twofa/auth/views.py
1from authy import AuthyApiException2from flask import flash, jsonify, redirect, render_template, request, session, url_for34from . import auth5from .forms import LoginForm, SignUpForm, VerifyForm6from ..database import db7from ..decorators import login_required, verify_authy_request8from ..models import User9from ..utils import create_user, send_authy_token_request, verify_authy_token101112@auth.route('/sign-up', methods=['GET', 'POST'])13def sign_up():14"""Powers the new user form"""15form = SignUpForm(request.form)1617if form.validate_on_submit():18try:19user = create_user(form)20session['user_id'] = user.id2122return redirect(url_for('main.account'))2324except AuthyApiException as e:25form.errors['Authy API'] = [26'There was an error creating the Authy user',27e.msg,28]2930return render_template('signup.html', form=form)313233@auth.route('/login', methods=['GET', 'POST'])34def log_in():35"""36Powers the main login form.3738- GET requests render the username / password form39- POST requests process the form data via an AJAX request triggered in the40user's browser41"""42form = LoginForm(request.form)4344if form.validate_on_submit():45user = User.query.filter_by(email=form.email.data).first()46if user is not None and user.verify_password(form.password.data):47session['user_id'] = user.id4849if user.has_authy_app:50# Send a request to verify this user's login with OneTouch51one_touch_response = user.send_one_touch_request()52return jsonify(one_touch_response)53else:54return jsonify({'success': False})55else:56# The username and password weren't valid57form.email.errors.append(58'The username and password combination you entered are invalid'59)6061if request.method == 'POST':62# This was an AJAX request, and we should return any errors as JSON63return jsonify(64{'error': render_template('_login_error.html', form=form)}65) # noqa: E50166else:67return render_template('login.html', form=form)686970@auth.route('/authy/callback', methods=['POST'])71@verify_authy_request72def authy_callback():73"""Authy uses this endpoint to tell us the result of a OneTouch request"""74authy_id = request.json.get('authy_id')75# When you're configuring your Endpoint/URL under OneTouch settings '1234'76# is the preset 'authy_id'77if authy_id != 1234:78user = User.query.filter_by(authy_id=authy_id).one()7980if not user:81return ('', 404)8283user.authy_status = request.json.get('status')84db.session.add(user)85db.session.commit()8687return ('', 200)888990@auth.route('/login/status')91def login_status():92"""93Used by AJAX requests to check the OneTouch verification status of a user94"""95user = User.query.get(session['user_id'])96return user.authy_status979899@auth.route('/verify', methods=['GET', 'POST'])100@login_required101def verify():102"""Powers token validation (not using OneTouch)"""103form = VerifyForm(request.form)104user = User.query.get(session['user_id'])105106# Send a token to our user when they GET this page107if request.method == 'GET':108send_authy_token_request(user.authy_id)109110if form.validate_on_submit():111user_entered_code = form.verification_code.data112113verified = verify_authy_token(user.authy_id, str(user_entered_code))114if verified.ok():115user.authy_status = 'approved'116db.session.add(user)117db.session.commit()118119flash(120"You're logged in! Thanks for using two factor verification.", 'success'121) # noqa: E501122return redirect(url_for('main.account'))123else:124form.errors['verification_code'] = ['Code invalid - please try again.']125126return render_template('verify.html', form=form)127128129@auth.route('/resend', methods=['POST'])130@login_required131def resend():132"""Resends a verification token to a user"""133user = User.query.get(session.get('user_id'))134send_authy_token_request(user.authy_id)135flash('I just re-sent your verification code - enter it below.', 'info')136return redirect(url_for('auth.verify'))137138139@auth.route('/logout')140def log_out():141"""Log out a user, clearing their session variables"""142user_id = session.pop('user_id', None)143user = User.query.get(user_id)144user.authy_status = 'unverified'145db.session.add(user)146db.session.commit()147148flash("You're now logged out! Thanks for visiting.", 'info')149return redirect(url_for('main.home'))150
Let's take a look at that client-side code now.
Scenario: The OneTouch callback URL provided by you is no longer active.
Action: We will disable the OneTouch callback after 3 consecutive HTTP error responses. We will also
How to enable OneTouch callback? You need to update the OneTouch callback endpoint, which will allow the OneTouch callback.
Visit the Twilio Console: Console > Authy > Applications > {ApplicationName} > Push Authentication > Webhooks > Endpoint/URL to update the Endpoint/URL with a valid OneTouch callback URL.
In order for two-factor authentication to be seamless, it is best done asynchronously so that the user doesn't even know it's happening.
We've already taken a look at what's happening on the server side, so let's step in front of the cameras now and see how our JavaScript is interacting with those server endpoints.
First we hijack the login form submit and pass the data to our sessions/create
controller using Ajax. Depending on how that endpoint responds, we will either wait for a OneTouch response or ask the user to enter a token.
If we expect a OneTouch response, we will begin polling /login/status
until we see the OneTouch login was either approved or denied.
twofa/static/js/sessions.js
1$(document).ready(function() {23$('#login-form').submit(function(e) {4e.preventDefault();5const formData = $(e.currentTarget).serialize();6attemptOneTouchVerification(formData);7});89const attemptOneTouchVerification = function(form) {10$.post( "/login", form, function(data) {11$('.form-errors').remove();12// Check first if we successfully authenticated the username and password13if (data.hasOwnProperty('error')) {14$('#login-form').prepend(data.error);15return;16}1718if (data.success) {19$('#authy-modal').modal({backdrop:'static'},'show');20$('.auth-ot').fadeIn();21checkForOneTouch();22} else {23redirectToTokenForm();24}25});26};2728const checkForOneTouch = function() {29$.get( "/login/status", function(data) {3031if (data === 'approved') {32window.location.href = "/account";33} else if (data === 'denied') {34redirectToTokenForm();35} else {36setTimeout(checkForOneTouch, 2000);37}38});39};4041const redirectToTokenForm = function() {42window.location.href = "/verify";43};44});45
Now let's see how to handle the case where we receive a denied OneTouch response.
This is the endpoint that our JavaScript is polling. It is waiting for the user's authy_status
to be either approved
or denied
. If the user approves the OneTouch request, our JavaScript code from the previous step will redirect their browser to their account screen.
If the OneTouch request was denied, we will ask the user to log in with a token instead.
twofa/auth/views.py
1from authy import AuthyApiException2from flask import flash, jsonify, redirect, render_template, request, session, url_for34from . import auth5from .forms import LoginForm, SignUpForm, VerifyForm6from ..database import db7from ..decorators import login_required, verify_authy_request8from ..models import User9from ..utils import create_user, send_authy_token_request, verify_authy_token101112@auth.route('/sign-up', methods=['GET', 'POST'])13def sign_up():14"""Powers the new user form"""15form = SignUpForm(request.form)1617if form.validate_on_submit():18try:19user = create_user(form)20session['user_id'] = user.id2122return redirect(url_for('main.account'))2324except AuthyApiException as e:25form.errors['Authy API'] = [26'There was an error creating the Authy user',27e.msg,28]2930return render_template('signup.html', form=form)313233@auth.route('/login', methods=['GET', 'POST'])34def log_in():35"""36Powers the main login form.3738- GET requests render the username / password form39- POST requests process the form data via an AJAX request triggered in the40user's browser41"""42form = LoginForm(request.form)4344if form.validate_on_submit():45user = User.query.filter_by(email=form.email.data).first()46if user is not None and user.verify_password(form.password.data):47session['user_id'] = user.id4849if user.has_authy_app:50# Send a request to verify this user's login with OneTouch51one_touch_response = user.send_one_touch_request()52return jsonify(one_touch_response)53else:54return jsonify({'success': False})55else:56# The username and password weren't valid57form.email.errors.append(58'The username and password combination you entered are invalid'59)6061if request.method == 'POST':62# This was an AJAX request, and we should return any errors as JSON63return jsonify(64{'error': render_template('_login_error.html', form=form)}65) # noqa: E50166else:67return render_template('login.html', form=form)686970@auth.route('/authy/callback', methods=['POST'])71@verify_authy_request72def authy_callback():73"""Authy uses this endpoint to tell us the result of a OneTouch request"""74authy_id = request.json.get('authy_id')75# When you're configuring your Endpoint/URL under OneTouch settings '1234'76# is the preset 'authy_id'77if authy_id != 1234:78user = User.query.filter_by(authy_id=authy_id).one()7980if not user:81return ('', 404)8283user.authy_status = request.json.get('status')84db.session.add(user)85db.session.commit()8687return ('', 200)888990@auth.route('/login/status')91def login_status():92"""93Used by AJAX requests to check the OneTouch verification status of a user94"""95user = User.query.get(session['user_id'])96return user.authy_status979899@auth.route('/verify', methods=['GET', 'POST'])100@login_required101def verify():102"""Powers token validation (not using OneTouch)"""103form = VerifyForm(request.form)104user = User.query.get(session['user_id'])105106# Send a token to our user when they GET this page107if request.method == 'GET':108send_authy_token_request(user.authy_id)109110if form.validate_on_submit():111user_entered_code = form.verification_code.data112113verified = verify_authy_token(user.authy_id, str(user_entered_code))114if verified.ok():115user.authy_status = 'approved'116db.session.add(user)117db.session.commit()118119flash(120"You're logged in! Thanks for using two factor verification.", 'success'121) # noqa: E501122return redirect(url_for('main.account'))123else:124form.errors['verification_code'] = ['Code invalid - please try again.']125126return render_template('verify.html', form=form)127128129@auth.route('/resend', methods=['POST'])130@login_required131def resend():132"""Resends a verification token to a user"""133user = User.query.get(session.get('user_id'))134send_authy_token_request(user.authy_id)135flash('I just re-sent your verification code - enter it below.', 'info')136return redirect(url_for('auth.verify'))137138139@auth.route('/logout')140def log_out():141"""Log out a user, clearing their session variables"""142user_id = session.pop('user_id', None)143user = User.query.get(user_id)144user.authy_status = 'unverified'145db.session.add(user)146db.session.commit()147148flash("You're now logged out! Thanks for visiting.", 'info')149return redirect(url_for('main.home'))150
Now let's see how to send a token to the user.
This view is responsible for sending the token and then validating the code that our user enters.
In the case where our user already has the Authy app but is not enabled for OneTouch, this same method will trigger a push notification that will be sent to their phone with a code inside the Authy app.
The user will see a verification form.
A POST
request to this view validates the code our user enters. First, we grab the User
model by the ID we stored in the session. Next, we use the Authy API to validate the code our user entered against the one Authy sent them.
If the two match, our login process is complete! We mark the user's authy_status
as approved
and thank them for using two-factor authentication.
twofa/auth/views.py
1from authy import AuthyApiException2from flask import flash, jsonify, redirect, render_template, request, session, url_for34from . import auth5from .forms import LoginForm, SignUpForm, VerifyForm6from ..database import db7from ..decorators import login_required, verify_authy_request8from ..models import User9from ..utils import create_user, send_authy_token_request, verify_authy_token101112@auth.route('/sign-up', methods=['GET', 'POST'])13def sign_up():14"""Powers the new user form"""15form = SignUpForm(request.form)1617if form.validate_on_submit():18try:19user = create_user(form)20session['user_id'] = user.id2122return redirect(url_for('main.account'))2324except AuthyApiException as e:25form.errors['Authy API'] = [26'There was an error creating the Authy user',27e.msg,28]2930return render_template('signup.html', form=form)313233@auth.route('/login', methods=['GET', 'POST'])34def log_in():35"""36Powers the main login form.3738- GET requests render the username / password form39- POST requests process the form data via an AJAX request triggered in the40user's browser41"""42form = LoginForm(request.form)4344if form.validate_on_submit():45user = User.query.filter_by(email=form.email.data).first()46if user is not None and user.verify_password(form.password.data):47session['user_id'] = user.id4849if user.has_authy_app:50# Send a request to verify this user's login with OneTouch51one_touch_response = user.send_one_touch_request()52return jsonify(one_touch_response)53else:54return jsonify({'success': False})55else:56# The username and password weren't valid57form.email.errors.append(58'The username and password combination you entered are invalid'59)6061if request.method == 'POST':62# This was an AJAX request, and we should return any errors as JSON63return jsonify(64{'error': render_template('_login_error.html', form=form)}65) # noqa: E50166else:67return render_template('login.html', form=form)686970@auth.route('/authy/callback', methods=['POST'])71@verify_authy_request72def authy_callback():73"""Authy uses this endpoint to tell us the result of a OneTouch request"""74authy_id = request.json.get('authy_id')75# When you're configuring your Endpoint/URL under OneTouch settings '1234'76# is the preset 'authy_id'77if authy_id != 1234:78user = User.query.filter_by(authy_id=authy_id).one()7980if not user:81return ('', 404)8283user.authy_status = request.json.get('status')84db.session.add(user)85db.session.commit()8687return ('', 200)888990@auth.route('/login/status')91def login_status():92"""93Used by AJAX requests to check the OneTouch verification status of a user94"""95user = User.query.get(session['user_id'])96return user.authy_status979899@auth.route('/verify', methods=['GET', 'POST'])100@login_required101def verify():102"""Powers token validation (not using OneTouch)"""103form = VerifyForm(request.form)104user = User.query.get(session['user_id'])105106# Send a token to our user when they GET this page107if request.method == 'GET':108send_authy_token_request(user.authy_id)109110if form.validate_on_submit():111user_entered_code = form.verification_code.data112113verified = verify_authy_token(user.authy_id, str(user_entered_code))114if verified.ok():115user.authy_status = 'approved'116db.session.add(user)117db.session.commit()118119flash(120"You're logged in! Thanks for using two factor verification.", 'success'121) # noqa: E501122return redirect(url_for('main.account'))123else:124form.errors['verification_code'] = ['Code invalid - please try again.']125126return render_template('verify.html', form=form)127128129@auth.route('/resend', methods=['POST'])130@login_required131def resend():132"""Resends a verification token to a user"""133user = User.query.get(session.get('user_id'))134send_authy_token_request(user.authy_id)135flash('I just re-sent your verification code - enter it below.', 'info')136return redirect(url_for('auth.verify'))137138139@auth.route('/logout')140def log_out():141"""Log out a user, clearing their session variables"""142user_id = session.pop('user_id', None)143user = User.query.get(user_id)144user.authy_status = 'unverified'145db.session.add(user)146db.session.commit()147148flash("You're now logged out! Thanks for visiting.", 'info')149return redirect(url_for('main.home'))150
That's it! We've just implemented two-factor auth using three different methods and the latest in Authy technology.
If you're a Python developer working with Twilio, you might enjoy these other tutorials:
Faster than email and less likely to get blocked, text messages are great for timely alerts and notifications. Learn how to send out SMS (and MMS) notifications to a list of server administrators.
Call Tracking helps you measure the effectiveness of different marketing campaigns. By assigning a unique phone number to different advertisements, you can track which ones have the best call rates and get some data about the callers themselves.