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.
Properties
Section titled “Properties”consent
Section titled “consent”
readonlyconsent:ConsentState|null
The consent state the API reported on the last response, or null before one (or from an older server).
readonlyready:Promise<void>
Resolves once the adapter’s stored token, if any, has been read into memory. Awaited by requestFields, so you rarely need it.
readonlytoken:string|null
The current token, held in memory. null before the first response of a visit.
Methods
Section titled “Methods”forget()
Section titled “forget()”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.
Parameters
Section titled “Parameters”Pick<SdkForm, "submissionUrl">
doFetch?
Section titled “doFetch?”(input, init?) => Promise<Response>
Returns
Section titled “Returns”Promise<string | null>
receive()
Section titled “receive()”receive(
responseBody):void
Reads visitor and consent from a render or submission response and applies the storage rules.
Parameters
Section titled “Parameters”responseBody
Section titled “responseBody”unknown
Returns
Section titled “Returns”void
requestFields()
Section titled “requestFields()”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.
Returns
Section titled “Returns”Promise<{ consent: { cmp: "granted" | "denied" | null; cmpString: string | null; dnt: boolean; gpc: boolean; }; visitor: string; }>
setConsent()
Section titled “setConsent()”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.
Parameters
Section titled “Parameters”options
Section titled “options”Returns
Section titled “Returns”void