Dynamic Number Insertion (DNI)
Dynamic Number Insertion (DNI) allows your website to serve tracking numbers intelligently based on:
- Source of the visitor (Google/Bing/Yahoo/etc)
- Geographical proximity to your closest location based on the IP address of the visitor
MetroLeads uses a combination of the above information along with your settings within the app to serve the most relevant tracking number.
API
MetroLeads provides a simple API to get the tracking number. Points to note:
- Resolved IP locations are cached for a stipulated amount of time
- For a single visitor, the DNI response is cached based on IP. This will result in the API returning the same DNI number irrespective of any source changes. For e.g. visitor arrives to site from Google and is presented with number A. If the visitor uses another browser and visits the site thru Bing the same number A will be presented. This behavior can be changed by using the nocache query parameter.
- The data used to resolve the location is sent by the client as JSON POST parameters
- Closest API can be either IP or zip code based
Resource URL
POST https://edge.metroleads.com/dni/api/companies/<company_uuid>/closest?nocache=1
You can also force the location of the user based on the zip code. This is relevant if your site allows the visitor to choose your location manually or accepts user zip code for finding closest location.
Resource URL
POST https://edge.metroleads.com/dni/api/companies/<company_uuid>/closest/zip/<zip_code>?nocache=1
Parameters
Parameter | Description |
---|---|
nocache | Disables caching on server |
Json Post Body Parameters
Parameter | Description |
---|---|
domain | Domain of the visitor |
referrer | Referrer string from the browser |
url | URL of the current page |
cookies | Cookies in the session |
keys | Additional information |
Important: The request body should be of type JSON. To ensure this set the request header {Content-Type: application/json}
Utility Method
The JSON parameters above can be fetched using the MetroLeads utility classes that are available when visit tracking is integrated. You can use the attached snippet of code to get all the above information in JSON format.
MG.util.getEnvironment()
{
"domain": "%28direct%29",
"referrer": "",
"url": "/",
"cookies": "sessionMGCookie=lorem visitMGCookie=ipsum",
"keys": ""
}
A sample standalone version (not using JQuery) is available here
Complete Example
var mlCompanyId = '48cb8a89-cc6d-4a66-aeea-96f735c07643';
$.postJSON('https://edge.metroleads.com/dni/api/companies/' + mlCompanyId + '/closest?nocache=1', JSON.stringify(MG.util.getEnvironment()))
.success(function(response) {
// Use response JSON to show phone in UI
})
.error(function(error) {
// Show default phone in UI
});
Json Response
In the example response below, +18185720210
is the tracking number to be displayed for visitors to call. The additional information can be used to show the location information.
{
"phone_number": "+18185720210",
"closest_location": {
"city": "Bangalore Urban",
"name": "Bangalore Office",
"country": "India",
"address": "622-623, 17th Main Road, Ejipura, Bengaluru, Karnataka 560095, India",
"longitude": "77.6266131000",
"hours": [
{
"duration": 8,
"to_time": "5:00pm",
"from_time": "9:00am",
"day_of_week": "weekdays"
},
{
"duration": 9,
"to_time": "6:00pm",
"from_time": "9:00am",
"day_of_week": "saturday"
}
],
"state": "Karnataka",
"postal_code": "560095",
"numbers": [],
"extra_params": {},
"latitude": "12.9370606000",
"timezone": "Asia/India",
"users": []
}
}