@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.
- package/dist/cjs/entry.js +1061 -24
- package/dist/cjs/entry.js.map +1 -1
- package/dist/cjs/index.js +1059 -24
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/main/app/index.d.ts +1 -0
- package/dist/cjs/main/entry.d.ts +5 -4
- package/dist/cjs/main/index.d.ts +17 -5
- package/dist/cjs/main/modules/analytics/batcher.d.ts +45 -0
- package/dist/cjs/main/modules/analytics/constantProperties.d.ts +53 -0
- package/dist/cjs/main/modules/analytics/demo.d.ts +0 -0
- package/dist/cjs/main/modules/analytics/events.d.ts +37 -0
- package/dist/cjs/main/modules/analytics/index.d.ts +73 -0
- package/dist/cjs/main/modules/analytics/people.d.ts +51 -0
- package/dist/cjs/main/modules/analytics/types.d.ts +32 -0
- package/dist/cjs/main/modules/analytics/utils.d.ts +19 -0
- package/dist/lib/entry.js +1060 -25
- package/dist/lib/entry.js.map +1 -1
- package/dist/lib/index.js +1059 -24
- package/dist/lib/index.js.map +1 -1
- package/dist/lib/main/app/index.d.ts +1 -0
- package/dist/lib/main/entry.d.ts +5 -4
- package/dist/lib/main/index.d.ts +17 -5
- package/dist/lib/main/modules/analytics/batcher.d.ts +45 -0
- package/dist/lib/main/modules/analytics/constantProperties.d.ts +53 -0
- package/dist/lib/main/modules/analytics/demo.d.ts +0 -0
- package/dist/lib/main/modules/analytics/events.d.ts +37 -0
- package/dist/lib/main/modules/analytics/index.d.ts +73 -0
- package/dist/lib/main/modules/analytics/people.d.ts +51 -0
- package/dist/lib/main/modules/analytics/types.d.ts +32 -0
- package/dist/lib/main/modules/analytics/utils.d.ts +19 -0
- package/dist/types/main/app/index.d.ts +1 -0
- package/dist/types/main/entry.d.ts +5 -4
- package/dist/types/main/index.d.ts +17 -5
- package/dist/types/main/modules/analytics/batcher.d.ts +45 -0
- package/dist/types/main/modules/analytics/constantProperties.d.ts +53 -0
- package/dist/types/main/modules/analytics/demo.d.ts +0 -0
- package/dist/types/main/modules/analytics/events.d.ts +37 -0
- package/dist/types/main/modules/analytics/index.d.ts +73 -0
- package/dist/types/main/modules/analytics/people.d.ts +51 -0
- package/dist/types/main/modules/analytics/types.d.ts +32 -0
- package/dist/types/main/modules/analytics/utils.d.ts +19 -0
- package/package.json +3 -3
package/dist/cjs/main/entry.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import TrackerClass from './index
|
|
2
|
-
export { default as App } from './app/index
|
|
3
|
-
export {
|
|
4
|
-
export {
|
|
1
|
+
import TrackerClass from './index';
|
|
2
|
+
export { default as App } from './app/index';
|
|
3
|
+
export { default as tracker, default as openReplay } from './singleton';
|
|
4
|
+
export { SanitizeLevel, Messages, Options } from './index';
|
|
5
|
+
export { default as Analytics } from './modules/analytics/index';
|
|
5
6
|
export default TrackerClass;
|
package/dist/cjs/main/index.d.ts
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
import App from './app/index
|
|
1
|
+
import App from './app/index';
|
|
2
2
|
export { default as App } from './app/index.js';
|
|
3
3
|
import * as _Messages from './app/messages.gen.js';
|
|
4
4
|
export declare const Messages: typeof _Messages;
|
|
5
5
|
export { SanitizeLevel } from './app/sanitizer.js';
|
|
6
|
+
import AnalyticsSDK from './modules/analytics/index.js';
|
|
6
7
|
import type { Options as AppOptions } from './app/index.js';
|
|
7
8
|
import type { Options as ConsoleOptions } from './modules/console.js';
|
|
8
9
|
import type { Options as ExceptionOptions } from './modules/exception.js';
|
|
@@ -31,10 +32,15 @@ export type Options = Partial<AppOptions & ConsoleOptions & ExceptionOptions & I
|
|
|
31
32
|
css: CssRulesOptions;
|
|
32
33
|
webAnimations?: WapOptions;
|
|
33
34
|
urls?: Partial<ViewportOptions>;
|
|
35
|
+
analytics?: {
|
|
36
|
+
ingestPoint?: string;
|
|
37
|
+
active?: boolean;
|
|
38
|
+
};
|
|
34
39
|
};
|
|
35
40
|
export default class API {
|
|
36
41
|
readonly options: Partial<Options>;
|
|
37
42
|
private readonly app;
|
|
43
|
+
readonly analytics: AnalyticsSDK | null;
|
|
38
44
|
private readonly crossdomainMode;
|
|
39
45
|
constructor(options: Partial<Options>);
|
|
40
46
|
checkDoNotTrack: () => boolean | undefined;
|
|
@@ -91,11 +97,11 @@ export default class API {
|
|
|
91
97
|
getSessionID(): string | null | undefined;
|
|
92
98
|
getTabId(): string | null;
|
|
93
99
|
sessionID(): string | null | undefined;
|
|
94
|
-
getSessionURL(options?: {
|
|
100
|
+
getSessionURL: (options?: {
|
|
95
101
|
withCurrentTime?: boolean;
|
|
96
|
-
})
|
|
97
|
-
setUserID(id: string)
|
|
98
|
-
userID(id: string)
|
|
102
|
+
}) => string | undefined;
|
|
103
|
+
setUserID: (id: string) => void;
|
|
104
|
+
userID: (id: string) => void;
|
|
99
105
|
setUserAnonymousID(id: string): void;
|
|
100
106
|
userAnonymousID(id: string): void;
|
|
101
107
|
setMetadata(key: string, value: string): void;
|
|
@@ -108,4 +114,10 @@ export default class API {
|
|
|
108
114
|
startTime: number;
|
|
109
115
|
endTime?: number;
|
|
110
116
|
}) => void;
|
|
117
|
+
private analyticsToken;
|
|
118
|
+
/**
|
|
119
|
+
* Use custom token for analytics events without session recording
|
|
120
|
+
* */
|
|
121
|
+
setAnalyticsToken: (token: string) => void;
|
|
122
|
+
getAnalyticsToken: () => string;
|
|
111
123
|
}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
interface PeopleEvent {
|
|
2
|
+
type: string;
|
|
3
|
+
timestamp: number;
|
|
4
|
+
payload: Record<string, any>;
|
|
5
|
+
}
|
|
6
|
+
interface Event {
|
|
7
|
+
name: string;
|
|
8
|
+
payload: Record<string, any>;
|
|
9
|
+
timestamp: number;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Creates batches of events, then sends them at intervals.
|
|
13
|
+
*/
|
|
14
|
+
declare class Batcher {
|
|
15
|
+
private readonly backendUrl;
|
|
16
|
+
private readonly getToken;
|
|
17
|
+
private readonly init;
|
|
18
|
+
private readonly autosendInterval;
|
|
19
|
+
private readonly retryTimeout;
|
|
20
|
+
private readonly retryLimit;
|
|
21
|
+
private readonly apiEdp;
|
|
22
|
+
private batch;
|
|
23
|
+
private intervalId;
|
|
24
|
+
constructor(backendUrl: string, getToken: () => string | null, init: () => Promise<void>);
|
|
25
|
+
getBatches(): {
|
|
26
|
+
data: {
|
|
27
|
+
user_actions: PeopleEvent[];
|
|
28
|
+
events: Event[];
|
|
29
|
+
};
|
|
30
|
+
};
|
|
31
|
+
addEvent(event: any): void;
|
|
32
|
+
sendImmediately(event: any): void;
|
|
33
|
+
/**
|
|
34
|
+
*
|
|
35
|
+
* Essentially we're dividing the batch by identify events and squash all same category events into one in each part,
|
|
36
|
+
* taking priority to the last one
|
|
37
|
+
*/
|
|
38
|
+
dedupePeopleEvents(): PeopleEvent[];
|
|
39
|
+
private squashPeopleEvents;
|
|
40
|
+
private sendBatch;
|
|
41
|
+
startAutosend(): void;
|
|
42
|
+
flush(): void;
|
|
43
|
+
stop(): void;
|
|
44
|
+
}
|
|
45
|
+
export default Batcher;
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
export interface StorageLike {
|
|
2
|
+
getItem: (key: string) => string | null;
|
|
3
|
+
setItem: (key: string, value: string) => void;
|
|
4
|
+
}
|
|
5
|
+
export default class ConstantProperties {
|
|
6
|
+
private readonly localStorage;
|
|
7
|
+
private readonly sessionStorage;
|
|
8
|
+
os: string;
|
|
9
|
+
osVersion: string;
|
|
10
|
+
browser: string;
|
|
11
|
+
browserVersion: string;
|
|
12
|
+
platform: string;
|
|
13
|
+
screenHeight: number;
|
|
14
|
+
screenWidth: number;
|
|
15
|
+
initialReferrer: string;
|
|
16
|
+
utmSource: string | null;
|
|
17
|
+
utmMedium: string | null;
|
|
18
|
+
utmCampaign: string | null;
|
|
19
|
+
deviceId: string;
|
|
20
|
+
searchEngine: string | null;
|
|
21
|
+
user_id: string | null;
|
|
22
|
+
constructor(localStorage: StorageLike, sessionStorage: StorageLike);
|
|
23
|
+
get all(): {
|
|
24
|
+
os: string;
|
|
25
|
+
os_version: string;
|
|
26
|
+
browser: string;
|
|
27
|
+
browser_version: string;
|
|
28
|
+
platform: string;
|
|
29
|
+
screen_height: number;
|
|
30
|
+
screen_width: number;
|
|
31
|
+
initial_referrer: string;
|
|
32
|
+
utm_source: string | null;
|
|
33
|
+
utm_medium: string | null;
|
|
34
|
+
utm_campaign: string | null;
|
|
35
|
+
user_id: string | null;
|
|
36
|
+
distinct_id: string;
|
|
37
|
+
sdk_edition: string;
|
|
38
|
+
sdk_version: string;
|
|
39
|
+
timezone: string;
|
|
40
|
+
search_engine: string | null;
|
|
41
|
+
};
|
|
42
|
+
setUserId: (user_id: string | null) => void;
|
|
43
|
+
resetUserId: (hard?: boolean) => void;
|
|
44
|
+
get defaultPropertyKeys(): string[];
|
|
45
|
+
get distinctId(): string;
|
|
46
|
+
private getDistinctDeviceId;
|
|
47
|
+
private getReferrer;
|
|
48
|
+
private parseUTM;
|
|
49
|
+
private getSearchEngine;
|
|
50
|
+
getSuperProperties: () => Record<string, any>;
|
|
51
|
+
saveSuperProperties: (props: Record<string, any>) => void;
|
|
52
|
+
clearSuperProperties: () => void;
|
|
53
|
+
}
|
|
File without changes
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import Batcher from './batcher.js';
|
|
2
|
+
import ConstantProperties from './constantProperties.js';
|
|
3
|
+
export default class Events {
|
|
4
|
+
private readonly constantProperties;
|
|
5
|
+
private readonly getTimestamp;
|
|
6
|
+
private readonly batcher;
|
|
7
|
+
ownProperties: Record<string, any>;
|
|
8
|
+
constructor(constantProperties: ConstantProperties, getTimestamp: () => number, batcher: Batcher);
|
|
9
|
+
/**
|
|
10
|
+
* Add event to batch with option to send it immediately,
|
|
11
|
+
* properties are optional and will not be saved as super prop
|
|
12
|
+
* */
|
|
13
|
+
sendEvent: (eventName: string, properties?: Record<string, any>, options?: {
|
|
14
|
+
send_immediately: boolean;
|
|
15
|
+
}) => void;
|
|
16
|
+
/**
|
|
17
|
+
* creates super property for all events
|
|
18
|
+
* */
|
|
19
|
+
setProperty: (nameOrProperties: Record<string, any> | string, value?: any) => void;
|
|
20
|
+
/**
|
|
21
|
+
* set super property only if it doesn't exist yet
|
|
22
|
+
* */
|
|
23
|
+
setPropertiesOnce: (nameOrProperties: Record<string, any> | string, value?: any) => void;
|
|
24
|
+
/**
|
|
25
|
+
* removes properties from list of super properties
|
|
26
|
+
* */
|
|
27
|
+
unsetProperties: (properties: string | string[]) => void;
|
|
28
|
+
/** clears all super properties */
|
|
29
|
+
reset: () => void;
|
|
30
|
+
/** mixpanel compatibility */
|
|
31
|
+
register: (nameOrProperties: Record<string, any> | string, value?: any) => void;
|
|
32
|
+
register_once: (nameOrProperties: Record<string, any> | string, value?: any) => void;
|
|
33
|
+
unregister: (properties: string | string[]) => void;
|
|
34
|
+
track: (eventName: string, properties?: Record<string, any>, options?: {
|
|
35
|
+
send_immediately: boolean;
|
|
36
|
+
}) => void;
|
|
37
|
+
}
|
|
@@ -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 {};
|