@reactor-cloud/analytics 0.2.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/dist/index.cjs +516 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +165 -0
- package/dist/index.d.ts +165 -0
- package/dist/index.js +491 -0
- package/dist/index.js.map +1 -0
- package/package.json +53 -0
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @reactor-cloud/analytics - Product analytics SDK for Reactor
|
|
3
|
+
*
|
|
4
|
+
* @example
|
|
5
|
+
* ```ts
|
|
6
|
+
* import { ReactorAnalytics } from '@reactor-cloud/analytics';
|
|
7
|
+
*
|
|
8
|
+
* const analytics = new ReactorAnalytics({
|
|
9
|
+
* projectKey: 'pk_...',
|
|
10
|
+
* endpoint: 'https://api.reactor.cloud/analytics/v1',
|
|
11
|
+
* });
|
|
12
|
+
*
|
|
13
|
+
* analytics.track('button_clicked', { button_id: 'signup' });
|
|
14
|
+
* analytics.identify('user_123', { email: 'user@example.com' });
|
|
15
|
+
* ```
|
|
16
|
+
*/
|
|
17
|
+
interface AnalyticsConfig {
|
|
18
|
+
/** Project key (X-Reactor-Project-Key header). */
|
|
19
|
+
projectKey: string;
|
|
20
|
+
/** Analytics API endpoint. */
|
|
21
|
+
endpoint: string;
|
|
22
|
+
/** Batch events before sending. */
|
|
23
|
+
batchSize?: number;
|
|
24
|
+
/** Flush interval in milliseconds. */
|
|
25
|
+
flushInterval?: number;
|
|
26
|
+
/** Auto-capture pageviews. */
|
|
27
|
+
autoPageview?: boolean;
|
|
28
|
+
/** Auto-capture errors with fingerprint coalescing. */
|
|
29
|
+
autoErrors?: boolean;
|
|
30
|
+
/** Auto-capture click interactions (opt-in). */
|
|
31
|
+
autoCapture?: boolean;
|
|
32
|
+
/** CSS selector for auto-capture targets. */
|
|
33
|
+
autoCaptureSelector?: string;
|
|
34
|
+
/** Error deduplication window in ms (default 5000). */
|
|
35
|
+
errorDedupeWindow?: number;
|
|
36
|
+
/** Persist anonymous ID to localStorage. */
|
|
37
|
+
persistence?: boolean;
|
|
38
|
+
/** Storage key for persistence. */
|
|
39
|
+
storageKey?: string;
|
|
40
|
+
/** Debug mode (logs events to console). */
|
|
41
|
+
debug?: boolean;
|
|
42
|
+
}
|
|
43
|
+
interface EventProperties {
|
|
44
|
+
[key: string]: string | number | boolean | null | undefined | EventProperties | EventProperties[];
|
|
45
|
+
}
|
|
46
|
+
interface UserTraits {
|
|
47
|
+
email?: string;
|
|
48
|
+
name?: string;
|
|
49
|
+
[key: string]: string | number | boolean | null | undefined;
|
|
50
|
+
}
|
|
51
|
+
interface PageContext {
|
|
52
|
+
path?: string;
|
|
53
|
+
url?: string;
|
|
54
|
+
referrer?: string;
|
|
55
|
+
title?: string;
|
|
56
|
+
}
|
|
57
|
+
interface ClientContext {
|
|
58
|
+
library?: {
|
|
59
|
+
name: string;
|
|
60
|
+
version: string;
|
|
61
|
+
};
|
|
62
|
+
userAgent?: string;
|
|
63
|
+
locale?: string;
|
|
64
|
+
timezone?: string;
|
|
65
|
+
screen?: {
|
|
66
|
+
width: number;
|
|
67
|
+
height: number;
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
interface QueuedEvent {
|
|
71
|
+
event: string;
|
|
72
|
+
properties: EventProperties;
|
|
73
|
+
timestamp: string;
|
|
74
|
+
anonymousId: string;
|
|
75
|
+
userId?: string;
|
|
76
|
+
sessionId?: string;
|
|
77
|
+
context: ClientContext & PageContext;
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* Reactor Analytics client.
|
|
81
|
+
*
|
|
82
|
+
* Provides methods for tracking events, identifying users, and managing consent.
|
|
83
|
+
*/
|
|
84
|
+
declare class ReactorAnalytics {
|
|
85
|
+
private config;
|
|
86
|
+
private anonymousId;
|
|
87
|
+
private userId;
|
|
88
|
+
private sessionId;
|
|
89
|
+
private queue;
|
|
90
|
+
private flushTimer;
|
|
91
|
+
private optedOut;
|
|
92
|
+
private errorFingerprints;
|
|
93
|
+
constructor(config: AnalyticsConfig);
|
|
94
|
+
/**
|
|
95
|
+
* Track an event.
|
|
96
|
+
*
|
|
97
|
+
* @param event - Event name.
|
|
98
|
+
* @param properties - Event properties.
|
|
99
|
+
*/
|
|
100
|
+
track(event: string, properties?: EventProperties): void;
|
|
101
|
+
/**
|
|
102
|
+
* Track a page view.
|
|
103
|
+
*
|
|
104
|
+
* @param name - Page name (optional).
|
|
105
|
+
* @param properties - Additional properties.
|
|
106
|
+
*/
|
|
107
|
+
page(name?: string, properties?: EventProperties): void;
|
|
108
|
+
/**
|
|
109
|
+
* Identify a user.
|
|
110
|
+
*
|
|
111
|
+
* @param userId - User ID.
|
|
112
|
+
* @param traits - User traits (email, name, etc.).
|
|
113
|
+
*/
|
|
114
|
+
identify(userId: string, traits?: UserTraits): void;
|
|
115
|
+
/**
|
|
116
|
+
* Alias an anonymous ID to a user ID.
|
|
117
|
+
*
|
|
118
|
+
* @param previousId - Previous anonymous ID.
|
|
119
|
+
* @param userId - User ID to alias to.
|
|
120
|
+
*/
|
|
121
|
+
alias(previousId: string, userId: string): void;
|
|
122
|
+
/**
|
|
123
|
+
* Reset the user identity.
|
|
124
|
+
* Generates a new anonymous ID and clears the user ID.
|
|
125
|
+
*/
|
|
126
|
+
reset(): void;
|
|
127
|
+
/**
|
|
128
|
+
* Flush the event queue.
|
|
129
|
+
*/
|
|
130
|
+
flush(): Promise<void>;
|
|
131
|
+
/**
|
|
132
|
+
* Opt out of tracking.
|
|
133
|
+
*/
|
|
134
|
+
optOut(): void;
|
|
135
|
+
/**
|
|
136
|
+
* Opt in to tracking.
|
|
137
|
+
*/
|
|
138
|
+
optIn(): void;
|
|
139
|
+
/**
|
|
140
|
+
* Get the current anonymous ID.
|
|
141
|
+
*/
|
|
142
|
+
getAnonymousId(): string;
|
|
143
|
+
/**
|
|
144
|
+
* Get the current user ID.
|
|
145
|
+
*/
|
|
146
|
+
getUserId(): string | undefined;
|
|
147
|
+
/**
|
|
148
|
+
* Get the current session ID.
|
|
149
|
+
*/
|
|
150
|
+
getSessionId(): string;
|
|
151
|
+
private enqueue;
|
|
152
|
+
private startFlushTimer;
|
|
153
|
+
private sendBatch;
|
|
154
|
+
private sendIdentify;
|
|
155
|
+
private sendAlias;
|
|
156
|
+
private sendConsentOptOut;
|
|
157
|
+
private sendConsentOptIn;
|
|
158
|
+
private setupAutoPageview;
|
|
159
|
+
private setupAutoErrors;
|
|
160
|
+
private generateErrorFingerprint;
|
|
161
|
+
private shouldTrackError;
|
|
162
|
+
private setupAutoCapture;
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
export { type AnalyticsConfig, type ClientContext, type EventProperties, type PageContext, type QueuedEvent, ReactorAnalytics, type UserTraits, ReactorAnalytics as default };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @reactor-cloud/analytics - Product analytics SDK for Reactor
|
|
3
|
+
*
|
|
4
|
+
* @example
|
|
5
|
+
* ```ts
|
|
6
|
+
* import { ReactorAnalytics } from '@reactor-cloud/analytics';
|
|
7
|
+
*
|
|
8
|
+
* const analytics = new ReactorAnalytics({
|
|
9
|
+
* projectKey: 'pk_...',
|
|
10
|
+
* endpoint: 'https://api.reactor.cloud/analytics/v1',
|
|
11
|
+
* });
|
|
12
|
+
*
|
|
13
|
+
* analytics.track('button_clicked', { button_id: 'signup' });
|
|
14
|
+
* analytics.identify('user_123', { email: 'user@example.com' });
|
|
15
|
+
* ```
|
|
16
|
+
*/
|
|
17
|
+
interface AnalyticsConfig {
|
|
18
|
+
/** Project key (X-Reactor-Project-Key header). */
|
|
19
|
+
projectKey: string;
|
|
20
|
+
/** Analytics API endpoint. */
|
|
21
|
+
endpoint: string;
|
|
22
|
+
/** Batch events before sending. */
|
|
23
|
+
batchSize?: number;
|
|
24
|
+
/** Flush interval in milliseconds. */
|
|
25
|
+
flushInterval?: number;
|
|
26
|
+
/** Auto-capture pageviews. */
|
|
27
|
+
autoPageview?: boolean;
|
|
28
|
+
/** Auto-capture errors with fingerprint coalescing. */
|
|
29
|
+
autoErrors?: boolean;
|
|
30
|
+
/** Auto-capture click interactions (opt-in). */
|
|
31
|
+
autoCapture?: boolean;
|
|
32
|
+
/** CSS selector for auto-capture targets. */
|
|
33
|
+
autoCaptureSelector?: string;
|
|
34
|
+
/** Error deduplication window in ms (default 5000). */
|
|
35
|
+
errorDedupeWindow?: number;
|
|
36
|
+
/** Persist anonymous ID to localStorage. */
|
|
37
|
+
persistence?: boolean;
|
|
38
|
+
/** Storage key for persistence. */
|
|
39
|
+
storageKey?: string;
|
|
40
|
+
/** Debug mode (logs events to console). */
|
|
41
|
+
debug?: boolean;
|
|
42
|
+
}
|
|
43
|
+
interface EventProperties {
|
|
44
|
+
[key: string]: string | number | boolean | null | undefined | EventProperties | EventProperties[];
|
|
45
|
+
}
|
|
46
|
+
interface UserTraits {
|
|
47
|
+
email?: string;
|
|
48
|
+
name?: string;
|
|
49
|
+
[key: string]: string | number | boolean | null | undefined;
|
|
50
|
+
}
|
|
51
|
+
interface PageContext {
|
|
52
|
+
path?: string;
|
|
53
|
+
url?: string;
|
|
54
|
+
referrer?: string;
|
|
55
|
+
title?: string;
|
|
56
|
+
}
|
|
57
|
+
interface ClientContext {
|
|
58
|
+
library?: {
|
|
59
|
+
name: string;
|
|
60
|
+
version: string;
|
|
61
|
+
};
|
|
62
|
+
userAgent?: string;
|
|
63
|
+
locale?: string;
|
|
64
|
+
timezone?: string;
|
|
65
|
+
screen?: {
|
|
66
|
+
width: number;
|
|
67
|
+
height: number;
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
interface QueuedEvent {
|
|
71
|
+
event: string;
|
|
72
|
+
properties: EventProperties;
|
|
73
|
+
timestamp: string;
|
|
74
|
+
anonymousId: string;
|
|
75
|
+
userId?: string;
|
|
76
|
+
sessionId?: string;
|
|
77
|
+
context: ClientContext & PageContext;
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* Reactor Analytics client.
|
|
81
|
+
*
|
|
82
|
+
* Provides methods for tracking events, identifying users, and managing consent.
|
|
83
|
+
*/
|
|
84
|
+
declare class ReactorAnalytics {
|
|
85
|
+
private config;
|
|
86
|
+
private anonymousId;
|
|
87
|
+
private userId;
|
|
88
|
+
private sessionId;
|
|
89
|
+
private queue;
|
|
90
|
+
private flushTimer;
|
|
91
|
+
private optedOut;
|
|
92
|
+
private errorFingerprints;
|
|
93
|
+
constructor(config: AnalyticsConfig);
|
|
94
|
+
/**
|
|
95
|
+
* Track an event.
|
|
96
|
+
*
|
|
97
|
+
* @param event - Event name.
|
|
98
|
+
* @param properties - Event properties.
|
|
99
|
+
*/
|
|
100
|
+
track(event: string, properties?: EventProperties): void;
|
|
101
|
+
/**
|
|
102
|
+
* Track a page view.
|
|
103
|
+
*
|
|
104
|
+
* @param name - Page name (optional).
|
|
105
|
+
* @param properties - Additional properties.
|
|
106
|
+
*/
|
|
107
|
+
page(name?: string, properties?: EventProperties): void;
|
|
108
|
+
/**
|
|
109
|
+
* Identify a user.
|
|
110
|
+
*
|
|
111
|
+
* @param userId - User ID.
|
|
112
|
+
* @param traits - User traits (email, name, etc.).
|
|
113
|
+
*/
|
|
114
|
+
identify(userId: string, traits?: UserTraits): void;
|
|
115
|
+
/**
|
|
116
|
+
* Alias an anonymous ID to a user ID.
|
|
117
|
+
*
|
|
118
|
+
* @param previousId - Previous anonymous ID.
|
|
119
|
+
* @param userId - User ID to alias to.
|
|
120
|
+
*/
|
|
121
|
+
alias(previousId: string, userId: string): void;
|
|
122
|
+
/**
|
|
123
|
+
* Reset the user identity.
|
|
124
|
+
* Generates a new anonymous ID and clears the user ID.
|
|
125
|
+
*/
|
|
126
|
+
reset(): void;
|
|
127
|
+
/**
|
|
128
|
+
* Flush the event queue.
|
|
129
|
+
*/
|
|
130
|
+
flush(): Promise<void>;
|
|
131
|
+
/**
|
|
132
|
+
* Opt out of tracking.
|
|
133
|
+
*/
|
|
134
|
+
optOut(): void;
|
|
135
|
+
/**
|
|
136
|
+
* Opt in to tracking.
|
|
137
|
+
*/
|
|
138
|
+
optIn(): void;
|
|
139
|
+
/**
|
|
140
|
+
* Get the current anonymous ID.
|
|
141
|
+
*/
|
|
142
|
+
getAnonymousId(): string;
|
|
143
|
+
/**
|
|
144
|
+
* Get the current user ID.
|
|
145
|
+
*/
|
|
146
|
+
getUserId(): string | undefined;
|
|
147
|
+
/**
|
|
148
|
+
* Get the current session ID.
|
|
149
|
+
*/
|
|
150
|
+
getSessionId(): string;
|
|
151
|
+
private enqueue;
|
|
152
|
+
private startFlushTimer;
|
|
153
|
+
private sendBatch;
|
|
154
|
+
private sendIdentify;
|
|
155
|
+
private sendAlias;
|
|
156
|
+
private sendConsentOptOut;
|
|
157
|
+
private sendConsentOptIn;
|
|
158
|
+
private setupAutoPageview;
|
|
159
|
+
private setupAutoErrors;
|
|
160
|
+
private generateErrorFingerprint;
|
|
161
|
+
private shouldTrackError;
|
|
162
|
+
private setupAutoCapture;
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
export { type AnalyticsConfig, type ClientContext, type EventProperties, type PageContext, type QueuedEvent, ReactorAnalytics, type UserTraits, ReactorAnalytics as default };
|