Skip to content

Sessions

Part of the Human Scoring use case.

A session is the stretch of interaction a classification is about. The SDK starts one at init. Tell the SDK when a session ends in a way only your app knows about — a logout or an account switch — so that one user's interaction is never counted toward the next user's classification. It is not the ad session that DEA opens for one ad in the Ads use case.

When to use it

  • The user logs out
  • The user switches accounts
  • You need the current session id, for example to include in a support request

Prerequisites

  • The SDK is installed and initialized. See the Quick Start.

Usage

Start a new session

import { DeaSdk } from '@dea/sdk';

DeaSdk.current?.reset();

reset() ends the current session and starts a new one with a new id. Evidence collected before the reset does not count toward the new session's classification. The scoring model, the consent answer and the browser's key are kept.

Read the current session

import { DeaSdk } from '@dea/sdk';

const info = DeaSdk.current?.getSessionInfo();

console.log(info?.session);      // current session id
console.log(info?.sdk.version);  // SDK version
console.log(info?.device.surface); // current viewport size

getSessionInfo() is a quick read. The device information stays current when the window is resized, zoomed or rotated.

Shut the SDK down

import { DeaSdk } from '@dea/sdk';

DeaSdk.current?.dispose();

dispose() stops capture and releases the SDK. Anything not yet processed or sent is dropped, including ad proofs waiting to be retried. After dispose(), DeaSdk.current is null and init can start a new instance.

Examples

Reset on logout

import { DeaSdk } from '@dea/sdk';

async function logout() {
  await fetch('/api/logout', { method: 'POST' });
  DeaSdk.current?.reset();
  location.assign('/login');
}

API

Member Returns Description
reset() void Ends the session and starts a new one
getSessionInfo() SessionInfo Session id, device and SDK version
dispose() void Stops capture and releases the SDK