Extending the session length

The session lifecycle is handled by the Tracking Tag on the browser side. The session ends 30 minutes after the last user event.

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

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

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

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

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:

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

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 cookie value.
  2. Creates a new session for this visitor which deletes and recreates the _cs_s cookie.
  3. Deletes all information, session, and cookies linked such as custom vars, consent cookie _cs_c, and so on.
  4. Triggers a new pageview.