> ## Documentation Index
> Fetch the complete documentation index at: https://docs.cevoid.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Session Tracking

> Enable Cevoid session tracking and verify when session IDs are attached to analytics events.

Use this page when you want Cevoid to attach session IDs to tracked events. If you only need the exact consent and cookie rules, use [Consent](./consent) instead.

Session tracking is optional. Without it, the SDK still sends events, but those events do not include a Cevoid `session_id`.

## Why this matters

Session tracking is what allows Cevoid to connect supported gallery activity and completed orders.

That means:

* when you enable session tracking together with sales tracking, Cevoid can measure attribution between Cevoid widget interactions and a completed order when consent resolves to granted
* when you enable session tracking without sales tracking, Cevoid can still measure gallery and card behavior, but there is no completed order to connect those interactions to
* when you enable sales tracking without session tracking, the sale can still be recorded, but Cevoid usually cannot connect a Cevoid widget event to that order

In practice, session tracking is usually most valuable when it is enabled together with sales tracking.

## What session tracking adds

When session tracking is enabled and consent resolves to granted, the SDK:

* creates or refreshes `ca_session`
* uses a 30-minute rolling session lifetime
* attaches `session_id` to tracked events

If consent is denied:

* events can still be sent
* `session_id` is omitted

## 1. Turn on session tracking

Enable it in `init()` or in the React component props.

```ts theme={"theme":{"light":"github-light","dark":"github-dark"}}
import { init } from '@cevoid/analytics-sdk'

init({
  publishableKey: 'cev_pk_...',
  enableSessionTracking: true
})
```

React example:

```tsx theme={"theme":{"light":"github-light","dark":"github-dark"}}
import { Analytics as CevoidAnalytics } from '@cevoid/analytics-sdk/react'

export function App() {
  return <CevoidAnalytics publishableKey="cev_pk_..." enableSessionTracking={true} />
}
```

## 2. Configure `cookieDomain` when needed

If your storefront spans subdomains, set `cookieDomain` so `ca_session` is written where you need it.

```ts theme={"theme":{"light":"github-light","dark":"github-dark"}}
init({
  publishableKey: 'cev_pk_...',
  enableSessionTracking: true,
  cookieDomain: '.example.com'
})
```

Use `cookieDomain` when:

* your storefront runs on multiple subdomains
* you want the session cookie shared across those subdomains

## 3. Add the cookie-policy entry when needed

If your storefront requires cookie disclosures before enabling analytics storage, add `ca_session` to your cookie policy before enabling session tracking in production.

Suggested description:

`Collects statistics from the visitor's interaction with Cevoid galleries on the website, such as post views, gallery views, post clicks, product clicks and statistics about order value after checkout.`

## 4. Make sure consent is available

When session tracking is enabled, the SDK checks these consent sources when they are present:

* Shopify Customer Privacy API
* `dataLayer` consent entries for `analytics_storage`
* `window.cevoidTrackingConsent`

On a non-Shopify site with no `dataLayer` consent entry and no `window.cevoidTrackingConsent` value, consent defaults to granted and the SDK can create `ca_session`.

If any present consent source resolves to denied, the SDK still sends events without a Cevoid session ID.

## 5. Verify the session flow

After initialization:

* look for `ca_session` in the browser
* trigger one or more tracked events
* if you use Shopify, GTM consent, or `window.cevoidTrackingConsent`, confirm that your consent source is available before expecting `session_id`

If consent is granted but cookies cannot be written, the SDK falls back to an in-memory session for the current page runtime only.

## Common mistakes

* expecting a session ID without enabling `enableSessionTracking`
* forgetting `cookieDomain` when the storefront spans subdomains
* assuming missing `session_id` means the event was dropped
* on Shopify, testing before the relevant consent source is available

## Related

* [Consent](./consent)
* [Installation](../analytics-sdk/installation)
* [Using Cevoid Galleries](./using-cevoid-galleries)
