The JS SDK tracks customer activity as events and sends them to Synerise in real time. Page views and sessions are tracked automatically. You can also send custom events for any action you want to record.
Every event consists of an action in the form context.activity (for example, page.visit) and optional parameters. The SDK automatically enriches every event with browser and tracker context, even when no parameters are explicitly passed. For the list of these parameters, see Common parameters.
Authentication
Requests to the SDK may require customer authentication. For more details, see this article.
Automatically tracked activities
Page view and session events are tracked automatically, unless configured otherwise (see Getting started).
Each time a page is refreshed, the tracking code is initiated and a page.visit event is generated. For single-page applications that do not refresh between pages, you must send page.visit on demand - see "Send a page.visit event" method.
List of automatically tracked activities
The following events are tracked by default:
| Action | Activity Tracked | Label |
|---|---|---|
| page.visit | All page views of your tracked domain | Visited page {{page title}} |
| session.start | Information about a customer starting a session | Started session |
| session.end | Information about a customer ending a session | Session end |
When Google Data Layer is configured, the following events are tracked in addition to the defaults above - see Transactions and basket events for setup details:
| Action | Activity Tracked |
|---|---|
| product.addToCart | Product added to cart |
| product.removeFromCart | Product removed from cart |
| transaction.charge | Purchase recorded |
| product.buy | One event per purchased item (created together with transaction.charge) |
Declarative tracking (custom events)
DO NOT use custom events for transaction.charge events. Transactions must be tracked as described in Transactions and basket events.
Use custom events to track any customer action not covered by automatic tracking, such as button clicks or form submissions.
When using the JS SDK, you can only send custom events that are defined in Data Modeling Hub > Events and have at least the Make this event available to anonymous profiles without JWT option selected in their permission settings.
Events with action names that are not defined in the system are rejected.
Example:
SR.event.trackCustomEvent(
"button.click", // event action name
{ // optional parameters — define your own
"customParam1": "value1",
"customParam2": "value2",
"time": 1556474400000 // if provided, the event is recorded in the past with this timestamp; if omitted, the SDK sets the timestamp automatically
}
)
The method takes two arguments:
- The name of the action (line 2)
An object that contains optional event parameters (lines 3-7)
- The action name must follow the
context.actionconvention. For example:button.click,social.share - The action name must be up to 32 characters long and must match the following regular expression:
^[a-zA-Z0-9\.\-_]+$
- The action name must follow the