---
title: Extending the session length - Web
description: How the Tag works with sessions
lastUpdated: 16 March 2026
source_url:
  html: https://docs.contentsquare.com/en/web/extending-the-session-length/
  md: https://docs.contentsquare.com/en/web/extending-the-session-length/index.md
---

The session lifecycle is handled by the Tracking Tag on the browser side.

The session ends 30 minutes after the last user event.

## Session initialization

To manage the session, the Tag creates a session cookie called `_cs_s` which has its expiration date set to 30 minutes after its initialization. When the tag is executed, it checks for the `_cs_s` cookie:

* If the cookie does not exist, it will increment the session number (stored in the `_cs_id` cookie) and will create the session cookie `_cs_s`
* If the cookie already exists, it will only update the expiration date (now +30 minutes).

## Session update

When a **pageview event** (natural or artificial) or a **user event** is triggered, the `_cs_s` cookie expiration date is updated (+30 minutes).

## Extending the session

To artificially extend the session duration, use the `extendSession` command:

```html
<script type="text/javascript">
  window._uxa = window._uxa || [];
  window._uxa.push(["extendSession"]);
</script>
```

When this command is called the Tag starts a process which:

* **Updates the expiration date of the session cookie** `_cs_s` to 30 minutes after the process is run
* **Sends a dynamic variable** with the key `session_expiry_update` and the process iteration number as value so that the Contentsquare data pipeline knows that the session should not be closed (example `{session_expiry_update: 2}`).

This process will run every 29 minutes:

* As long as the session length has not reached 4 hours (maximum duration of a session), counting from the beginning of the session, not the moment the command executed.
* Until a new **pageview event** is triggered (natural or artificial). The process is then stopped and the session management goes back to its normal behavior.

Thanks to this process, **the command only has to be called once per pageview.**

## Clear previous visitors data

Use the `session:clear:visitor` command to clear all data linked to previous visitors:

* Cvars
* Consent
* Exclusion
* Visitor ID
* Page number
* Session number

The command must be pushed **before the Tag starts**:

```html
<script type="text/javascript">
  (function () {
    window._uxa = window._uxa || [];
    window._uxa.push(["session:clear:visitor"]);
    var mt = document.createElement("script");
    mt.type = "text/javascript";
    mt.async = true;
    mt.src = "//t.contentsquare.net/uxa/YOUR_TAG_ID.js";
    document.getElementsByTagName("head")[0].appendChild(mt);
  })();
</script>
```

## Create a new visitor

Use the `session:start:newVisitor` command to trigger the creation of a new visitor.\
The `session:start:newVisitor` command:

1. Creates a new visitor by deleting and replacing the [`_cs_id`](https://docs.contentsquare.com/en/web/cookies/#_cs_id) cookie value.
2. Creates a new session for this visitor which deletes and recreates the [`_cs_s`](https://docs.contentsquare.com/en/web/cookies/#_cs_s) cookie.
3. Deletes all information, session, and cookies linked such as custom vars, consent cookie [`_cs_c`](https://docs.contentsquare.com/en/web/cookies/#_cs_c), and so on.
4. Triggers a new pageview.
