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¶
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. Consent is not affected, and
neither is pause: a paused SDK stays paused.
The SDK also starts the evidence over by itself when the app comes back after more than five minutes
in the background, because by then nothing says the same person holds the device. The session id
does not change then; the classification is insufficient again until the session has as many
actions as the
model asks for, 8 with the built-in model. See
Evidence.
Read the current session¶
final info = DeaSdk.instance!.getSessionInfo();
debugPrint(info.session); // current session id, a UUID
debugPrint(info.sdk.version); // SDK version
debugPrint('${info.device.surface}'); // current screen size
getSessionInfo() is a quick read. The screen size it reports stays current when the screen
rotates or the window is resized.
Shut the SDK down¶
dispose() stops capture and releases the SDK. Anything not yet processed is dropped. After
dispose(), DeaSdk.instance is null and DeaSdk.init can start a new instance.
Examples¶
Reset on logout¶
import 'package:dea_sdk/dea_sdk.dart';
import 'package:flutter/material.dart';
Future<void> logout(BuildContext context) async {
await authService.signOut();
DeaSdk.instance?.reset();
if (context.mounted) {
Navigator.of(context).pushNamedAndRemoveUntil('/login', (_) => false);
}
}
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 |