|Help Centre

How can I add an event listener?

Last updated at


We've introduced two new callback functions that you can define in the fs.js config:

- setOnScriptReadyFunction (Which is called when the script has loaded and is ready to run)
- setRequestTimerFunction (Which is called when the backend request to get a phone number has been sent to Freespee, to measure how long time the request took)

Below a full example that uses the two new and one existing callback.

<script type="text/javascript">
function scriptIsReady() {
console.log('fs.js is ready');
function backendRequestTimer(start, end) {
console.log('Backend request took: ' + (end - start));
function numberReplaced(element, number, replacedWith) {
console.log(number + " was replaced with " + replacedWith + " in element " + element);
var __fs_conf = __fs_conf || [];
__fs_conf.push(['setAdv',{'id': '<xyz>}]);
__fs_conf.push(['setOnScriptReadyFunction', scriptIsReady]);
__fs_conf.push(['setRequestTimerFunction', backendRequestTimer]);
__fs_conf.push(['addNumberReplacedListener', numberReplaced]);
<script type="text/javascript" src="js/fs.js"></script> 

Did you find this article helpful?

Gold StarGreen LightYellow LightRed Light

Powered by Customer Thermometer

If you still need help you can ask our Support team