@thisbefine/analytics 0.1.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/LICENSE +21 -0
- package/README.md +403 -0
- package/dist/core/analytics.d.ts +123 -0
- package/dist/core/analytics.d.ts.map +1 -0
- package/dist/core/analytics.js +334 -0
- package/dist/core/analytics.js.map +1 -0
- package/dist/core/errors.d.ts +94 -0
- package/dist/core/errors.d.ts.map +1 -0
- package/dist/core/errors.js +420 -0
- package/dist/core/errors.js.map +1 -0
- package/dist/core/logger.d.ts +28 -0
- package/dist/core/logger.d.ts.map +1 -0
- package/dist/core/logger.js +36 -0
- package/dist/core/logger.js.map +1 -0
- package/dist/core/logging.d.ts +12 -0
- package/dist/core/logging.d.ts.map +1 -0
- package/dist/core/logging.js +33 -0
- package/dist/core/logging.js.map +1 -0
- package/dist/core/privacy.d.ts +53 -0
- package/dist/core/privacy.d.ts.map +1 -0
- package/dist/core/privacy.js +94 -0
- package/dist/core/privacy.js.map +1 -0
- package/dist/core/queue.d.ts +59 -0
- package/dist/core/queue.d.ts.map +1 -0
- package/dist/core/queue.js +263 -0
- package/dist/core/queue.js.map +1 -0
- package/dist/core/session.d.ts +90 -0
- package/dist/core/session.d.ts.map +1 -0
- package/dist/core/session.js +246 -0
- package/dist/core/session.js.map +1 -0
- package/dist/core/storage.d.ts +64 -0
- package/dist/core/storage.d.ts.map +1 -0
- package/dist/core/storage.js +242 -0
- package/dist/core/storage.js.map +1 -0
- package/dist/core/types.d.ts +298 -0
- package/dist/core/types.d.ts.map +1 -0
- package/dist/core/types.js +34 -0
- package/dist/core/types.js.map +1 -0
- package/dist/core/validation.d.ts +11 -0
- package/dist/core/validation.d.ts.map +1 -0
- package/dist/core/validation.js +82 -0
- package/dist/core/validation.js.map +1 -0
- package/dist/core/version.d.ts +2 -0
- package/dist/core/version.d.ts.map +1 -0
- package/dist/core/version.js +4 -0
- package/dist/core/version.js.map +1 -0
- package/dist/index.d.ts +45 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +41 -0
- package/dist/index.js.map +1 -0
- package/dist/next/analytics.d.ts +59 -0
- package/dist/next/analytics.d.ts.map +1 -0
- package/dist/next/analytics.js +87 -0
- package/dist/next/analytics.js.map +1 -0
- package/dist/next.d.ts +46 -0
- package/dist/next.d.ts.map +1 -0
- package/dist/next.js +44 -0
- package/dist/next.js.map +1 -0
- package/dist/react/analytics.d.ts +51 -0
- package/dist/react/analytics.d.ts.map +1 -0
- package/dist/react/analytics.js +63 -0
- package/dist/react/analytics.js.map +1 -0
- package/dist/react/bug-report-widget.d.ts +21 -0
- package/dist/react/bug-report-widget.d.ts.map +1 -0
- package/dist/react/bug-report-widget.js +34 -0
- package/dist/react/bug-report-widget.js.map +1 -0
- package/dist/react/hooks.d.ts +141 -0
- package/dist/react/hooks.d.ts.map +1 -0
- package/dist/react/hooks.js +186 -0
- package/dist/react/hooks.js.map +1 -0
- package/dist/react.d.ts +42 -0
- package/dist/react.d.ts.map +1 -0
- package/dist/react.js +39 -0
- package/dist/react.js.map +1 -0
- package/dist/widget/bug-report.d.ts +16 -0
- package/dist/widget/bug-report.d.ts.map +1 -0
- package/dist/widget/bug-report.js +416 -0
- package/dist/widget/bug-report.js.map +1 -0
- package/package.json +107 -0
|
@@ -0,0 +1,298 @@
|
|
|
1
|
+
import type { ErrorCaptureConfig } from "./errors";
|
|
2
|
+
import type { LogLevel } from "./logging";
|
|
3
|
+
/**
|
|
4
|
+
* Configuration options for the analytics SDK
|
|
5
|
+
*/
|
|
6
|
+
export interface AnalyticsConfig {
|
|
7
|
+
/** Your Thisbefine API key (starts with tbf_) */
|
|
8
|
+
apiKey: string;
|
|
9
|
+
/** API host URL. Defaults to https://thisbefine.com */
|
|
10
|
+
host?: string;
|
|
11
|
+
/** Number of events to batch before sending. Default: 20 */
|
|
12
|
+
flushAt?: number;
|
|
13
|
+
/** Maximum time (ms) between flushes. Default: 10000 (10s) */
|
|
14
|
+
flushInterval?: number;
|
|
15
|
+
/** Session timeout in ms. Default: 1800000 (30 minutes) */
|
|
16
|
+
sessionTimeout?: number;
|
|
17
|
+
/** Cookie domain for cross-subdomain tracking */
|
|
18
|
+
cookieDomain?: string;
|
|
19
|
+
/** Enable debug logging to console. Default: false */
|
|
20
|
+
debug?: boolean;
|
|
21
|
+
/** Respect Do Not Track browser setting. Default: true */
|
|
22
|
+
respectDNT?: boolean;
|
|
23
|
+
/** Maximum retry attempts for failed requests. Default: 3 */
|
|
24
|
+
maxRetries?: number;
|
|
25
|
+
/** Error capture configuration */
|
|
26
|
+
errors?: ErrorCaptureConfig;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Internal resolved configuration with defaults applied
|
|
30
|
+
*/
|
|
31
|
+
export interface ResolvedConfig {
|
|
32
|
+
apiKey: string;
|
|
33
|
+
host: string;
|
|
34
|
+
flushAt: number;
|
|
35
|
+
flushInterval: number;
|
|
36
|
+
sessionTimeout: number;
|
|
37
|
+
cookieDomain: string | undefined;
|
|
38
|
+
debug: boolean;
|
|
39
|
+
respectDNT: boolean;
|
|
40
|
+
maxRetries: number;
|
|
41
|
+
errors?: ErrorCaptureConfig;
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Event context sent with every event
|
|
45
|
+
*/
|
|
46
|
+
export interface EventContext {
|
|
47
|
+
library: {
|
|
48
|
+
name: string;
|
|
49
|
+
version: string;
|
|
50
|
+
};
|
|
51
|
+
userAgent: string;
|
|
52
|
+
locale: string;
|
|
53
|
+
timezone: string;
|
|
54
|
+
screen?: {
|
|
55
|
+
width: number;
|
|
56
|
+
height: number;
|
|
57
|
+
};
|
|
58
|
+
page?: {
|
|
59
|
+
url: string;
|
|
60
|
+
path: string;
|
|
61
|
+
referrer: string;
|
|
62
|
+
title: string;
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Base event structure
|
|
67
|
+
*/
|
|
68
|
+
export interface BaseEvent {
|
|
69
|
+
type: "track" | "identify" | "page" | "group";
|
|
70
|
+
timestamp: string;
|
|
71
|
+
anonymousId: string;
|
|
72
|
+
userId?: string;
|
|
73
|
+
sessionId?: string;
|
|
74
|
+
accountId?: string;
|
|
75
|
+
context?: EventContext;
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* Track event for custom user actions
|
|
79
|
+
*/
|
|
80
|
+
export interface TrackEvent extends BaseEvent {
|
|
81
|
+
type: "track";
|
|
82
|
+
event: string;
|
|
83
|
+
properties?: Record<string, unknown>;
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* Identify event for user identification
|
|
87
|
+
*/
|
|
88
|
+
export interface IdentifyEvent extends BaseEvent {
|
|
89
|
+
type: "identify";
|
|
90
|
+
userId: string;
|
|
91
|
+
traits?: Record<string, unknown>;
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* Page event for pageview tracking
|
|
95
|
+
*/
|
|
96
|
+
export interface PageEvent extends BaseEvent {
|
|
97
|
+
type: "page";
|
|
98
|
+
name?: string;
|
|
99
|
+
properties?: Record<string, unknown>;
|
|
100
|
+
url: string;
|
|
101
|
+
referrer?: string;
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
104
|
+
* Group event for account/company association
|
|
105
|
+
*/
|
|
106
|
+
export interface GroupEvent extends BaseEvent {
|
|
107
|
+
type: "group";
|
|
108
|
+
accountId: string;
|
|
109
|
+
traits?: AccountTraits;
|
|
110
|
+
}
|
|
111
|
+
/**
|
|
112
|
+
* Account/company traits for B2B SaaS
|
|
113
|
+
*/
|
|
114
|
+
export interface AccountTraits {
|
|
115
|
+
/** Company/account name */
|
|
116
|
+
name?: string;
|
|
117
|
+
/** Subscription plan (e.g., 'free', 'starter', 'pro', 'enterprise') */
|
|
118
|
+
plan?: string;
|
|
119
|
+
/** Monthly recurring revenue in dollars */
|
|
120
|
+
mrr?: number;
|
|
121
|
+
/** Industry vertical */
|
|
122
|
+
industry?: string;
|
|
123
|
+
/** Number of employees */
|
|
124
|
+
employeeCount?: number;
|
|
125
|
+
/** Account creation date */
|
|
126
|
+
createdAt?: string | Date;
|
|
127
|
+
/** Custom properties */
|
|
128
|
+
[key: string]: unknown;
|
|
129
|
+
}
|
|
130
|
+
/**
|
|
131
|
+
* Union type for all event types
|
|
132
|
+
*/
|
|
133
|
+
export type AnalyticsEvent = TrackEvent | IdentifyEvent | PageEvent | GroupEvent;
|
|
134
|
+
/**
|
|
135
|
+
* User traits for identification
|
|
136
|
+
*/
|
|
137
|
+
export interface UserTraits {
|
|
138
|
+
email?: string;
|
|
139
|
+
name?: string;
|
|
140
|
+
avatar?: string;
|
|
141
|
+
[key: string]: unknown;
|
|
142
|
+
}
|
|
143
|
+
/**
|
|
144
|
+
* Current user state
|
|
145
|
+
*/
|
|
146
|
+
export interface UserState {
|
|
147
|
+
anonymousId: string;
|
|
148
|
+
userId?: string;
|
|
149
|
+
traits?: UserTraits;
|
|
150
|
+
accountId?: string;
|
|
151
|
+
accountTraits?: AccountTraits;
|
|
152
|
+
}
|
|
153
|
+
/**
|
|
154
|
+
* Batch request payload sent to the API
|
|
155
|
+
*/
|
|
156
|
+
export interface BatchPayload {
|
|
157
|
+
batch: Array<{
|
|
158
|
+
event: string;
|
|
159
|
+
properties?: Record<string, unknown>;
|
|
160
|
+
timestamp?: string;
|
|
161
|
+
anonymousId?: string;
|
|
162
|
+
userId?: string;
|
|
163
|
+
sessionId?: string;
|
|
164
|
+
url?: string;
|
|
165
|
+
referrer?: string;
|
|
166
|
+
}>;
|
|
167
|
+
}
|
|
168
|
+
/**
|
|
169
|
+
* Identify request payload
|
|
170
|
+
*/
|
|
171
|
+
export interface IdentifyPayload {
|
|
172
|
+
userId: string;
|
|
173
|
+
anonymousId?: string;
|
|
174
|
+
traits?: UserTraits;
|
|
175
|
+
}
|
|
176
|
+
/**
|
|
177
|
+
* Public Analytics interface
|
|
178
|
+
*/
|
|
179
|
+
export interface Analytics {
|
|
180
|
+
/**
|
|
181
|
+
* Track a custom event
|
|
182
|
+
* @param event - Event name (e.g., 'button_clicked', 'signup_completed')
|
|
183
|
+
* @param properties - Optional event properties
|
|
184
|
+
*/
|
|
185
|
+
track(event: string, properties?: Record<string, unknown>): void;
|
|
186
|
+
/**
|
|
187
|
+
* Identify a user and associate traits
|
|
188
|
+
* @param userId - Unique user identifier
|
|
189
|
+
* @param traits - Optional user traits (email, name, etc.)
|
|
190
|
+
*/
|
|
191
|
+
identify(userId: string, traits?: UserTraits): void;
|
|
192
|
+
/**
|
|
193
|
+
* Track a page view
|
|
194
|
+
* @param name - Optional page name
|
|
195
|
+
* @param properties - Optional page properties
|
|
196
|
+
*/
|
|
197
|
+
page(name?: string, properties?: Record<string, unknown>): void;
|
|
198
|
+
/**
|
|
199
|
+
* Associate the current user with an account/company
|
|
200
|
+
* @param accountId - Unique account identifier
|
|
201
|
+
* @param traits - Optional account traits (name, plan, MRR, etc.)
|
|
202
|
+
*/
|
|
203
|
+
group(accountId: string, traits?: AccountTraits): void;
|
|
204
|
+
/**
|
|
205
|
+
* Reset the current user session (call on logout)
|
|
206
|
+
*/
|
|
207
|
+
reset(): void;
|
|
208
|
+
/**
|
|
209
|
+
* Manually flush the event queue
|
|
210
|
+
*/
|
|
211
|
+
flush(): Promise<void>;
|
|
212
|
+
/**
|
|
213
|
+
* Opt out of tracking
|
|
214
|
+
*/
|
|
215
|
+
optOut(): void;
|
|
216
|
+
/**
|
|
217
|
+
* Opt back in to tracking
|
|
218
|
+
*/
|
|
219
|
+
optIn(): void;
|
|
220
|
+
/**
|
|
221
|
+
* Check if user has opted out
|
|
222
|
+
*/
|
|
223
|
+
isOptedOut(): boolean;
|
|
224
|
+
/**
|
|
225
|
+
* Get current user state
|
|
226
|
+
*/
|
|
227
|
+
getUser(): UserState;
|
|
228
|
+
/**
|
|
229
|
+
* Capture an exception and send to error tracking
|
|
230
|
+
* @param error - The Error object to capture
|
|
231
|
+
* @param context - Optional additional context
|
|
232
|
+
*/
|
|
233
|
+
captureException(error: Error, context?: Record<string, unknown>): void;
|
|
234
|
+
/**
|
|
235
|
+
* Capture a message as an error event
|
|
236
|
+
* @param message - Error message
|
|
237
|
+
* @param level - Severity level
|
|
238
|
+
* @param context - Optional additional context
|
|
239
|
+
*/
|
|
240
|
+
captureMessage(message: string, level?: "error" | "fatal" | "warning", context?: Record<string, unknown>): void;
|
|
241
|
+
/**
|
|
242
|
+
* Add a breadcrumb for error context
|
|
243
|
+
* @param breadcrumb - Breadcrumb data (type, message, optional data)
|
|
244
|
+
*/
|
|
245
|
+
addBreadcrumb(breadcrumb: {
|
|
246
|
+
type: "click" | "navigation" | "network" | "console" | "custom";
|
|
247
|
+
message: string;
|
|
248
|
+
data?: Record<string, unknown>;
|
|
249
|
+
}): void;
|
|
250
|
+
/**
|
|
251
|
+
* Send a structured log event
|
|
252
|
+
* @param message - Log message
|
|
253
|
+
* @param level - Log level
|
|
254
|
+
* @param metadata - Optional additional data
|
|
255
|
+
*/
|
|
256
|
+
log(message: string, level: LogLevel, metadata?: Record<string, unknown>): void;
|
|
257
|
+
}
|
|
258
|
+
/**
|
|
259
|
+
* Storage interface for persistence
|
|
260
|
+
*/
|
|
261
|
+
export interface StorageInterface {
|
|
262
|
+
get(key: string): string | null;
|
|
263
|
+
set(key: string, value: string): void;
|
|
264
|
+
remove(key: string): void;
|
|
265
|
+
}
|
|
266
|
+
/**
|
|
267
|
+
* SDK library info
|
|
268
|
+
*/
|
|
269
|
+
export declare const LIBRARY_INFO: {
|
|
270
|
+
name: string;
|
|
271
|
+
version: string;
|
|
272
|
+
};
|
|
273
|
+
/**
|
|
274
|
+
* Default configuration values
|
|
275
|
+
*/
|
|
276
|
+
export declare const DEFAULT_CONFIG: {
|
|
277
|
+
readonly host: "https://thisbefine.com";
|
|
278
|
+
readonly flushAt: 20;
|
|
279
|
+
readonly flushInterval: 10000;
|
|
280
|
+
readonly sessionTimeout: number;
|
|
281
|
+
readonly debug: false;
|
|
282
|
+
readonly respectDNT: true;
|
|
283
|
+
readonly maxRetries: 3;
|
|
284
|
+
};
|
|
285
|
+
/**
|
|
286
|
+
* Storage key names
|
|
287
|
+
*/
|
|
288
|
+
export declare const STORAGE_KEYS: {
|
|
289
|
+
readonly ANONYMOUS_ID: "tif_anonymous_id";
|
|
290
|
+
readonly USER_ID: "tif_user_id";
|
|
291
|
+
readonly USER_TRAITS: "tif_user_traits";
|
|
292
|
+
readonly ACCOUNT_ID: "tif_account_id";
|
|
293
|
+
readonly ACCOUNT_TRAITS: "tif_account_traits";
|
|
294
|
+
readonly SESSION_ID: "tif_session_id";
|
|
295
|
+
readonly LAST_ACTIVITY: "tif_last_activity";
|
|
296
|
+
readonly OPT_OUT: "tif_opt_out";
|
|
297
|
+
};
|
|
298
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/core/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,UAAU,CAAC;AACnD,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAC;AAG1C;;GAEG;AACH,MAAM,WAAW,eAAe;IAC/B,iDAAiD;IACjD,MAAM,EAAE,MAAM,CAAC;IAEf,uDAAuD;IACvD,IAAI,CAAC,EAAE,MAAM,CAAC;IAEd,4DAA4D;IAC5D,OAAO,CAAC,EAAE,MAAM,CAAC;IAEjB,8DAA8D;IAC9D,aAAa,CAAC,EAAE,MAAM,CAAC;IAEvB,2DAA2D;IAC3D,cAAc,CAAC,EAAE,MAAM,CAAC;IAExB,iDAAiD;IACjD,YAAY,CAAC,EAAE,MAAM,CAAC;IAEtB,sDAAsD;IACtD,KAAK,CAAC,EAAE,OAAO,CAAC;IAEhB,0DAA0D;IAC1D,UAAU,CAAC,EAAE,OAAO,CAAC;IAErB,6DAA6D;IAC7D,UAAU,CAAC,EAAE,MAAM,CAAC;IAEpB,kCAAkC;IAClC,MAAM,CAAC,EAAE,kBAAkB,CAA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AE,MAAM,GAAG,MAAM,GAAG,IAAI,CAAC;IAChC,GAAG,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,IAAI,CAAC;IACtC,MAAM,CAAC,GAAG,EAAE,MAAM,GAAG,IAAI,CAAC;CAC1B;AAED;;GAEG;AACH,eAAO,MAAM,YAAY;;;CAGxB,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,cAAc;;;;;;;;CAQjB,CAAC;AAEX;;GAEG;AACH,eAAO,MAAM,YAAY;;;;;;;;;CASf,CAAC"}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { VERSION } from "./version";
|
|
2
|
+
/**
|
|
3
|
+
* SDK library info
|
|
4
|
+
*/
|
|
5
|
+
export const LIBRARY_INFO = {
|
|
6
|
+
name: "@thisbefine/analytics",
|
|
7
|
+
version: VERSION,
|
|
8
|
+
};
|
|
9
|
+
/**
|
|
10
|
+
* Default configuration values
|
|
11
|
+
*/
|
|
12
|
+
export const DEFAULT_CONFIG = {
|
|
13
|
+
host: "https://thisbefine.com",
|
|
14
|
+
flushAt: 20,
|
|
15
|
+
flushInterval: 10000,
|
|
16
|
+
sessionTimeout: 30 * 60 * 1000,
|
|
17
|
+
debug: false,
|
|
18
|
+
respectDNT: true,
|
|
19
|
+
maxRetries: 3,
|
|
20
|
+
};
|
|
21
|
+
/**
|
|
22
|
+
* Storage key names
|
|
23
|
+
*/
|
|
24
|
+
export const STORAGE_KEYS = {
|
|
25
|
+
ANONYMOUS_ID: "tif_anonymous_id",
|
|
26
|
+
USER_ID: "tif_user_id",
|
|
27
|
+
USER_TRAITS: "tif_user_traits",
|
|
28
|
+
ACCOUNT_ID: "tif_account_id",
|
|
29
|
+
ACCOUNT_TRAITS: "tif_account_traits",
|
|
30
|
+
SESSION_ID: "tif_session_id",
|
|
31
|
+
LAST_ACTIVITY: "tif_last_activity",
|
|
32
|
+
OPT_OUT: "tif_opt_out",
|
|
33
|
+
};
|
|
34
|
+
//# sourceMappingURL=types.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/core/types.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AA2TpC;;GAEG;AACH,MAAM,CAAC,MAAM,YAAY,GAAG;IAC3B,IAAI,EAAE,uBAAuB;IAC7B,OAAO,EAAE,OAAO;CAChB,CAAC;AAEF;;GAEG;AACH,MAAM,CAAC,MAAM,cAAc,GAAG;IAC7B,IAAI,EAAE,wBAAwB;IAC9B,OAAO,EAAE,EAAE;IACX,aAAa,EAAE,KAAK;IACpB,cAAc,EAAE,EAAE,GAAG,EAAE,GAAG,IAAI;IAC9B,KAAK,EAAE,KAAK;IACZ,UAAU,EAAE,IAAI;IAChB,UAAU,EAAE,CAAC;CACJ,CAAC;AAEX;;GAEG;AACH,MAAM,CAAC,MAAM,YAAY,GAAG;IAC3B,YAAY,EAAE,kBAAkB;IAChC,OAAO,EAAE,aAAa;IACtB,WAAW,EAAE,iBAAiB;IAC9B,UAAU,EAAE,gBAAgB;IAC5B,cAAc,EAAE,oBAAoB;IACpC,UAAU,EAAE,gBAAgB;IAC5B,aAAa,EAAE,mBAAmB;IAClC,OAAO,EAAE,aAAa;CACb,CAAC"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export interface ValidationResult {
|
|
2
|
+
valid: boolean;
|
|
3
|
+
error?: string;
|
|
4
|
+
}
|
|
5
|
+
export declare const isNonEmptyString: (value: unknown) => value is string;
|
|
6
|
+
export declare const validateEventName: (event: unknown) => ValidationResult;
|
|
7
|
+
export declare const validateUserId: (userId: unknown) => ValidationResult;
|
|
8
|
+
export declare const validateAccountId: (accountId: unknown) => ValidationResult;
|
|
9
|
+
export declare const validateProperties: (properties: unknown) => ValidationResult;
|
|
10
|
+
export declare const sanitizeString: (str: string, maxLength: number) => string;
|
|
11
|
+
//# sourceMappingURL=validation.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"validation.d.ts","sourceRoot":"","sources":["../../src/core/validation.ts"],"names":[],"mappings":"AAIA,MAAM,WAAW,gBAAgB;IAChC,KAAK,EAAE,OAAO,CAAC;IACf,KAAK,CAAC,EAAE,MAAM,CAAC;CACf;AAED,eAAO,MAAM,gBAAgB,GAAI,OAAO,OAAO,KAAG,KAAK,IAAI,MAE1D,CAAC;AAEF,eAAO,MAAM,iBAAiB,GAAI,OAAO,OAAO,KAAG,gBAWlD,CAAC;AAEF,eAAO,MAAM,cAAc,GAAI,QAAQ,OAAO,KAAG,gBAkBhD,CAAC;AAEF,eAAO,MAAM,iBAAiB,GAAI,WAAW,OAAO,KAAG,gBAkBtD,CAAC;AAEF,eAAO,MAAM,kBAAkB,GAAI,YAAY,OAAO,KAAG,gBA0BxD,CAAC;AAEF,eAAO,MAAM,cAAc,GAAI,KAAK,MAAM,EAAE,WAAW,MAAM,KAAG,MAG/D,CAAC"}
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
const MAX_STRING_LENGTH = 500;
|
|
2
|
+
const MAX_EVENT_NAME_LENGTH = 200;
|
|
3
|
+
const MAX_PROPERTIES_SIZE = 32 * 1024;
|
|
4
|
+
export const isNonEmptyString = (value) => {
|
|
5
|
+
return typeof value === "string" && value.trim().length > 0;
|
|
6
|
+
};
|
|
7
|
+
export const validateEventName = (event) => {
|
|
8
|
+
if (!isNonEmptyString(event)) {
|
|
9
|
+
return { valid: false, error: "Event name must be a non-empty string" };
|
|
10
|
+
}
|
|
11
|
+
if (event.length > MAX_EVENT_NAME_LENGTH) {
|
|
12
|
+
return {
|
|
13
|
+
valid: false,
|
|
14
|
+
error: `Event name exceeds ${MAX_EVENT_NAME_LENGTH} characters`,
|
|
15
|
+
};
|
|
16
|
+
}
|
|
17
|
+
return { valid: true };
|
|
18
|
+
};
|
|
19
|
+
export const validateUserId = (userId) => {
|
|
20
|
+
if (!isNonEmptyString(userId)) {
|
|
21
|
+
return { valid: false, error: "User ID must be a non-empty string" };
|
|
22
|
+
}
|
|
23
|
+
if (userId.length > MAX_STRING_LENGTH) {
|
|
24
|
+
return {
|
|
25
|
+
valid: false,
|
|
26
|
+
error: `User ID exceeds ${MAX_STRING_LENGTH} characters`,
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
if (userId === "undefined" ||
|
|
30
|
+
userId === "null" ||
|
|
31
|
+
userId === "[object Object]") {
|
|
32
|
+
return { valid: false, error: `Invalid user ID: "${userId}"` };
|
|
33
|
+
}
|
|
34
|
+
return { valid: true };
|
|
35
|
+
};
|
|
36
|
+
export const validateAccountId = (accountId) => {
|
|
37
|
+
if (!isNonEmptyString(accountId)) {
|
|
38
|
+
return { valid: false, error: "Account ID must be a non-empty string" };
|
|
39
|
+
}
|
|
40
|
+
if (accountId.length > MAX_STRING_LENGTH) {
|
|
41
|
+
return {
|
|
42
|
+
valid: false,
|
|
43
|
+
error: `Account ID exceeds ${MAX_STRING_LENGTH} characters`,
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
if (accountId === "undefined" ||
|
|
47
|
+
accountId === "null" ||
|
|
48
|
+
accountId === "[object Object]") {
|
|
49
|
+
return { valid: false, error: `Invalid account ID: "${accountId}"` };
|
|
50
|
+
}
|
|
51
|
+
return { valid: true };
|
|
52
|
+
};
|
|
53
|
+
export const validateProperties = (properties) => {
|
|
54
|
+
if (properties === undefined || properties === null) {
|
|
55
|
+
return { valid: true };
|
|
56
|
+
}
|
|
57
|
+
if (typeof properties !== "object" || Array.isArray(properties)) {
|
|
58
|
+
return { valid: false, error: "Properties must be an object" };
|
|
59
|
+
}
|
|
60
|
+
try {
|
|
61
|
+
const json = JSON.stringify(properties);
|
|
62
|
+
if (json.length > MAX_PROPERTIES_SIZE) {
|
|
63
|
+
return {
|
|
64
|
+
valid: false,
|
|
65
|
+
error: `Properties exceed ${MAX_PROPERTIES_SIZE} bytes`,
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
catch {
|
|
70
|
+
return {
|
|
71
|
+
valid: false,
|
|
72
|
+
error: "Properties contain circular references or non-serializable values",
|
|
73
|
+
};
|
|
74
|
+
}
|
|
75
|
+
return { valid: true };
|
|
76
|
+
};
|
|
77
|
+
export const sanitizeString = (str, maxLength) => {
|
|
78
|
+
if (str.length <= maxLength)
|
|
79
|
+
return str;
|
|
80
|
+
return str.slice(0, maxLength);
|
|
81
|
+
};
|
|
82
|
+
//# sourceMappingURL=validation.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"validation.js","sourceRoot":"","sources":["../../src/core/validation.ts"],"names":[],"mappings":"AAAA,MAAM,iBAAiB,GAAG,GAAG,CAAC;AAC9B,MAAM,qBAAqB,GAAG,GAAG,CAAC;AAClC,MAAM,mBAAmB,GAAG,EAAE,GAAG,IAAI,CAAC;AAOtC,MAAM,CAAC,MAAM,gBAAgB,GAAG,CAAC,KAAc,EAAmB,EAAE;IACnE,OAAO,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,CAAC,IAAI,EAAE,CAAC,MAAM,GAAG,CAAC,CAAC;AAC7D,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,iBAAiB,GAAG,CAAC,KAAc,EAAoB,EAAE;IACrE,IAAI,CAAC,gBAAgB,CAAC,KAAK,CAAC,EAAE,CAAC;QAC9B,OAAO,EAAE,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,uCAAuC,EAAE,CAAC;IACzE,CAAC;IACD,IAAI,KAAK,CAAC,MAAM,GAAG,qBAAqB,EAAE,CAAC;QAC1C,OAAO;YACN,KAAK,EAAE,KAAK;YACZ,KAAK,EAAE,sBAAsB,qBAAqB,aAAa;SAC/D,CAAC;IACH,CAAC;IACD,OAAO,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC;AACxB,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,cAAc,GAAG,CAAC,MAAe,EAAoB,EAAE;IACnE,IAAI,CAAC,gBAAgB,C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,SAAS,IAAI,UAAU,KAAK,IAAI,EAAE,CAAC;QACrD,OAAO,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC;IACxB,CAAC;IAED,IAAI,OAAO,UAAU,KAAK,QAAQ,IAAI,KAAK,CAAC,OAAO,CAAC,UAAU,CAAC,EAAE,CAAC;QACjE,OAAO,EAAE,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,8BAA8B,EAAE,CAAC;IAChE,CAAC;IAED,IAAI,CAAC;QACJ,MAAM,IAAI,GAAG,IAAI,CAAC,SAAS,CAAC,UAAU,CAAC,CAAC;QACxC,IAAI,IAAI,CAAC,MAAM,GAAG,mBAAmB,EAAE,CAAC;YACvC,OAAO;gBACN,KAAK,EAAE,KAAK;gBACZ,KAAK,EAAE,qBAAqB,mBAAmB,QAAQ;aACvD,CAAC;QACH,CAAC;IACF,CAAC;IAAC,MAAM,CAAC;QACR,OAAO;YACN,KAAK,EAAE,KAAK;YACZ,KAAK,EACJ,mEAAmE;SACpE,CAAC;IACH,CAAC;IAED,OAAO,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC;AACxB,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,cAAc,GAAG,CAAC,GAAW,EAAE,SAAiB,EAAU,EAAE;IACxE,IAAI,GAAG,CAAC,MAAM,IAAI,SAAS;QAAE,OAAO,GAAG,CAAC;IACxC,OAAO,GAAG,CAAC,KAAK,CAAC,CAAC,EAAE,SAAS,CAAC,CAAC;AAChC,CAAC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"version.d.ts","sourceRoot":"","sources":["../../src/core/version.ts"],"names":[],"mappings":"AAGA,eAAO,MAAM,OAAO,UAAU,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"version.js","sourceRoot":"","sources":["../../src/core/version.ts"],"names":[],"mappings":"AAAA,gDAAgD;AAChD,uBAAuB;AAEvB,MAAM,CAAC,MAAM,OAAO,GAAG,OAAO,CAAC"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @thisbefine/analytics
|
|
3
|
+
*
|
|
4
|
+
* Lightweight analytics SDK for tracking events, identifying users,
|
|
5
|
+
* and measuring what matters for your SaaS.
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* ```typescript
|
|
9
|
+
* import { createAnalytics } from '@thisbefine/analytics';
|
|
10
|
+
*
|
|
11
|
+
* const analytics = createAnalytics({
|
|
12
|
+
* apiKey: 'tbf_xxx',
|
|
13
|
+
* debug: process.env.NODE_ENV === 'development',
|
|
14
|
+
* });
|
|
15
|
+
*
|
|
16
|
+
* // Track events
|
|
17
|
+
* analytics.track('button_clicked', { buttonId: 'signup' });
|
|
18
|
+
*
|
|
19
|
+
* // Identify users
|
|
20
|
+
* analytics.identify('user_123', { email: 'user@example.com', plan: 'pro' });
|
|
21
|
+
*
|
|
22
|
+
* // Track page views
|
|
23
|
+
* analytics.page('/dashboard');
|
|
24
|
+
*
|
|
25
|
+
* // Reset on logout
|
|
26
|
+
* analytics.reset();
|
|
27
|
+
* ```
|
|
28
|
+
*
|
|
29
|
+
* For React/Next.js integration, use:
|
|
30
|
+
* ```typescript
|
|
31
|
+
* import { AnalyticsProvider, useAnalytics } from '@thisbefine/analytics/react';
|
|
32
|
+
* // or
|
|
33
|
+
* import { AnalyticsProvider, useAnalytics } from '@thisbefine/analytics/next';
|
|
34
|
+
* ```
|
|
35
|
+
*
|
|
36
|
+
* @packageDocumentation
|
|
37
|
+
*/
|
|
38
|
+
export { createAnalytics, getAnalytics, initAnalytics, } from "./core/analytics";
|
|
39
|
+
export type { Breadcrumb, ErrorCaptureConfig, ErrorPayload, } from "./core/errors";
|
|
40
|
+
export type { LogLevel } from "./core/logging";
|
|
41
|
+
export type { AccountTraits, Analytics, AnalyticsConfig, AnalyticsEvent, EventContext, GroupEvent, IdentifyEvent, PageEvent, TrackEvent, UserState, UserTraits, } from "./core/types";
|
|
42
|
+
export { DEFAULT_CONFIG, LIBRARY_INFO, STORAGE_KEYS } from "./core/types";
|
|
43
|
+
export type { BugReportWidgetOptions } from "./widget/bug-report";
|
|
44
|
+
export { createBugReportWidget } from "./widget/bug-report";
|
|
45
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAoCG;AAEH,OAAO,EACN,eAAe,EACf,YAAY,EACZ,aAAa,GACb,MAAM,kBAAkB,CAAC;AAE1B,YAAY,EACX,UAAU,EACV,kBAAkB,EAClB,YAAY,GACZ,MAAM,eAAe,CAAC;AAEvB,YAAY,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAE/C,YAAY,EACX,aAAa,EACb,SAAS,EACT,eAAe,EACf,cAAc,EACd,YAAY,EACZ,UAAU,EACV,aAAa,EACb,SAAS,EACT,UAAU,EACV,SAAS,EACT,UAAU,GACV,MAAM,cAAc,CAAC;AAEtB,OAAO,EAAE,cAAc,EAAE,YAAY,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAE1E,YAAY,EAAE,sBAAsB,EAAE,MAAM,qBAAqB,CAAC;AAClE,OAAO,EAAE,qBAAqB,EAAE,MAAM,qBAAqB,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @thisbefine/analytics
|
|
3
|
+
*
|
|
4
|
+
* Lightweight analytics SDK for tracking events, identifying users,
|
|
5
|
+
* and measuring what matters for your SaaS.
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* ```typescript
|
|
9
|
+
* import { createAnalytics } from '@thisbefine/analytics';
|
|
10
|
+
*
|
|
11
|
+
* const analytics = createAnalytics({
|
|
12
|
+
* apiKey: 'tbf_xxx',
|
|
13
|
+
* debug: process.env.NODE_ENV === 'development',
|
|
14
|
+
* });
|
|
15
|
+
*
|
|
16
|
+
* // Track events
|
|
17
|
+
* analytics.track('button_clicked', { buttonId: 'signup' });
|
|
18
|
+
*
|
|
19
|
+
* // Identify users
|
|
20
|
+
* analytics.identify('user_123', { email: 'user@example.com', plan: 'pro' });
|
|
21
|
+
*
|
|
22
|
+
* // Track page views
|
|
23
|
+
* analytics.page('/dashboard');
|
|
24
|
+
*
|
|
25
|
+
* // Reset on logout
|
|
26
|
+
* analytics.reset();
|
|
27
|
+
* ```
|
|
28
|
+
*
|
|
29
|
+
* For React/Next.js integration, use:
|
|
30
|
+
* ```typescript
|
|
31
|
+
* import { AnalyticsProvider, useAnalytics } from '@thisbefine/analytics/react';
|
|
32
|
+
* // or
|
|
33
|
+
* import { AnalyticsProvider, useAnalytics } from '@thisbefine/analytics/next';
|
|
34
|
+
* ```
|
|
35
|
+
*
|
|
36
|
+
* @packageDocumentation
|
|
37
|
+
*/
|
|
38
|
+
export { createAnalytics, getAnalytics, initAnalytics, } from "./core/analytics";
|
|
39
|
+
export { DEFAULT_CONFIG, LIBRARY_INFO, STORAGE_KEYS } from "./core/types";
|
|
40
|
+
export { createBugReportWidget } from "./widget/bug-report";
|
|
41
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAoCG;AAEH,OAAO,EACN,eAAe,EACf,YAAY,EACZ,aAAa,GACb,MAAM,kBAAkB,CAAC;AAwB1B,OAAO,EAAE,cAAc,EAAE,YAAY,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAG1E,OAAO,EAAE,qBAAqB,EAAE,MAAM,qBAAqB,CAAC"}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import type { AnalyticsConfig } from "../core/types";
|
|
2
|
+
export interface NextAnalyticsProps {
|
|
3
|
+
/**
|
|
4
|
+
* Your Thisbefine API key.
|
|
5
|
+
* If not provided, reads from NEXT_PUBLIC_TBF_API_KEY environment variable.
|
|
6
|
+
*/
|
|
7
|
+
apiKey?: string;
|
|
8
|
+
/**
|
|
9
|
+
* API host URL.
|
|
10
|
+
* Defaults to https://thisbefine.com
|
|
11
|
+
* For local development, use http://localhost:3000
|
|
12
|
+
*/
|
|
13
|
+
host?: string;
|
|
14
|
+
/**
|
|
15
|
+
* Enable debug logging to console.
|
|
16
|
+
* @default false
|
|
17
|
+
*/
|
|
18
|
+
debug?: boolean;
|
|
19
|
+
/**
|
|
20
|
+
* Automatically track page views on route changes.
|
|
21
|
+
* @default true
|
|
22
|
+
*/
|
|
23
|
+
trackPageviews?: boolean;
|
|
24
|
+
/**
|
|
25
|
+
* Additional configuration options
|
|
26
|
+
*/
|
|
27
|
+
config?: Omit<AnalyticsConfig, "apiKey" | "host" | "debug">;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Next.js Analytics component - initializes Thisbefine analytics
|
|
31
|
+
*
|
|
32
|
+
* Optimized for the Next.js App Router with automatic pageview tracking
|
|
33
|
+
* on client-side navigations using usePathname/useSearchParams.
|
|
34
|
+
*
|
|
35
|
+
* Add this component once at the root of your app (e.g., in layout.tsx).
|
|
36
|
+
*
|
|
37
|
+
* @example
|
|
38
|
+
* ```tsx
|
|
39
|
+
* // app/layout.tsx
|
|
40
|
+
* // Zero config - reads from NEXT_PUBLIC_TBF_API_KEY
|
|
41
|
+
* import { Analytics } from '@thisbefine/analytics/next';
|
|
42
|
+
*
|
|
43
|
+
* export default function RootLayout({ children }) {
|
|
44
|
+
* return (
|
|
45
|
+
* <html>
|
|
46
|
+
* <body>
|
|
47
|
+
* {children}
|
|
48
|
+
* <Analytics />
|
|
49
|
+
* </body>
|
|
50
|
+
* </html>
|
|
51
|
+
* );
|
|
52
|
+
* }
|
|
53
|
+
*
|
|
54
|
+
* // With explicit config
|
|
55
|
+
* <Analytics apiKey="tbf_xxx" host="http://localhost:3000" debug />
|
|
56
|
+
* ```
|
|
57
|
+
*/
|
|
58
|
+
export declare const Analytics: ({ apiKey, host, debug, trackPageviews, config, }: NextAnalyticsProps) => import("react/jsx-runtime").JSX.Element | null;
|
|
59
|
+
//# sourceMappingURL=analytics.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"analytics.d.ts","sourceRoot":"","sources":["../../src/next/analytics.tsx"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,eAAe,CAAC;AAErD,MAAM,WAAW,kBAAkB;IAClC;;;OAGG;IACH,MAAM,CAAC,EAAE,MAAM,CAAC;IAEhB;;;;OAIG;IACH,IAAI,CAAC,EAAE,MAAM,CAAC;IAEd;;;OAGG;IACH,KAAK,CAAC,EAAE,OAAO,CAAC;IAEhB;;;OAGG;IACH,cAAc,CAAC,EAAE,OAAO,CAAC;IAEzB;;OAEG;IACH,MAAM,CAAC,EAAE,IAAI,CAAC,eAAe,EAAE,QAAQ,GAAG,MAAM,GAAG,OAAO,CAAC,CAAC;CAC5D;AAmCD;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AACH,eAAO,MAAM,SAAS,GAAI,kDAMvB,kBAAkB,mDAmCpB,CAAC"}
|