Installation and configuration

Synerise works on customers’ online and offline data.
To analyze the activity of your customers, you need to track their actions on the website. You can do this by embedding tracking codes in your pages. You can also use Google Tag Manager.
If you have a web app with multiple pages, where each one triggers a new page refresh, you will most likely need the basic JavaScript method.

Embedding a tracking code in page source

Paste the tracking code before the </body> closing tag of your website.

Important: If you want to use a custom domain to treat Synerise tracking as first-party, see Third-party tracking blockers.
To apply the custom domain, in the tracking code below replace the default URL of the JS SDK script (//www.snrcdn.net/sdk/3.0/synerise-javascript-sdk.min.js) with the one you received from the Synerise Customer Success & Implementation team.
<script>
    function onSyneriseLoad() {
        SR.init({
            'trackerKey':'XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX',
        });
    }

    (function(s,y,n,e,r,i,se){s['SyneriseObjectNamespace']=r;s[r]=s[r]||[],
     s[r]._t=1*new Date(),s[r]._i=0,s[r]._l=i;var z=y.createElement(n),
     se=y.getElementsByTagName(n)[0];z.async=1;z.src=e;se.parentNode.insertBefore(z,se);
     z.onload=z.onreadystatechange=function(){var rdy=z.readyState;
     if(!rdy||/complete|loaded/.test(z.readyState)){s[i]();z.onload = null;
     z.onreadystatechange=null;}};})(window,document,'script',
     '//www.snrcdn.net/sdk/3.0/synerise-javascript-sdk.min.js','SR', 'onSyneriseLoad');
</script>

Tracking code in Single Page Applications

If your website is a Single Page Application (SPA), the tracking code must be modified. The modification changes the mechanism of sending page visit events and retrieving dynamic content.

  1. Add the highlighted parameters to the initialization:
        function onSyneriseLoad() {
            SR.init({
                'trackerKey':'XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX',
                'customPageVisit': true,
                'dynamicContent': {
                    'virtualPage': true
                }
            });
        }
    
    Result:
    The parameters disable page visit events and dynamic content retrieval.
  2. Re-enable page visit tracking by implementing the SR.event.pageVisit(); method.
    • The method must be called after the page changes and finishes loading.
    • The method must be called after og:tags are added.
  3. Re-enable dynamic content by implementing the SR.dynamicContent.get(); method after the page changes and finishes loading.
    • The method must be called after the page changes and finishes loading.
    • The method must be called after SR.event.pageVisit();
      To ensure this, you can call the methods as a promise:
      SR.event.pageVisit()
          .then(function () {
              SR.dynamicContent.get();
          })
      
Tip: You can use Google Tag Manager to implement the methods. To do so, trigger SR.event.pageVisit(); and SR.dynamicContent.get(); methods on events that indicate a page content refresh. SR.init is only called when DOM is loaded.

Tracking script variants (no custom domain)

We have several variants of our Javascript SDK that you can use depending on the required features.

Fewer features usually result in smaller page size and shorter load times.

Script version URI
default:
Script with all functionalities
synerise-javascript-sdk.min.js
no-cm:
Script without Cookie Matching
synerise-javascript-sdk-no-cm.min.js
no-wp:
Script without WebPush
synerise-javascript-sdk-no-wp.min.js
no-wp-cm:
Script without WebPush and Cookie Matching
synerise-javascript-sdk-no-wp-cm.min.js
no-m-cm-wss:
Script without Cookie Matching, Automation-based Dynamic Content, and WebSockets
synerise-javascript-sdk-no-m-cm-wss.min.js

Additional tracking configuration parameters

The only required parameter during the initialization of the tracking code is the trackerKey parameter.
By using the additional parameters described below, you can modify the configuration of the tracking code.

Google dataLayer

If you are using Google dataLayer, you can connect it with Synerise.
By using Enhanced Ecommerce you can track transaction events.

SR.init({
    'trackerKey':'XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX',
    'dataLayer':dataLayer
});

Sub-domains

If you are using several sub-domains, you can limit tracking to only generate data for particular domains. To do that, add the domain name in the script:

SR.init({
    'trackerKey':'XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX',
    'domain':'.example.com'
});

Automatic tracking of page visits

You can turn off the automatic collection of page visit events with the customPageVisit parameter.
In this case, events should be sent manually using the sdk methods.

SR.init({
    'trackerKey':'XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX',
    'customPageVisit':true
});

Synerise webpush worker scope

If you use Synerise webpush and need to set a custom service worker scope (registration path), you can enter that path as a parameter.

SR.init({
    'trackerKey':'XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX',
    'webpush':{
        'service_worker_scope':'/pl/'
    }
});

Disabling modules

Additionally, if you need to disable some Synerise modules on a specific sub-page or domain, you can do it by specifying the parameters as below:

SR.init({
    'trackerKey':'XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX',
    'disableMessenger':true,
    'disableFormMarker':true,
    'disableWebPush':true,
    'disableDynamicContent':true,
    'disableNotification':true
});

By default, the _snrs_p, _snrs_uuid, and _snrs_puuid cookies expire after 30 years. You can change this by using the cookieExpiration parameter. The value is the number of days after which the cookies expire.

Note: The expiration time of the _snrs_sa and _snrs_sb cookies is 30 minutes and cannot be changed.

The following example sets cookie expiration time to 60 days:

SR.init({ 
    'trackerKey': 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx',
    'cookieExpiration': 60
});

Authentication

Requests to the SDK may require customer authentication. For more details, see this article.

😕

We are sorry to hear that

Thank you for helping improve out documentation. If you need help or have any questions, please consider contacting support.

😉

Awesome!

Thank you for helping improve out documentation. If you need help or have any questions, please consider contacting support.