|Help Centre

Can I use the Freespee script in my single-page app?

Last updated at

Yes, but you will need to trigger an execution when a new page is loaded manually. It can be done using the trackPage method on the __fs_dncs_instance object.

In the root of your project add the snippet as usual but halt execution by adding the autoInvoke=false option.

<script type="text/javascript">
    var __fs_conf = __fs_conf || [];
    __fs_conf.push(['setAdv',{'id':'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx'}]);
    __fs_conf.push(['autoInvoke', false]);
</script>
<script type="text/javascript" src="//url/js/external/fs.js"></script>

On every page load (including the initial one) you then need to run __fs_dncs_instance.trackPage().

For example, if you're using AngularJS you would put it in the $viewContentLoaded event:

myApp.run(['$rootScope', function($rootScope) {
    $rootScope.$on('$viewContentLoaded', function() {
        __fs_dncs_instance.trackPage();
    });
}]);

If Freespee for some reason is unable to automatically retrieve the current URL of the visitor you can manually send us the URL in the trackpage() function.

 

In order for this to work you need to set the overrideUrl property to the URL the visitor is viewing when sending the trackpage() request.

 

So if you for example call your object "a" then you need to set a.overrideUrl = 'THE URL' and then send us the entire object in the trackpage() function as such:

__fs_dncs_instance.trackPage(a);

Can't find what you're looking for?