Skip to content

VisitorSession

What a respondent’s browser holds between the steps of one form, and, only with consent, between visits.

The token lives in memory. This package never writes to localStorage, sessionStorage, a cookie or IndexedDB itself. Putting an identifier on a respondent’s device is “storage” under the ePrivacy rules and needs their consent first, so persistence goes through the optional VisitorStorage adapter you pass, and the session calls its set only when the API reports that recognising the respondent is granted. On a denial, a withdrawal, a forget, or a response that says nothing about consent (an older server), it calls remove.

If you keep the token anywhere yourself, the same rule applies to you: persist it only while recognition is granted and remove it as soon as it is not.

Without a consent option the organization’s default applies. That default is denied until an Owner changes it or you pass a signal from your consent banner, so out of the box nothing is recognised across visits and each page load is a new visitor.

readonly consent: ConsentState | null

The consent state the API reported on the last response, or null before one (or from an older server).


readonly ready: Promise<void>

Resolves once the adapter’s stored token, if any, has been read into memory. Awaited by requestFields, so you rarely need it.


readonly token: string | null

The current token, held in memory. null before the first response of a visit.

forget(form, doFetch?): Promise<string | null>

Asks the API to forget this browser (rotating its id and removing links to details held about it), then clears the token from memory and calls the adapter’s remove. Resolves with the message to show.

Pick<SdkForm, "submissionUrl">

(input, init?) => Promise<Response>

Promise<string | null>


receive(responseBody): void

Reads visitor and consent from a render or submission response and applies the storage rules.

unknown

void


requestFields(): Promise<{ consent: { cmp: "granted" | "denied" | null; cmpString: string | null; dnt: boolean; gpc: boolean; }; visitor: string; }>

The visitor and consent members to merge into a render or submission request body.

Promise<{ consent: { cmp: "granted" | "denied" | null; cmpString: string | null; dnt: boolean; gpc: boolean; }; visitor: string; }>


setConsent(options): void

Replaces the consent signals, for a consent banner’s callback. cmp: 'denied' is a withdrawal: the in-memory token is dropped and the adapter’s remove is called at once.

ConsentOptions

void