track method
Start/refresh the active session and return its server sessionId.
Implementation
Future<String?> track({Map<String, Object?>? context}) async {
NexusLog.debug(
'sessions.track — deviceKey=${_id.deviceKey}, sessionKey=${_id.sessionKey}'
'${_id.distinctId != null ? ', distinctId=${_id.distinctId}' : ' (anonymous)'}',
);
final res = await _http.post('/partner/sessions/track', {
if (_id.distinctId != null) 'distinctId': _id.distinctId,
'deviceKey': _id.deviceKey,
'sessionKey': _id.sessionKey,
if (_cfg.appVersion != null) 'appVersion': _cfg.appVersion,
..._id.wireContext,
...?context,
});
final sessionId =
res?['data']?['sessionId'] as String? ?? res?['sessionId'] as String?;
if (sessionId != null) {
NexusLog.info('session tracked → $sessionId');
} else if (res == null) {
NexusLog.warn(
'session track failed — no session created (see the request error above)',
);
} else {
NexusLog.warn('session track returned no sessionId — response: $res');
}
return sessionId;
}