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
15
16
SR.event.trackCustomEvent(
    "entries.count", 
    {
        "eventLabel": "entriesCount",
        "lat": "50.0937",
        "lon": "18.5429",
        "object": "Shopping center",
        "shopId": "S198",
        "shopName": "Chicago",
        "zipCode": "60639",
        "street": "W North Ave",
        "time": 1556474400000,
        "entries": 27,
    },
    "Entries count"
)

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()

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"
    },
    { //field mapping
        lastname: "surname",
        firstname: "name",
        email: "email"
    }
)

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 customId instead of email. See non-unique email feature configuration.
SR.event.sendFormData('contact', {
    lastname: "Doe",
    firstname: "John",
    email: "john.doe@synerise.com"
})

Send newsletter agreements

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

SR.event.sendFormData('newsletter', {})

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({...})
😕

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.