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

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