@sessionlens/sdk 0.2.1 → 0.3.0
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/README.md +22 -0
- package/dist/core/config.d.ts +5 -2
- package/dist/core/enrich.d.ts +6 -0
- package/dist/core/identity.d.ts +14 -0
- package/dist/core/tracker.d.ts +16 -1
- package/dist/index.d.ts +6 -0
- package/dist/index.esm.js +342 -120
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +342 -119
- package/dist/index.js.map +1 -1
- package/dist/types.d.ts +8 -0
- package/dist/utils/ua.d.ts +8 -0
- package/dist/utils/uuid.d.ts +2 -0
- package/dist/version.d.ts +2 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -45,6 +45,28 @@ sessionLens.sessionLensIdentify({
|
|
|
45
45
|
sessionLens.sessionLensReset();
|
|
46
46
|
```
|
|
47
47
|
|
|
48
|
+
## Identity and anonymous tracking (0.3.0+)
|
|
49
|
+
|
|
50
|
+
`user_id` is optional. Without it, events are tracked against a persistent anonymous device id
|
|
51
|
+
(`localStorage._sl_device_id`). Link the device to a person when you know who they are:
|
|
52
|
+
|
|
53
|
+
```javascript
|
|
54
|
+
await sessionLens.sessionLensInit({ sdk_key: '...', org_id: '...' }); // no user_id needed
|
|
55
|
+
|
|
56
|
+
sessionLens.sessionLensTrack({ event_name: 'pricing_viewed' }); // anonymous
|
|
57
|
+
|
|
58
|
+
sessionLens.identify('user-123', { name: 'Ada Lovelace', email: 'ada@example.com', plan: 'pro' });
|
|
59
|
+
sessionLens.setUserProperties({ company: 'Analytical Engines' }); // name/email map to core profile fields
|
|
60
|
+
|
|
61
|
+
sessionLens.reset(); // on logout: new anonymous identity
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
- Identifying again on the same device (a different user) links the device to the new user; past events keep their original attribution.
|
|
65
|
+
- `alias(newId, oldId)` is deprecated and simply calls `identify(newId)`.
|
|
66
|
+
- Passing `user_id` to `sessionLensInit` still works and behaves like an implicit `identify()`.
|
|
67
|
+
- Each event is automatically enriched with `$device_id`, `$distinct_id`, `$insert_id`, `$library`, `$library_version`, `$current_url`, `$pathname`, `$referrer`, `$initial_referrer`, UTM parameters, screen size and client browser/OS hints. Browser, OS and geo (from the request IP) are derived on the server.
|
|
68
|
+
- Trait limits: at most 100 keys, keys up to 128 characters, values up to 4 KB. Trait keys may not start with `$` or contain `.`; offending keys are dropped without failing the call.
|
|
69
|
+
|
|
48
70
|
### Advanced Usage with Custom Configuration
|
|
49
71
|
|
|
50
72
|
```javascript
|
package/dist/core/config.d.ts
CHANGED
|
@@ -1,14 +1,16 @@
|
|
|
1
1
|
export interface SessionLensConfig {
|
|
2
2
|
sdk_key: string;
|
|
3
|
-
user_id
|
|
3
|
+
user_id?: string;
|
|
4
4
|
org_id: string;
|
|
5
5
|
project_id?: string;
|
|
6
|
+
app?: string;
|
|
6
7
|
debug?: boolean;
|
|
7
8
|
api_base_url?: string;
|
|
8
9
|
endpoints?: {
|
|
9
10
|
events?: string;
|
|
10
11
|
identify?: string;
|
|
11
12
|
reset?: string;
|
|
13
|
+
userProperties?: string;
|
|
12
14
|
validate?: string;
|
|
13
15
|
};
|
|
14
16
|
}
|
|
@@ -17,10 +19,11 @@ interface SessionInfo {
|
|
|
17
19
|
client_id: string;
|
|
18
20
|
org_id: string;
|
|
19
21
|
project_id: string;
|
|
20
|
-
user_id
|
|
22
|
+
user_id?: string;
|
|
21
23
|
started_at: number;
|
|
22
24
|
last_activity: number;
|
|
23
25
|
}
|
|
26
|
+
export declare function restartSession(): void;
|
|
24
27
|
export declare function sessionLensInit(config: SessionLensConfig): Promise<void>;
|
|
25
28
|
export declare function sessionLensGetConfig(): SessionLensConfig;
|
|
26
29
|
export declare function getSessionInfo(): SessionInfo;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* System properties attached to every event. All browser access is guarded so this
|
|
3
|
+
* is safe to call during SSR (only identity/library fields are returned there).
|
|
4
|
+
* The server re-derives browser/os/geo authoritatively; the client UA fields are a fallback.
|
|
5
|
+
*/
|
|
6
|
+
export declare function buildSystemProperties(clientTimestamp: number): Record<string, any>;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export interface Identity {
|
|
2
|
+
device_id: string;
|
|
3
|
+
distinct_id: string;
|
|
4
|
+
user_id?: string;
|
|
5
|
+
}
|
|
6
|
+
export declare function getDeviceId(): string;
|
|
7
|
+
/** Current identity. Anonymous visitors have distinct_id === device_id and no user_id. */
|
|
8
|
+
export declare function getIdentity(): Identity;
|
|
9
|
+
/** Persist a user identity. From now on events carry distinct_id = userId. */
|
|
10
|
+
export declare function setUser(userId: string): void;
|
|
11
|
+
/** Forget the user and start a fresh anonymous identity on a new device id. */
|
|
12
|
+
export declare function resetIdentity(): Identity;
|
|
13
|
+
/** Referrer of the very first page load, persisted once ('$direct' when there was none). */
|
|
14
|
+
export declare function getInitialReferrer(currentReferrer: string): string;
|
package/dist/core/tracker.d.ts
CHANGED
|
@@ -1,4 +1,19 @@
|
|
|
1
|
+
import { SessionLensConfig } from './config';
|
|
1
2
|
import { SessionLensEvent, SessionLensUser } from '../types';
|
|
3
|
+
/**
|
|
4
|
+
* Initialize the SDK. If `config.user_id` is supplied (pre-0.3 integrations) it is treated
|
|
5
|
+
* as an implicit identify() - sent only when it differs from the persisted identity.
|
|
6
|
+
*/
|
|
7
|
+
export declare function sessionLensInit(config: SessionLensConfig): Promise<void>;
|
|
2
8
|
export declare function sessionLensTrack(event: SessionLensEvent): void;
|
|
9
|
+
/** Link the current device to `userId` (last identify wins) and optionally set traits. */
|
|
10
|
+
export declare function identify(userId: string, traits?: Record<string, any>): void;
|
|
11
|
+
/** @deprecated Aliasing is subsumed by identify(); `oldId` is ignored (the device link is implicit). */
|
|
12
|
+
export declare function alias(newId: string, _oldId?: string): void;
|
|
13
|
+
/** Set traits on the current profile (`name` and `email` map to core profile fields). */
|
|
14
|
+
export declare function setUserProperties(traits: Record<string, any>): void;
|
|
15
|
+
/** Legacy signature: sessionLensIdentify({ user_id, properties }). */
|
|
3
16
|
export declare function sessionLensIdentify(user: SessionLensUser): void;
|
|
4
|
-
|
|
17
|
+
/** Forget the user, start an anonymous identity on a new device id and a new session. */
|
|
18
|
+
export declare function reset(): void;
|
|
19
|
+
export declare const sessionLensReset: typeof reset;
|
package/dist/index.d.ts
CHANGED
|
@@ -2,12 +2,18 @@ import { SessionLensConfig } from './core/config';
|
|
|
2
2
|
import { SessionLensEvent, SessionLensUser, SessionLensInstance } from './types';
|
|
3
3
|
export * from './types';
|
|
4
4
|
export { SessionLensConfig } from './core/config';
|
|
5
|
+
export { SDK_VERSION } from './version';
|
|
5
6
|
export * from './integrations/react';
|
|
6
7
|
declare class SessionLens implements SessionLensInstance {
|
|
7
8
|
sessionLensInit(config: SessionLensConfig): Promise<void>;
|
|
8
9
|
sessionLensTrack(event: SessionLensEvent): void;
|
|
9
10
|
sessionLensIdentify(user: SessionLensUser): void;
|
|
10
11
|
sessionLensReset(): void;
|
|
12
|
+
identify(userId: string, traits?: Record<string, any>): void;
|
|
13
|
+
/** @deprecated Use identify(). */
|
|
14
|
+
alias(newId: string, oldId?: string): void;
|
|
15
|
+
setUserProperties(traits: Record<string, any>): void;
|
|
16
|
+
reset(): void;
|
|
11
17
|
}
|
|
12
18
|
declare const sessionLens: SessionLens;
|
|
13
19
|
export default sessionLens;
|