

<div class="admonition admonition-tip"><div class="admonition-icon"><svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2.5"><path stroke-linecap="round" stroke-linejoin="round" d="M9.663 17h4.673M12 3v1m6.364 1.636l-.707.707M21 12h-1M4 12H3m3.343-5.657l-.707-.707m2.828 9.9a5 5 0 117.072 0l-.548.547A3.374 3.374 0 0014 18.469V19a2 2 0 11-4 0v-.531c0-.895-.356-1.754-.988-2.386l-.548-.547z" /></svg></div><div class="admonition-body"><div class="admonition-content">

We recommend creating the tracking code with the creator, as described in this article. However, if you're looking for the legacy method or need to edit an existing tracking code without the creator, see [Advanced tracking code settings](/developers/web/advanced-tracking-code).

</div></div></div>


## What is Synerise Web SDK

Synerise Web SDK (Software Development Kit) is a JavaScript library that allows you to integrate Synerise on your website. This library (SDK) is responsible for data exchange between Synerise and the website into which it is implemented. Thanks to the SDK, we not only send data ([events](/docs/assets/events)) but also download data to show [dynamic content campaigns](/docs/campaign/dynamiccontent). The SDK is also responsible for customer identification, which means that SDK assigns a UUID for anonymous users on your website, if they already have a UUID, it recognizes them.

If the visitor's User Agent matches any of those used by Googlebot, the SDK doesn't initialize. This means that Googlebot's page crawling visits don't generate any Dynamic Content, events, or Profiles.

### How to implement Synerise Web SDK?

By [adding a tracking code into the source code of your website](#creating-a-tracking-code).  

### What can the tracking code do?
The tracking code's permissions are designed to be restrictive, so the code can be included in the source code of your website without risk to your infrastructure or the personal data of your visitors.

It enables the following features:
- You can display [Dynamic Content](/docs/campaign/dynamiccontent) on the page.  
    Profile data, such as name or date of birth, can be added to the Dynamic Content with Jinjava inserts.  
    Only the data of the profile whose UUID is stored in the cookies can be used.
- You can send events.  
    By default, [page.visit](/docs/assets/events/event-reference/web-and-app#pagevisit) events are tracked automatically.  
    Other events can be sent with [declarative tracking](/developers/web/event-tracking#declarative-tracking-custom-events).
- You can [identify users on your website](/developers/web/user-identification).  
    When a visitor enters your site for the first time or after clearing their cookies, the SDK generates a random UUID and an anonymous profile is created. If that user becomes recognized (for example, by sending a login form), it may be [merged with an existing recognized profile](/docs/crm/profile-merge).
- Events sent by SDK requests can modify profiles if you allow it.  
    To edit the list of events which can modify profile data, see [Event authentication settings](/docs/assets/events/event-settings).
- The tracker key (part of the tracking code) can be used to authenticate customer-oriented requests to the [Recommendations](/developers/api/recommendations) and [Search](https://developers.synerise.com/AISearch/) APIs. This can be used to generate personalized recommendation and search results.
- You can use [all methods provided by Synerise SDK](/developers/web/methods-reference).
- You can also:
    - [track cart status](/developers/web/cart). 
    - [send form data](/developers/web/tracking-form-data/tracking-form-data-sdk).  
        
      <div class="admonition admonition-important"><div class="admonition-icon"><svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2.5"><path stroke-linecap="round" stroke-linejoin="round" d="M12 8v4m0 4h.01M21 12a9 9 0 11-18 0 9 9 0 0118 0z" /></svg></div><div class="admonition-body"><div class="admonition-content">

      By default, sending form data with the SDK requires [JWT authentication](/developers/web/jwt-auth). If you want to change that, follow the instructions in ["Sending form data with JS SDK"](/developers/web/tracking-form-data/tracking-form-data-sdk).

      </div></div></div>

    - [send transaction events](/developers/web/transactions-sdk).
    - [send the status of newsletter agreements](/developers/web/newsletter-agreements#javascript-sdk). 


  The code **can't be used to**:
- Access the details or settings of your workspace.
- Authenticate API requests, except for recommendation and search results.
- Explicitly request personal data of customers.  
    The SDK identifies the visitor by their UUID from the cookies. It can't access the visitor's Synerise profile directly (personal data from the profile can be displayed with Dynamic Content) or access the data of other profiles.

## Prerequisites

- If you use a custom tracking domain, prepare DNS entries for it. See [Custom tracking domain](/developers/web/first-party-tracking).
- Add the following domains to the allowlist in your Content Security Policy:
    - `*.synerise.com`
    - `*.snrcdn.net`
    - `*.snrbox.com` - If you use a custom tracking domain, you can skip this entry.
    - `*.snrlink-page.com`
    - `fcm.googleapis.com` - This is only required for Web Push.

## Creating a tracking code
---

1. Go to <img src="/api/docs/image/54176ad07f146575310749eba44b7c2f42c1b327/icons/settings-icon.svg" alt="Settings icon" class="icon"> **Settings > Tracking Codes > Add tracking code**.  
    **Result**: The tracking code creation form opens.  
    <figure><img src="/api/docs/image/54176ad07f146575310749eba44b7c2f42c1b327/docs/settings/tool/_gfx/tracking-code-blank.png" class="large" alt="Tracking code creation form"><figcaption>Tracking code creation form</figcaption></figure>
2. In **Tracking code name**, enter the name.  
    It's used for identifying the code on the list of tracking codes. 
3. In **Domain name**, enter the domain where the code will be used.
    This setting **doesn't affect tracking or cookies** - its purpose is to identify the code.
4. Select the type of page where you want to implement the code.  
    
   <div class="admonition admonition-important"><div class="admonition-icon"><svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2.5"><path stroke-linecap="round" stroke-linejoin="round" d="M12 8v4m0 4h.01M21 12a9 9 0 11-18 0 9 9 0 0118 0z" /></svg></div><div class="admonition-body"><div class="admonition-content">

   If you choose **Single Page App**, you will need to manually implement page visit events and dynamic content after you include the tracking code in the page. This is described further in the article.

   </div></div></div>

5. If you use Google data layer, enable the toggle and select the version.  
    If your site uses multiple versions, you can only choose one for use with Synerise tracking.
6. If you use a custom tracking domain, enable **Custom domain tracking** and enter the domain in the field that appears.  
    
   <div class="admonition admonition-important"><div class="admonition-icon"><svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2.5"><path stroke-linecap="round" stroke-linejoin="round" d="M12 8v4m0 4h.01M21 12a9 9 0 11-18 0 9 9 0 0118 0z" /></svg></div><div class="admonition-body"><div class="admonition-content">

   Using a custom tracking domain requires additional configuration. See [Custom tracking domain](/developers/web/first-party-tracking).

   </div></div></div>

7. This completes the basic settings. 
    - If you don't need additional settings, continue to [Adding the tracking code to your site](#adding-the-tracking-code-to-your-site).
    - If you need additional settings, continue to [Additional options](#additional-options).

### Additional options


<div class="admonition admonition-tip"><div class="admonition-icon"><svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2.5"><path stroke-linecap="round" stroke-linejoin="round" d="M9.663 17h4.673M12 3v1m6.364 1.636l-.707.707M21 12h-1M4 12H3m3.343-5.657l-.707-.707m2.828 9.9a5 5 0 117.072 0l-.548.547A3.374 3.374 0 0014 18.469V19a2 2 0 11-4 0v-.531c0-.895-.356-1.754-.988-2.386l-.548-.547z" /></svg></div><div class="admonition-body"><div class="admonition-content">

If you want to manually add these options to an existing tracking code, see [Advanced tracking code settings](/developers/web/advanced-tracking-code).

</div></div></div>


1. Expand **Additional options**.
2. Configure the settings that you need:

#### Custom cookie expiration time
By default, cookies expire after 400 days. To change the expiration time, enable the toggle and enter the period.
#### Override cookie domain
If you use several subdomains, they generate cookies with their own domain. To declare a specific domain instead, enable the toggle and enter the domain.
#### Disable automatic tracking of page visits
You can disable automatic collection of `page.visit` events. You can re-implement the events by using the [SDK methods](/developers/web/event-tracking).  
        
<div class="admonition admonition-important"><div class="admonition-icon"><svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2.5"><path stroke-linecap="round" stroke-linejoin="round" d="M12 8v4m0 4h.01M21 12a9 9 0 11-18 0 9 9 0 0118 0z" /></svg></div><div class="admonition-body"><div class="admonition-content">

For Single-Page Applications, this option is always enabled.

</div></div></div>

#### Custom service worker scope
If you use Synerise Web push notifications and need to set a custom service worker scope (registration path), enable the toggle and enter the path. 
#### Customizing metadata
You can add `<meta>` tags (for example, OG tags) to the website or modify existing ones. The new values are added to `page.visit` events. They can also be used with other features based on metadata, such as communication, recommendations, personalization, and so on. To add the metadata, enable the toggle and paste JS code inside the `function (metadata)` function.  

<div class="admonition admonition-note"><div class="admonition-icon"><svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2.5"><path stroke-linecap="round" stroke-linejoin="round" d="M13 16h-1v-4h-1m1-4h.01M21 12a9 9 0 11-18 0 9 9 0 0118 0z" /></svg></div><div class="admonition-body"><div class="admonition-content">

If you chose **Shopify** as the page type, a piece of Jinjava required for the integration is already added to the metadata and this option can't be disabled.

</div></div></div>


**Example**:  
    
<pre><code class="language-LANG">function (metadata) { // DO NOT REMOVE
    metadata.size = 8;
    metadata.isExample = true;
    metadata['og:title'] = 'Sneakers';
    metadata['product:retailer_part_no'] = '1a4d3380-04d1';
    return metadata; // DO NOT REMOVE
    }                // DO NOT REMOVE</code></pre>


Syntax usage:
- If the name of the meta key doesn't contain special characters, use the `metadata.keyName = 'keyValue'` syntax.
- If the name of the meta key contains special characters, use the `metadata['key_name'] = 'keyValue'` syntax.
- Up to 20 meta parameters can be returned.
- The following value types are allowed:
    - string
    - number
    - boolean
    - array

#### Manage some Synerise features
You can turn off Web push notifications and/or Dynamic Content by disabling the toggles.  
The feature or features will be disabled entirely for this tracking code and **can't be restored with SDK methods**.

## Adding the tracking code to your site

1. After you complete the configuration, click **Generate**.  
    **Result**: The tracking code is generated and displayed.  
    <figure><img src="/api/docs/image/54176ad07f146575310749eba44b7c2f42c1b327/docs/settings/tool/_gfx/tracking-code-summary.png" class="large" alt="A screenshot of a generated tracking code"><figcaption>An example generated tracking code for a Web page</figcaption></figure>
2. Continue depending on the selected page type:  
    
   <div class="content-tabs" data-tab-group="tabgrp-1234">
   <div class="tab-buttons"><button class="tab-button" data-tab-id="tabgrp-1234-0" data-tab-group="tabgrp-1234" data-tab-active="true">Web page</button><button class="tab-button" data-tab-id="tabgrp-1234-1" data-tab-group="tabgrp-1234">Single page app</button><button class="tab-button" data-tab-id="tabgrp-1234-2" data-tab-group="tabgrp-1234">VTEX</button><button class="tab-button" data-tab-id="tabgrp-1234-3" data-tab-group="tabgrp-1234">Shopify</button></div>

   <div class="tab-panel" data-tab-id="tabgrp-1234-0" data-tab-group="tabgrp-1234" data-tab-active="true">

   1. Copy the tracking code.
   2. Paste the code into your website, before the closing `</body>` tag.  
       You can use Google Tag Manager to do this (when using a custom tracking domain this is **not** recommended).
   3. If you enabled the custom tracking domain, make sure it's added to the DNS and API methods as described in [Custom tracking domain](/developers/web/first-party-tracking).

   </div>

   <div class="tab-panel" data-tab-id="tabgrp-1234-1" data-tab-group="tabgrp-1234">

   1. Copy the tracking code.
   2. Paste the code into your website, before the closing `</body>` tag.  
       You can use Google Tag Manager to do this (when using a custom tracking domain this is **not** recommended).
   3. If you enabled the custom tracking domain, make sure it's added to the DNS and API methods as described in [Custom tracking domain](/developers/web/first-party-tracking).
   3. Re-enable page visit tracking and Dynamic Content retrieval by implementing the following methods in the page:

      <pre><code class="language-js">SR.event.pageVisit()
          .then(function () {
              SR.dynamicContent.get();
      })</code></pre>


   <div class="admonition admonition-important"><div class="admonition-icon"><svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2.5"><path stroke-linecap="round" stroke-linejoin="round" d="M12 8v4m0 4h.01M21 12a9 9 0 11-18 0 9 9 0 0118 0z" /></svg></div><div class="admonition-body"><div class="admonition-content">

   Page visits and dynamic content retrieval must be implemented according to the following rules:
   - og:tags must be loaded first, regardless of the method that is used to load them.
   - page visits and dynamic content must be requested whenever the page is loaded, reloaded, and when the view changes.

   </div></div></div>



   <div class="admonition admonition-tip"><div class="admonition-icon"><svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2.5"><path stroke-linecap="round" stroke-linejoin="round" d="M9.663 17h4.673M12 3v1m6.364 1.636l-.707.707M21 12h-1M4 12H3m3.343-5.657l-.707-.707m2.828 9.9a5 5 0 117.072 0l-.548.547A3.374 3.374 0 0014 18.469V19a2 2 0 11-4 0v-.531c0-.895-.356-1.754-.988-2.386l-.548-.547z" /></svg></div><div class="admonition-body"><div class="admonition-content">

   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 or DOM being loaded. `SR.init` is only called when DOM is loaded.

   </div></div></div>

   </div>

   <div class="tab-panel" data-tab-id="tabgrp-1234-2" data-tab-group="tabgrp-1234">

   For VTEX, 2 variants of the tracking code are generated.  
   1. Add the codes to the VTEX pages as described in [Integration for stores using Store Framework](/docs/settings/tool/vtex/vtex-integration).
   2. If you enabled the custom tracking domain, make sure it's added to the DNS and API methods as described in [Custom tracking domain](/developers/web/first-party-tracking).

   </div>

   <div class="tab-panel" data-tab-id="tabgrp-1234-3" data-tab-group="tabgrp-1234">

   For Shopify, 2 variants of the tracking code are generated.  
   1. Add the tracking code to the Shopify page according to the [Shopify integration instructions](/docs/settings/tool/integrating-shopify-with-synerise#implement-tracking-codes-in-your-shop).
   2. If you enabled the custom tracking domain, make sure it's added to the DNS and API methods as described in [Custom tracking domain](/developers/web/first-party-tracking).

   </div>
   </div>


## Nonce for Content Security Policies

Nonce (number used once) is a content attribute which can be used by Content Security Policies (CSPs) to determine if an element should be allowed. If a script doesn't have a nonce value that matches the one expected by the CSP, the script can't execute.

You can add the nonce to the Synerise SDK initialization script:

<pre><code class="language-js">SR.init({
  trackerKey: "VALUE",
  nonce: "VALUE"
});</code></pre>


The tracking code and any scripts that the SDK adds to the page (for example, in Dynamic Content) will have the nonce value that you add to `SR.init`


<div class="admonition admonition-important"><div class="admonition-icon"><svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2.5"><path stroke-linecap="round" stroke-linejoin="round" d="M12 8v4m0 4h.01M21 12a9 9 0 11-18 0 9 9 0 0118 0z" /></svg></div><div class="admonition-body"><div class="admonition-content">

You must generate the value of the nonce yourself and make sure it matches the one expected by the CSP.

</div></div></div>


For more details on nonce and implementing it, see [MDN Web Docs](https://developer.mozilla.org/en-US/docs/Web/HTML/Global_attributes/nonce).