@openreplay/tracker 17.0.1 → 17.1.1

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.
Files changed (42) hide show
  1. package/dist/cjs/entry.js +1061 -24
  2. package/dist/cjs/entry.js.map +1 -1
  3. package/dist/cjs/index.js +1059 -24
  4. package/dist/cjs/index.js.map +1 -1
  5. package/dist/cjs/main/app/index.d.ts +1 -0
  6. package/dist/cjs/main/entry.d.ts +5 -4
  7. package/dist/cjs/main/index.d.ts +17 -5
  8. package/dist/cjs/main/modules/analytics/batcher.d.ts +45 -0
  9. package/dist/cjs/main/modules/analytics/constantProperties.d.ts +53 -0
  10. package/dist/cjs/main/modules/analytics/demo.d.ts +0 -0
  11. package/dist/cjs/main/modules/analytics/events.d.ts +37 -0
  12. package/dist/cjs/main/modules/analytics/index.d.ts +73 -0
  13. package/dist/cjs/main/modules/analytics/people.d.ts +51 -0
  14. package/dist/cjs/main/modules/analytics/types.d.ts +32 -0
  15. package/dist/cjs/main/modules/analytics/utils.d.ts +19 -0
  16. package/dist/lib/entry.js +1060 -25
  17. package/dist/lib/entry.js.map +1 -1
  18. package/dist/lib/index.js +1059 -24
  19. package/dist/lib/index.js.map +1 -1
  20. package/dist/lib/main/app/index.d.ts +1 -0
  21. package/dist/lib/main/entry.d.ts +5 -4
  22. package/dist/lib/main/index.d.ts +17 -5
  23. package/dist/lib/main/modules/analytics/batcher.d.ts +45 -0
  24. package/dist/lib/main/modules/analytics/constantProperties.d.ts +53 -0
  25. package/dist/lib/main/modules/analytics/demo.d.ts +0 -0
  26. package/dist/lib/main/modules/analytics/events.d.ts +37 -0
  27. package/dist/lib/main/modules/analytics/index.d.ts +73 -0
  28. package/dist/lib/main/modules/analytics/people.d.ts +51 -0
  29. package/dist/lib/main/modules/analytics/types.d.ts +32 -0
  30. package/dist/lib/main/modules/analytics/utils.d.ts +19 -0
  31. package/dist/types/main/app/index.d.ts +1 -0
  32. package/dist/types/main/entry.d.ts +5 -4
  33. package/dist/types/main/index.d.ts +17 -5
  34. package/dist/types/main/modules/analytics/batcher.d.ts +45 -0
  35. package/dist/types/main/modules/analytics/constantProperties.d.ts +53 -0
  36. package/dist/types/main/modules/analytics/demo.d.ts +0 -0
  37. package/dist/types/main/modules/analytics/events.d.ts +37 -0
  38. package/dist/types/main/modules/analytics/index.d.ts +73 -0
  39. package/dist/types/main/modules/analytics/people.d.ts +51 -0
  40. package/dist/types/main/modules/analytics/types.d.ts +32 -0
  41. package/dist/types/main/modules/analytics/utils.d.ts +19 -0
  42. package/package.json +3 -3
@@ -0,0 +1,73 @@
1
+ import ConstantProperties from './constantProperties.js';
2
+ import type { StorageLike } from './constantProperties.js';
3
+ import Events from './events.js';
4
+ import People from './people.js';
5
+ interface Options {
6
+ ingestPoint: string;
7
+ projectKey: string;
8
+ /** Storage class for persistent data */
9
+ localStorage?: StorageLike;
10
+ /** Storage class for data on a per-session basis */
11
+ sessionStorage?: StorageLike;
12
+ /** Used to request a custom session token when in not-standalone mode */
13
+ getToken?: () => string;
14
+ /** Used to get current timestamp when not in standalone mode */
15
+ getTimestamp?: () => number;
16
+ /** Callback for people.identify */
17
+ setUserId?: (user_id: string) => void;
18
+ /** automatically set when used inside openreplay tracker */
19
+ notStandalone?: boolean;
20
+ }
21
+ export default class Analytics {
22
+ readonly events: Events;
23
+ readonly constantProperties: ConstantProperties;
24
+ readonly people: People;
25
+ private token;
26
+ private readonly batcher;
27
+ private readonly backendUrl;
28
+ private readonly projectKey;
29
+ private readonly localStorage;
30
+ private readonly sessionStorage;
31
+ private readonly getToken;
32
+ private readonly getTimestamp;
33
+ private readonly setUserId;
34
+ private readonly standalone;
35
+ /**
36
+ * @param localStorage Class or Object that implements Storage-like interface that stores
37
+ * values persistently like window.localStorage or any other file-based storage
38
+ *
39
+ * @param sessionStorage Class or Object that implements Storage-like interface that stores values
40
+ * on per-session basis like window.sessionStorage or any other in-memory storage
41
+ *
42
+ * @param getToken Function that returns token to bind events to a session
43
+ *
44
+ * @param getTimestamp returns current timestamp
45
+ *
46
+ * @param setUserId callback for people.identify
47
+ *
48
+ * @param standalone if true, analytics will manage its own token (instead of using with openreplay tracker session)
49
+ * */
50
+ constructor(options: Options);
51
+ _getToken: () => string | null;
52
+ _getTimestamp: () => number;
53
+ init: () => Promise<void>;
54
+ reset: () => void;
55
+ /**
56
+ * COMPATIBILITY LAYER
57
+ * */
58
+ /**
59
+ * Identify a user with an id (e.g. email, username, etc.)
60
+ * will bind all events and properties (including device_id) to this user
61
+ *
62
+ * you will need to manually call people.reset() to clear the id on logout event
63
+ * */
64
+ identify: (user_id: string) => void;
65
+ /**
66
+ * Add event to batch with option to send it immediately,
67
+ * properties are optional and will not be saved as super prop
68
+ * */
69
+ track: (eventName: string, properties?: Record<string, any>, options?: {
70
+ send_immediately: boolean;
71
+ }) => void;
72
+ }
73
+ export {};
@@ -0,0 +1,51 @@
1
+ import Batcher from './batcher.js';
2
+ import ConstantProperties from './constantProperties.js';
3
+ type Value = string | number;
4
+ export default class People {
5
+ private readonly constantProperties;
6
+ private readonly getTimestamp;
7
+ private readonly onId;
8
+ private readonly batcher;
9
+ ownProperties: Record<string, Value | Value[]>;
10
+ constructor(constantProperties: ConstantProperties, getTimestamp: () => number, onId: (user_id: string) => void, batcher: Batcher);
11
+ identify: (user_id: string, options?: {
12
+ fromTracker: boolean;
13
+ }) => void;
14
+ /** Resets user id and own properties
15
+ *
16
+ * !hard reset will destroy persistent device id!
17
+ * */
18
+ reset: (hard?: boolean) => void;
19
+ get user_id(): string | null;
20
+ /**
21
+ * Will delete user and its data from backend, then reset all local properties
22
+ */
23
+ deleteUser: () => void;
24
+ /**
25
+ * set user properties, overwriting existing ones
26
+ * */
27
+ setProperties: (propertyOrObj: Record<string, string | number> | string, value?: string) => void;
28
+ /**
29
+ * Set property if it doesn't exist yet
30
+ * */
31
+ setPropertiesOnce: (properties: Record<string, string | number>) => void;
32
+ /**
33
+ * Add value to property (will turn string prop into array)
34
+ * */
35
+ appendValues: (key: string, value: string | number) => void;
36
+ /**
37
+ * Add unique values to property (will turn string prop into array)
38
+ * */
39
+ appendUniqueValues: (key: string, value: string | number) => void;
40
+ /**
41
+ * Adds value (incl. negative) to existing numerical property
42
+ * */
43
+ increment: (key: string, value: number) => void;
44
+ /** mixpanel compatibility */
45
+ union: (key: string, value: string | number) => void;
46
+ set: (propertyOrObj: Record<string, string | number> | string, value?: string) => void;
47
+ set_once: (properties: Record<string, string | number>) => void;
48
+ append: (key: string, value: string | number) => void;
49
+ incrementBy: (key: string, value: number) => void;
50
+ }
51
+ export {};
@@ -0,0 +1,32 @@
1
+ export declare const mutationTypes: {
2
+ identity: string;
3
+ deleteUser: string;
4
+ setProperty: string;
5
+ setPropertyOnce: string;
6
+ appendProperty: string;
7
+ appendUniqueProperty: string;
8
+ incrementProperty: string;
9
+ };
10
+ export declare const categories: {
11
+ readonly people: "user_actions";
12
+ readonly events: "events";
13
+ };
14
+ export declare const createEvent: (category: (typeof categories)[keyof typeof categories], type?: (typeof mutationTypes)[keyof typeof mutationTypes], timestamp?: number, payload?: Record<string, any>) => {
15
+ category: "user_actions";
16
+ data: {
17
+ type: string | undefined;
18
+ user_id: any;
19
+ payload: any;
20
+ timestamp: number | undefined;
21
+ name?: undefined;
22
+ };
23
+ } | {
24
+ category: "events";
25
+ data: {
26
+ name: any;
27
+ payload: any;
28
+ timestamp: number | undefined;
29
+ type?: undefined;
30
+ user_id?: undefined;
31
+ };
32
+ };
@@ -0,0 +1,19 @@
1
+ interface ClientData {
2
+ screen: string;
3
+ width: number;
4
+ height: number;
5
+ browser: string;
6
+ browserVersion: string;
7
+ browserMajorVersion: number;
8
+ mobile: boolean;
9
+ os: string;
10
+ osVersion: string;
11
+ cookies: boolean;
12
+ }
13
+ /**
14
+ * Detects client browser, OS, and device information
15
+ */
16
+ export declare function uaParse(sWindow: Window & typeof globalThis): ClientData;
17
+ export declare function isObject(item: any): boolean;
18
+ export declare function getUTCOffsetString(): string;
19
+ export {};
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@openreplay/tracker",
3
3
  "description": "The OpenReplay tracker main package",
4
- "version": "17.0.1",
4
+ "version": "17.1.1",
5
5
  "keywords": [
6
6
  "logging",
7
7
  "replay"
@@ -63,8 +63,8 @@
63
63
  "eslint": "^9.37.0",
64
64
  "eslint-config-prettier": "^9.1.0",
65
65
  "eslint-plugin-prettier": "^5.5.4",
66
- "jest": "^29.7.0",
67
- "jest-environment-jsdom": "^29.7.0",
66
+ "jest": "^30.2.0",
67
+ "jest-environment-jsdom": "^30.2.0",
68
68
  "prettier": "^3.6.2",
69
69
  "replace-in-files": "^2.0.3",
70
70
  "rollup": "^4.52.4",