Sign in

Welcome.
How can we help?

Can I replace a phone number on click?

Topic: , Updated:

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 automatically find and replace phone numbers on a website, 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 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 behavior, you can add the setting "__fs_conf.push(['returnInputNumber', false]);" to you 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.

Was this article helpful?
1 out of 2 found this helpful

Comments

  • Avatar
    JC Mengant
    I think the doOnClick function should be : function doOnClick() { var a = document.getElementById('nr'); __fs_dncs_instance.getNumber( function(ref,res) { ref.innerHTML=res.local; }, a, '+44201234567', 'advid' ); }
  • Avatar
    Tobias Lindgren
    Hi! Thanks for helping out, you're right there was a small typo in the example, I've updated it now. Cheers, /Tobias

Not the answer to your question?

Powered by Zendesk