## Related terms

- tracking\-code
- event

See the [glossary](/glossary.md) for definitions.

---

# Event tracking


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](/docs/assets/events/event-reference/common-parameters).

## Authentication

Requests to the SDK may require customer authentication. For more details, see [this article](/developers/web/jwt-auth).

## Automatically tracked activities

Page view and session events are tracked automatically, unless configured otherwise (see [Getting started](/developers/web/installation-and-configuration)). 

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](/developers/web/methods-reference#send-a-pagevisit-event).

### List of automatically tracked activities

The following events are tracked by default:

| Action        | Activity Tracked                                | Label                       |
|:--------------|:------------------------------------------------|:----------------------------|
| [page.visit](/docs/assets/events/event-reference/web-and-app#pagevisit)    | All page views of your tracked domain           | Visited page {{page title}} |
| [session.start](/docs/assets/events/event-reference/web-and-app#sessionstart) | Information about a customer starting a session | Started session             |
| [session.end](/docs/assets/events/event-reference/web-and-app#sessionend)   | 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](/developers/web/transactions-sdk) for setup details:

| Action                 | Activity Tracked                                                          |
|:-----------------------|:--------------------------------------------------------------------------|
| [product.addToCart](/docs/assets/events/event-reference/items#productaddtocart)      | Product added to cart                                                     |
| [product.removeFromCart](/docs/assets/events/event-reference/items#productremovefromcart) | Product removed from cart                                                 |
| [transaction.charge](/docs/assets/events/event-reference/items#transactioncharge)     | Purchase recorded                                                         |
| [product.buy](/docs/assets/events/event-reference/items#productbuy)            | One event per purchased item (created together with `transaction.charge`) |


## Declarative tracking (custom events)


<div class="admonition admonition-warning"><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 9v2m0 4h.01m-6.938 4h13.856c1.54 0 2.502-1.667 1.732-2.5L13.732 4c-.77-.833-1.964-.833-2.732 0L4.082 16.5c-.77.833.192 2.5 1.732 2.5z" /></svg></div><div class="admonition-body"><div class="admonition-content">

DO NOT use custom events for `transaction.charge` events. Transactions must be tracked as described in [Transactions and basket events](/developers/web/transactions-sdk).

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


Use custom events to track any customer action not covered by automatic tracking, such as button clicks or form submissions.


<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">

When using the JS SDK, you can only send custom events that are defined in [**Data Modeling Hub > Events**](/docs/assets/events/event-definitions) and have at least the **Make this event available to anonymous profiles without JWT** option selected in their permission settings.  <br>

Events with action names that are not defined in the system are rejected.

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


**Example:**

<pre><code class="language-javascript">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
    }
)</code></pre>


The method takes two arguments:

+ The name of the action (line 2)
+ An object that contains optional event parameters (lines 3-7)


<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">

- The action name must follow the `context.action` convention. 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\.\-_]+$
    ```

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


