Sir Filiate tracking JavaScript

The Sir Filiate tracking JavaScript can be used when there is no native plugin/integration available for your platform.


Getting started

On every page on which a customer can enter, add the following code:

<script src="https://scripts.sirfiliate.com/sirfiliate.js" async></script>
<script type="text/javascript">
    (function(s,f){s.SirFiliateTracking=f;s[f]=s[f]||function(){ (s[f].q=s[f].q||[]).push(arguments)}})(window,'sf');

    sf('init', '{{ YOUR_MERCHANT_ID }}');
    sf('detect');
</script>

Tracking a conversion

A conversion is tracked by executing the conversion method on the Sir Filiate tracking object.

A call to the Sir Filiate API will only be made if an affiliate is detected and a cookie is within the expiration days.

<script src="https://scripts.sirfiliate.com/sirfiliate.js" async></script>
<script type="text/javascript">
    (function(s,f){s.SirFiliateTracking=f;s[f]=s[f]||function(){ (s[f].q=s[f].q||[]).push(arguments)}})(window,'sf');

    sf('init', '{{ YOUR_MERCHANT_ID }}');
    sf('conversion', {{ ORDER_AMOUNT_IN_CENTS }}, {{ OPTIONAL_DESCRIPTION }}); // Track conversion
</script>

To change the number of days the cookie will be valid for, use the following code:

<script src="https://scripts.sirfiliate.com/sirfiliate.js" async></script>
<script type="text/javascript">
    (function(s,f){s.SirFiliateTracking=f;s[f]=s[f]||function(){ (s[f].q=s[f].q||[]).push(arguments)}})(window,'sf');

    sf('init', '{{ YOUR_MERCHANT_ID }}');
    sf('setExpireDays', {{ NUMBER_OF_DAYS }}); // Set amount of days until expiration
</script>

If, for whatever reason, you need to use a different cookie key, you can do so by using the setCookieKey function.

<script src="https://scripts.sirfiliate.com/sirfiliate.js" async></script>
<script type="text/javascript">
    (function(s,f){s.SirFiliateTracking=f;s[f]=s[f]||function(){ (s[f].q=s[f].q||[]).push(arguments)}})(window,'sf');

    sf('init', '{{ YOUR_MERCHANT_ID }}');
    sf('setCookieKey', '{{ YOUR_COOKIE_KEY }}'); // Set cookie key
</script>