Web SDK methods reference

Authentication by JSON Web Token (JWT)

JS SDK calls can be authenticated with JWT. For more details, read this article.

Retrieve current JWT

You can check the current token. If no token is set, the method returns null.

After retrieving the token from the SDK, you can decode it to check the expiration time and details of the customer.

SR.jwt.getAccessToken();

Set JWT

Set a new token when a customer logs in or the old token expires. The method takes one argument: the JWT as a string.

SR.client.setAccessToken('token');

Clear JWT

To log out a user, clear the token.

SR.jwt.clearAccessToken();

Tracking customer actions

Basic method for tracking events

For more details, click here.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
SR.event.trackCustomEvent(
    "entries.count", // event action name
    { // additional parameters
        "lat": "50.0937",
        "lon": "18.5429",
        "object": "Shopping center",
        "shopId": "S198",
        "shopName": "Chicago",
        "zipCode": "60639",
        "street": "W North Ave",
        "time": 1556474400000,
        "entries": 27
    }
)

Re-initialize the tracking code

You can use this method to re-initialize a search for the data-synerise attributes on a page. This is used, for example, in pop-up windows.

SyneriseTC.initFormCatch()

Send a page.visit event

You can send a page.visit event. This is used, for example, in single-page applications. By default, the page.visit event tracks data such as customer UUID, OG tags of the page (if they exist), browser, etc.

SR.event.pageVisit(
  {
    "key": "value" // optional additional parameters
  }
)

Managing customer data

Send form data

This method allows you to send data from an HTML form to the SDK. This event is sent automatically when a customer sends a form. For more details, click here.

SR.event.sendFormData('contact',
    { //form data
        "surname": "Doe",
        "name": "John",
        "email": "john.doe@synerise.com",
        "customParam1": "customValue1",
        "customParam2": "customValue2"
    },
    { //field mapping
        "lastname": "surname",
        "firstname": "name",
        "email": "email",
        "customAttribute1": "customParam1",
        "customAttribute2": "customParam2"
    }
)

Send form data without a form

You can emulate the behavior of a form by calling the SDK directly.

WARNING:
  • If you use the non-unique email feature, use custom_identify instead of email. See non-unique email feature configuration.
  • The SDK does not validate the data. For example, if the customer makes an error in their identifier and sends the form, a new profile with that identifier is created. This may cause the event history of an anonymous customer to be merged into a recognized profile with an error in the identifier, even if the user re-sends the form again with the right identifier. To avoid this, validate the entered data before sending the form.
SR.event.sendFormData('formType', {
    lastname: "Doe",
    firstname: "John",
    email: "john.doe@synerise.com",
    customAttribute: "customAttributeValue" // saved in the `attributes` object of a Profile
    // more attributes and custom attributes
})

You can replace formType with another value or a number of comma-separated values (no spaces). These values are saved as formType in the event and as tags in the customer’s Profile.

Send newsletter agreements

You can use this method to send a customer’s newsletter agreements. For more details, click here.

SyneriseTC.sendFormData('newsletter', {
    // depending on the configuration, email (default) or customId is used as the identifier
    email:'john.doe@synerise.com',
    firstname:'John'
    }
)

Tracking transactions

Transactions can be tracked using Google Data Layer or sent to the Synerise tracker, which uses an identical format.

Send a “product added to cart” event

dataLayer.push({
    'event': 'addToCart',
    'ecommerce': {
        'currencyCode': 'EUR',
        'add': {
            'products': [{
                'name': 'Triblend Android T-Shirt',
                'id': '12345',
                'price': '15.25',
                'brand': 'Google',
                'category': 'Apparel',
                'variant': 'Gray',
                'quantity': 1
            }]
        }
    }
})

Send a “product removed from cart” event

dataLayer.push({
    'event': 'removeFromCart',
    'ecommerce': {
        'remove': {
            'products': [{
                'name': 'Triblend Android T-Shirt',
                'id': '12345',
                'price': '15.25',
                'brand': 'Google',
                'category': 'Apparel',
                'variant': 'Gray',
                'quantity': 1
            }]
        }
    }
})

Send purchase details

dataLayer.push({
    'ecommerce': {
        'purchase': {
            'actionField': {
                'id': 'T12345',
                'affiliation': 'Online Store',
                'revenue': '35.43',
                'tax': '4.90',
                'shipping': '5.99',
                'coupon': 'SUMMER_SALE'
            },
            'products': [{
                    'name': 'Triblend Android T-Shirt',
                    'id': '12345',
                    'price': '15.25',
                    'brand': 'Google',
                    'category': 'Apparel',
                    'variant': 'Gray',
                    'quantity': 1,
                    'coupon': ''
                },
                {
                    'name': 'Donut Friday Scented T-Shirt',
                    'id': '67890',
                    'price': '33.75',
                    'brand': 'Google',
                    'category': 'Apparel',
                    'variant': 'Black',
                    'quantity': 1
                }
            ]
        }
    }
})

Enable syneriseLayer transaction tracking

You can use this method for transaction tracking if you’re not using Google Data Layer.

SR.init({
    "trackerKey":"XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX",
    "dataLayer": window["syneriseLayer"] = []
});

Send a transaction to syneriseLayer

syneriseLayer queries are formatted in the same way as Google Data Layer queries.

syneriseLayer.push({...})

Tracking campaign interactions

Send a “dynamicContent.show” event

By default, the dynamicContent.show event is tracked automatically when a Dynamic Content campaign is displayed to the visitor.

If the the event is not tracked automatically for your campaign, you can send it using the dedicated method below. This lets you build analytics and measure the performance of your communication.

SR.event.dynamicContentShow(
  {
    "id": "value", // campaign ID
    "variantId": "value", // variant ID
    "key": "value" // optional additional parameters
  },
  "Dynamic content was displayed"
)

Send a “dynamicContent.click” event

The dynamicContent.click event is tracked automatically when a link or a button from Dynamic Content campaign is clicked by the Profile.

If the the event is not tracked automatically for any link in your campaign, you can send it using the dedicated method below. This lets you build analytics and measure the performance of your communication.

SR.event.dynamicContentClick(
  {
    "id": "value", // campaign ID
    "variantId": "value", // variant ID
    "key": "value" // optional additional parameters
  },
  "Dynamic content was clicked" // Optional label, not saved in persistent storage
)

Send a “recommendation.view” event

By default, the recommendation.view event is tracked automatically when a recommended items are displayed to a visitor within the Dynamic Content campaign.

If the the event is not tracked automatically for your campaign, you can send it using the dedicated method below. This lets you build analytics and measure the performance of your communication.

SR.event.recommendationView(
  {
    "campaignId": "value", // ID of the recommendation campaign related to the event
    "correlationId": "value", // correlation ID of the response from recommendation campaign. Its value is included in the links to recommended items
    "items": ["value", "value"], // an array of items included in the recommendation 
    "key": "value" // optional additional parameters
  },
  "Recommended items were displayed" // Optional label, not saved in persistent storage
)

Send a “recommendation.click” event

By default, the recommendation.click event is tracked automatically when a recommended item is clicked by the Profile within the Dynamic Content campaign.

If the the event is not tracked automatically for the links to reccommended items in your campaign, you can send it using the dedicated method below. This lets you build analytics and measure the performance of your communication.

SR.event.recommendationClick(
  {
    "campaignId": "value", // ID of the recommendation campaign related to the event
    "correlationId": "value", // correlation ID of the response from recommendation campaign. Its value is included in the links to recommended items
    "item": "value", // ID of the clicked item (also called `sku`, `productId`, and `retailer_part_no`) 
    "key": "value" // optional additional parameters
  },
  "Recommended item was clicked" // Optional label, not saved in persistent storage
)

Send a “item.search.click” event

You can send the item.search.click event using the dedicated method below. The event should be sent when a visitor clicks an item in AI search results. This lets you build analytics and measure the performance of your communication.

SR.event.itemSearchClick(
  {
    "correlationId": "value", // correlation ID of the response from AI search. Its value is included in the links to returned items
    "item": "value", // ID of the clicked item (also called sku, productId, and retailer_part_no) 
    "position": 1, // position of the clicked item in the result list (count starts with 1)
    "searchType": "autocomplete", // type of the search. The value can be "full-text-search" or "autocomplete"
    "key": "value" // optional additional parameters
  },
  "An item in search results was clicked" // Optional label, not saved in persistent storage
)

Dynamic content

Get campaigns rendered on current page

You can retrieve the data of campaigns that were rendered on the current page.

SR.dynamicContent.getRendered()

The output is an array of Dynamic Content campaigns that were rendered on the current page. Each object contains metadata of the campaign, such as its UUID, capping, triggers, variants, and so on. The variant object stores the HTML, JS, and CSS content of the campaign, with Inserts already processed.

Get campaign content on demand

You can retrieve the content of a single Dynamic Content campaign. The campaign must be active.

SR.dynamicContent.get("campaignUuid")

The command makes an API request to fetch the campaign. The response contains the HTML, JS, and CSS (with inserts already processed) of the campaign in the variants array, in the content object of a variant.

Example:
Use the following method to retrieve the content of the Dynamic Content campaign that displays the search box on top of this page:

SR.dynamicContent.get("23c47a51-8d63-42c4-8f83-9c5352532732")

😕

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.

Close modal icon Placeholder alt for modal to satisfy link checker