|Help Centre

Can I replace a phone number on click?

Our Call to Action script has the functionality to request a trackable phone number upon the click on a button, via either the built-in "fsButton" or getNumber functionalities. 

fsButton

In this example, the script will not try to find and replace phone numbers on a website automatically but instead request a trackable phone number when the button or link is clicked. 

Below you can find an example of the snippet of code that needs to be added to your standard Freespee script:

        __fs_conf.push(['fsButton', {
                run: true,
                pre: 'Call us!',
                post: ['Phone number: {{phone}}'],
                useLocalPhoneNumber: true
        }]);

All the parameters that are included in the fsButton snippet are mandatory, and {{phone}} is a placeholder for the Freespee trackable phone number. The post attribute is an array that can contain multiple templates in case your website display numbers in multiple ways.

The entire Freespee script will then look similar to the following: 

<script type="text/javascript">
var __fs_conf = __fs_conf || [];
__fs_conf.push(['setAdv',{'id': 'advid'}]);
__fs_conf.push(['fsButton', {
run: true,
pre: 'Call us!',
post: ['Phone number: {{phone}}'],
useLocalPhoneNumber: true
}]);
</script>
<script type="text/javascript" src="//analytics.freespee.com/js/external/fs.js"></script>
 

getNumber

In case you would like to modify the button or link even further, we recommend to use our initial getNumber functionality as this allows for more customisations:

<html>
<
script type="text/javascript"> var __fs_conf = __fs_conf || []; __fs_conf.push(['setAdv',{'id': 'advid'}]); __fs_conf.push(['numberDetection', false]); </script> <script type="text/javascript" src="//analytics.freespee.com/js/external/fs.js"></script>
<p>Number is: <span id="nr" onClick="doOnClick();">Click here to see phone number</span></p> <script> function doOnClick() { var a = document.getElementById('nr'); __fs_dncs_instance.getNumber( function(ref,res) { ref.innerHTML=res.local; }, a, '+44201234567', 'advid' ); } </script>
</html>

In the above script, a click on the button will replace the text with a dynamically generated Freespee number. This script can be implemented to work with your own custom button already in place on your website. By default, the getNumber function will return the input number as a fallback if there ever was an issue replacing the number. If you want to change this behaviour, you can add the setting "__fs_conf.push(['returnInputNumber', false]);" to your configuration to make sure no fallback is done.

Important: Please make sure to add the "__fs_conf.push(['numberDetection', false]);" config to your getNumber script configuration.

Can't find what you're looking for?