Dynamic Number Insertion (DNI)

Dynamic Number Insertion (DNI) allows your website to serve tracking numbers intelligently based on:

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:

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": []
  }
}