Get dynamic numbers on your website
Dynamic number insertion allows for web pages to display telephone numbers that are unique to each visitor. This enables you to track visitors on your website, where they come from and what is driving your phone calls. This is achieved by Mediahawk providing a pool of numbers which then dynamically change when a user enters a page on your website.
Before you begin this guide, please ensure you have followed the Authenticate guide and have a valid token.
You can download a full working code example for this guide here:
CURL, PHP, Node.js, Python, C#
Add a dynamic URL
Each website that you want to track will have to have it's own dynamic URL. This allows us to track visitors to the website and update the phone numbers on the website to be trackable. To add a new dynamic URL, you will also have to add a pool as every URL must contain a pool. A pool is a set of tracking numbers. You may use one pool for client services and one pool for sales if you want to track calls to them separately or they have different destination numbers.
- CURL
- PHP
- Python
- Node.js
- C#
- Try it out
apiKey="<API_KEY>"
url="<WEBSITE_URL>"
poolName="<POOL_NAME>"
prefix="<NUMBER_PREFIX>"
curl -L -X POST "https://www.reports.mediahawk.co.uk/rest/v2_0/urls?api_key=${apiKey}" \
--header "Content-Type: application/json" \
--data '{ "url": "'$url'", "google_bot_filter": true, "subdomain_tracking": false, "pool": { "name": "'$poolName'", "prefix": "'$prefix'", "format": "08000000000", "numbers_to_replace": [] } }'
$apiKey = "<API_KEY>";
$url = "<WEBSITE_URL>";
$prefix = "<PREFIX>";
$poolName = "<POOL_NAME>";
// Use Guzzle to make a request to the Mediahawk API
$client = new Client();
$headers = [
"Content-Type" => "application/json",
"Accept" => "application/json",
];
$body = json_encode([
"url" => $url,
"google_bot_filter" => true,
"subdomain_tracking" => false,
"pool" => [
"name" => $poolName,
"prefix" => $prefix,
"format" => "08000000000",
"numbers_to_replace" => [],
]
]);
$request = new Request("POST", "https://www.reports.mediahawk.co.uk/rest/v2_0/urls?api_key={$apiKey}", $headers, $body);
$res = $client->sendAsync($request)->wait();
$responseDecoded = json_decode($res->getBody());
echo json_encode($responseDecoded, JSON_PRETTY_PRINT) . PHP_EOL;
import requests
import json
apiKey = "<API_KEY>"
url = "<WEBSITE_URL>"
prefix = "<PREFIX>"
poolName = "<POOL_NAME>"
headers = {
"Content-Type": "application/json"
}
payload = json.dumps({
"url": url,
"google_bot_filter": True,
"subdomain_tracking": False,
"pool": {
"name": poolName,
"prefix": prefix,
"format": "08000000000",
"numbers_to_replace": []
}
})
url = "https://www.reports.mediahawk.co.uk/rest/v2_0/urls?api_key=" + apiKey
httpRequest = requests.Session();
response = httpRequest.request("POST", url, headers=headers, data=payload)
dynamicUrl = json.loads(response.text)
print(json.dumps(dynamicUrl, indent=2))
const axios = require("axios");
let apiKey = "<API_KEY>";
let url = "<WEBSITE_URL>";
let prefix = "<NUMBER_PREFIX>";
let poolName = "<POOL_NAME>";
let data = JSON.stringify({
url: url,
google_bot_filter: true,
subdomain_tracking: false,
pool: {
name: poolName,
prefix: prefix,
format: "08000000000",
numbers_to_replace: [],
},
});
let config = {
method: "post",
url: "https://www.reports.mediahawk.co.uk/rest/v2_0/urls?api_key=" + apiKey,
headers: {
"Content-Type": "application/json",
Accept: "application/json",
},
data: data,
};
axios(config)
.then((response) => {
console.log(JSON.stringify(response.data, null, 2));
})
.catch((error) => {
console.log(error);
});
using RestSharp;
using Newtonsoft.Json;
string apiKey = "<API_KEY>";
string url = "<WEBSITE_URL>";
string prefix = "<PREFIX>";
string poolName = "<POOL_NAME>";
var restClient = new RestClient("https://www.reports.mediahawk.co.uk");
restClient.Timeout = -1;
var dynamicUrlCreateRequest = new RestRequest("/rest/v2_0/urls?api_key=" + apiKey, Method.POST);
dynamicUrlCreateRequest.AddHeader("Content-Type", "application/json");
dynamicUrlCreateRequest.AddHeader("Accept", "application/json");
dynamicUrlCreateRequest.AddJsonBody(
new
{
url = url,
google_bot_filter = true,
subdomain_tracking = false,
pool = new
{
name = poolName,
prefix = prefix,
format = "08000000000",
numbers_to_replace = Array.Empty<string>()
}
}
);
IRestResponse dynamicUrlResponse = restClient.Execute(dynamicUrlCreateRequest);
var dynamicUrlObject = JsonConvert.DeserializeObject<dynamic>(dynamicUrlResponse.Content);
Console.WriteLine(dynamicUrlObject);
The response will appear here
Each pool has a routing that tells us where to send calls. If you have different routings for different phone numbers, you will require multiple pools.
Add additional pools
This step is optional.
If you have any other phone numbers on the website you'd like to track, add those pools now.
- CURL
- PHP
- Python
- Node.js
- C#
- Try it out
apiKey="<API_KEY>"
# The unique tracking reference of your dynamic URL
vaCode="<VA_CODE>"
prefix="<NUMBER_PREFIX>"
poolName="<POOL_NAME>"
curl -L -X POST "https://www.reports.mediahawk.co.uk/rest/v2_0/urls/${vaCode}/pools?api_key=${apiKey}" \
--header "Content-Type: application/json" \
--data '{ "name": "'$poolName'", "prefix": "'$prefix'", "format": "08000000000", "numbers_to_replace": [] }'
$apiKey = "<API_KEY>";
// The unique tracking reference of your dynamic URL
$vaCode = "<VA_CODE>";
$prefix = "<PREFIX>";
$poolName = "<POOL_NAME>";
// Use Guzzle to make a request to the Mediahawk API
$client = new Client();
$headers = [
"Content-Type" => "application/json",
"Accept" => "application/json",
];
$body = json_encode([
"name" => $poolName,
"prefix" => $prefix,
"format" => "08000000000",
"numbers_to_replace" => [],
]);
$request = new Request("POST", "https://www.reports.mediahawk.co.uk/rest/v2_0/urls/${vaCode}/pools?api_key={$apiKey}", $headers, $body);
$res = $client->sendAsync($request)->wait();
$responseDecoded = json_decode($res->getBody());
echo json_encode($responseDecoded, JSON_PRETTY_PRINT) . PHP_EOL;
import requests
import json
apiKey = "<API_KEY>"
# The unique tracking reference of your dynamic URL
vaCode = "<VA_CODE>"
prefix = "<PREFIX>"
poolName = "<POOL_NAME>"
headers = {
"Content-Type": "application/json"
}
payload = json.dumps({
"name": poolName,
"prefix": prefix,
"format": "08000000000",
"numbers_to_replace": []
})
url = "https://www.reports.mediahawk.co.uk/rest/v2_0/urls/"+vaCode+"/pools?api_key=" + apiKey
httpRequest = requests.Session();
response = httpRequest.request("POST", url, headers=headers, data=payload)
pool = json.loads(response.text)
print(json.dumps(pool, indent=2))
const axios = require("axios");
let apiKey = "<API_KEY>";
// The unique tracking reference of your dynamic URL
let vaCode = "<VA_CODE>";
let prefix = "<NUMBER_PREFIX>";
let poolName = "<POOL_NAME>";
let data = JSON.stringify({
name: poolName,
prefix: prefix,
format: "08000000000",
numbers_to_replace: [],
});
let config = {
method: "post",
url:
"https://www.reports.mediahawk.co.uk/rest/v2_0/urls/" +
vaCode +
"/pools?api_key=" +
apiKey,
headers: {
"Content-Type": "application/json",
Accept: "application/json",
},
data: data,
};
axios(config)
.then((response) => {
console.log(JSON.stringify(response.data, null, 2));
})
.catch((error) => {
console.log(error);
});
using RestSharp;
using Newtonsoft.Json;
string apiKey = "<API_KEY>";
// The unique tracking reference of your dynamic URL
string vaCode = "<VA_CODE>";
string prefix = "<PREFIX>";
string poolName = "<POOL_NAME>";
var restClient = new RestClient("https://www.reports.mediahawk.co.uk");
restClient.Timeout = -1;
var poolCreateRequest = new RestRequest("/rest/v2_0/urls/"+vaCode+"/pools?api_key=" + apiKey, Method.POST);
poolCreateRequest.AddHeader("Content-Type", "application/json");
poolCreateRequest.AddHeader("Accept", "application/json");
poolCreateRequest.AddJsonBody(
new
{
name = poolName,
prefix = prefix,
format = "08000000000",
numbers_to_replace = Array.Empty<string>()
}
);
IRestResponse poolResponse = restClient.Execute(poolCreateRequest);
var poolObject = JsonConvert.DeserializeObject<dynamic>(poolResponse.Content);
Console.WriteLine(poolObject);
The response will appear here
Get the instructions
Once you have added your dynamic URL, you need to get the instructions that tell you how to set it up on the website.
- CURL
- PHP
- Python
- Node.js
- C#
- Try it out
apiKey="<API_KEY>"
# The unique tracking reference of your dynamic URL
vaCode="<VA_CODE>"
curl -L -X GET "https://www.reports.mediahawk.co.uk/rest/v2_0/urls/${vaCode}/instructions?api_key=${apiKey}"
$apiKey = "<API_KEY>";
// The unique tracking reference of your dynamic URL
$vaCode = "<VA_CODE>";
// Use Guzzle to make a request to the Mediahawk API
$client = new Client();
$headers = [
"Accept" => "application/json",
];
$request = new Request("GET", "https://www.reports.mediahawk.co.uk/rest/v2_0/urls/${vaCode}/instructions?api_key=${apiKey}", $headers);
$res = $client->sendAsync($request)->wait();
$responseDecoded = json_decode($res->getBody());
echo json_encode($responseDecoded, JSON_PRETTY_PRINT) . PHP_EOL;
import requests
import json
apiKey = "<API_KEY>"
# The unique tracking reference of your dynamic URL
vaCode = "<VA_CODE>"
url = "https://www.reports.mediahawk.co.uk/rest/v2_0/urls/"+vaCode+"/instructions?api_key=" + apiKey
httpRequest = requests.Session()
headers = {
"Content-Type": "application/json"
}
response = httpRequest.request("GET", url, headers=headers)
instructionsResponse = json.loads(response.text)
print(json.dumps(instructionsResponse, indent=2))
const axios = require("axios");
let apiKey = "<API_KEY>";
// The unique tracking reference of your dynamic URL
let vaCode = "<VA_CODE>";
let config = {
method: "get",
url:
"https://www.reports.mediahawk.co.uk/rest/v2_0/urls/" +
vaCode +
"/instructions?api_key=" +
apiKey,
headers: {
"Content-type": "application/json",
},
};
axios(config)
.then((response) => {
console.log(JSON.stringify(response.data, null, 2));
})
.catch((error) => {
console.log(error);
});
using RestSharp;
using Newtonsoft.Json;
string apiKey = "<API_KEY>";
// The unique tracking reference of your dynamic URL
string vaCode = "<VA_CODE>";
var restClient = new RestClient("https://www.reports.mediahawk.co.uk");
restClient.Timeout = -1;
var instructionsRequest = new RestRequest("/rest/v2_0/urls/"+vaCode+"/instructions?api_key=" + apiKey, Method.GET);
instructionsRequest.AddHeader("Content-Type", "application/json");
instructionsRequest.AddHeader("Accept", "application/json");
IRestResponse instructionsResponse = restClient.Execute(instructionsRequest);
var instructionsObject = JsonConvert.DeserializeObject<dynamic>(instructionsResponse.Content);
Console.WriteLine(instructionsObject);
The response will appear here
Update your website
The final step is to add the code to the website. This can be done easily through Google Tag Manager or directly in the HTML. The process is explained on our support site.