@nagoorkani/session-capture-core 0.1.2 → 0.1.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/core.d.ts +9 -1
- package/dist/core.js +25 -2
- package/dist/types.d.ts +8 -1
- package/package.json +1 -1
package/dist/core.d.ts
CHANGED
|
@@ -17,7 +17,7 @@ import { type CaptureEvent, type EventBatch, type EventType, type InitOptions, t
|
|
|
17
17
|
* still showed a bug fixed in 0.1.1 could not be told apart from one that had
|
|
18
18
|
* never been updated, from the dashboard or from the logs.
|
|
19
19
|
*/
|
|
20
|
-
export declare const SDK_VERSION = "0.1.
|
|
20
|
+
export declare const SDK_VERSION = "0.1.4";
|
|
21
21
|
/**
|
|
22
22
|
* Idle bound. Nothing for this long and the next event opens a new session.
|
|
23
23
|
*
|
|
@@ -111,6 +111,12 @@ export declare class SdkCore {
|
|
|
111
111
|
applyConfig(config: RemoteConfig): void;
|
|
112
112
|
/** Events discarded because remote config disabled capture. Diagnostics. */
|
|
113
113
|
private dropOnKill;
|
|
114
|
+
/**
|
|
115
|
+
* Who `identify` last named, repeated on every later `session_start` so a
|
|
116
|
+
* rotated session is not anonymous. Memory only: a relaunch or reload
|
|
117
|
+
* forgets it, and the host calls `identify` again once it knows the user.
|
|
118
|
+
*/
|
|
119
|
+
private user;
|
|
114
120
|
get droppedOnKill(): number;
|
|
115
121
|
/** The config currently in force. */
|
|
116
122
|
get remoteConfig(): RemoteConfig;
|
|
@@ -159,6 +165,8 @@ export declare class SdkCore {
|
|
|
159
165
|
mark(name: string): void;
|
|
160
166
|
/** Record time from SDK load to app-ready. */
|
|
161
167
|
markReady(): void;
|
|
168
|
+
/** Attach an end user to this session and every later one in this run. */
|
|
169
|
+
identify(userId: string, traits?: Record<string, unknown>): void;
|
|
162
170
|
screen(name: string): void;
|
|
163
171
|
/** Called by the platform lifecycle glue. */
|
|
164
172
|
onAppStateChange(state: 'active' | 'background'): void;
|
package/dist/core.js
CHANGED
|
@@ -21,7 +21,7 @@ import { DEFAULT_CONFIG, SCHEMA_VERSION, } from "./types.js";
|
|
|
21
21
|
* still showed a bug fixed in 0.1.1 could not be told apart from one that had
|
|
22
22
|
* never been updated, from the dashboard or from the logs.
|
|
23
23
|
*/
|
|
24
|
-
export const SDK_VERSION = '0.1.
|
|
24
|
+
export const SDK_VERSION = '0.1.4';
|
|
25
25
|
/**
|
|
26
26
|
* Idle bound. Nothing for this long and the next event opens a new session.
|
|
27
27
|
*
|
|
@@ -61,6 +61,12 @@ export class SdkCore {
|
|
|
61
61
|
this.sessionListeners = new Set();
|
|
62
62
|
/** Events discarded because remote config disabled capture. Diagnostics. */
|
|
63
63
|
this.dropOnKill = 0;
|
|
64
|
+
/**
|
|
65
|
+
* Who `identify` last named, repeated on every later `session_start` so a
|
|
66
|
+
* rotated session is not anonymous. Memory only: a relaunch or reload
|
|
67
|
+
* forgets it, and the host calls `identify` again once it knows the user.
|
|
68
|
+
*/
|
|
69
|
+
this.user = null;
|
|
64
70
|
this.now = deps.now ?? Date.now;
|
|
65
71
|
this.onFlush = deps.onFlush ?? (() => { });
|
|
66
72
|
this.deviceContext = deps.deviceContext ?? (() => ({}));
|
|
@@ -83,6 +89,11 @@ export class SdkCore {
|
|
|
83
89
|
this.options = options;
|
|
84
90
|
this.enabled = options.enabled ?? true;
|
|
85
91
|
this.started = true;
|
|
92
|
+
if (options.appUserId) {
|
|
93
|
+
this.user = options.appUserEmail
|
|
94
|
+
? { userId: options.appUserId, email: options.appUserEmail }
|
|
95
|
+
: { userId: options.appUserId };
|
|
96
|
+
}
|
|
86
97
|
this.sessions = new SessionManager({
|
|
87
98
|
timeoutMs: SESSION_TIMEOUT_MS,
|
|
88
99
|
initial: this.restoreSession(),
|
|
@@ -102,6 +113,12 @@ export class SdkCore {
|
|
|
102
113
|
// its session row from this event (section 20); without it the first
|
|
103
114
|
// screen view would arrive for a session nothing has announced.
|
|
104
115
|
this.startSessionIfNeeded();
|
|
116
|
+
// A session restored across a reload announces nothing, so name the user
|
|
117
|
+
// explicitly. ponytail: a fresh session gets this twice (session_start and
|
|
118
|
+
// here); harmless, the worker takes the latest.
|
|
119
|
+
if (this.user) {
|
|
120
|
+
this.capture('user_action', { action: 'identify', ...this.user });
|
|
121
|
+
}
|
|
105
122
|
}
|
|
106
123
|
/**
|
|
107
124
|
* Whether capture is currently active.
|
|
@@ -329,6 +346,12 @@ export class SdkCore {
|
|
|
329
346
|
markReady() {
|
|
330
347
|
this.capture('performance', { ...timeToReady(this.now()) });
|
|
331
348
|
}
|
|
349
|
+
/** Attach an end user to this session and every later one in this run. */
|
|
350
|
+
identify(userId, traits) {
|
|
351
|
+
const email = typeof traits?.email === 'string' ? traits.email : undefined;
|
|
352
|
+
this.user = email ? { userId, email } : { userId };
|
|
353
|
+
this.capture('user_action', { action: 'identify', userId, ...traits });
|
|
354
|
+
}
|
|
332
355
|
screen(name) {
|
|
333
356
|
if (!this.isEnabled() || !this.sessions)
|
|
334
357
|
return;
|
|
@@ -390,7 +413,7 @@ export class SdkCore {
|
|
|
390
413
|
announce(sessionId) {
|
|
391
414
|
// Device context rides on session_start — it is the only event the worker
|
|
392
415
|
// reads it from, and every field is optional there.
|
|
393
|
-
this.capture('session_start', { ...this.deviceContext() });
|
|
416
|
+
this.capture('session_start', { ...this.deviceContext(), ...this.user });
|
|
394
417
|
for (const listener of this.sessionListeners) {
|
|
395
418
|
try {
|
|
396
419
|
listener(sessionId);
|
package/dist/types.d.ts
CHANGED
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
*/
|
|
10
10
|
/** Current wire format version. */
|
|
11
11
|
export declare const SCHEMA_VERSION: 1;
|
|
12
|
-
export type EventType = 'session_start' | 'session_end' | 'screen_view' | 'user_action' | 'navigation' | 'network_request' | 'error' | 'performance' | 'lifecycle' | 'breadcrumb' | 'custom';
|
|
12
|
+
export type EventType = 'session_start' | 'session_end' | 'screen_view' | 'user_action' | 'navigation' | 'network_request' | 'error' | 'performance' | 'lifecycle' | 'breadcrumb' | 'custom' | 'device_context';
|
|
13
13
|
/** Event types that are always captured, regardless of sample rate. */
|
|
14
14
|
export declare const UNSAMPLED_TYPES: readonly EventType[];
|
|
15
15
|
export interface CaptureEvent {
|
|
@@ -66,6 +66,13 @@ export interface InitOptions {
|
|
|
66
66
|
captureNetwork?: boolean;
|
|
67
67
|
/** Overridden by remote config when it loads. */
|
|
68
68
|
debug?: boolean;
|
|
69
|
+
/**
|
|
70
|
+
* Your app's own user, when it is known at launch. Recorded on every session
|
|
71
|
+
* as `appUserId` / `appUserEmail`; `identify()` replaces it after a login.
|
|
72
|
+
* Omit for anonymous users.
|
|
73
|
+
*/
|
|
74
|
+
appUserId?: string;
|
|
75
|
+
appUserEmail?: string;
|
|
69
76
|
}
|
|
70
77
|
/**
|
|
71
78
|
* Delivered by `GET /v1/config`, cached to disk, refetched periodically.
|