@stacksee/analytics 0.4.3 → 0.4.5

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 (41) hide show
  1. package/dist/base.provider-AfFL5W_P.js +19 -0
  2. package/dist/client-RZPcOfAk.js +86 -0
  3. package/dist/client.d.ts +68 -2
  4. package/dist/client.js +576 -10
  5. package/dist/index.d.ts +2 -2
  6. package/dist/index.js +1 -14
  7. package/dist/providers/client.js +6 -0
  8. package/dist/{src/providers/index.d.ts → providers/server.d.ts} +0 -2
  9. package/dist/providers/server.js +6 -0
  10. package/dist/{providers.js → server-CMRw9K0d.js} +2 -5
  11. package/dist/server.d.ts +38 -2
  12. package/dist/server.js +18 -14
  13. package/package.json +8 -4
  14. package/readme.md +11 -5
  15. package/dist/client-CyvENC-f.js +0 -577
  16. package/dist/client-MwIAm9fk.js +0 -96
  17. package/dist/environment-Bnc8FqHv.js +0 -6
  18. package/dist/providers.d.ts +0 -2
  19. package/dist/src/client.d.ts +0 -68
  20. package/dist/src/index.d.ts +0 -5
  21. package/dist/src/server.d.ts +0 -38
  22. package/dist/test/base-provider.test.d.ts +0 -1
  23. package/dist/test/client-analytics.test.d.ts +0 -1
  24. package/dist/test/events.test.d.ts +0 -1
  25. package/dist/test/index.test.d.ts +0 -1
  26. package/dist/test/mock-provider.d.ts +0 -34
  27. package/dist/test/providers.test.d.ts +0 -1
  28. package/dist/test/server-analytics.test.d.ts +0 -1
  29. package/dist/test/server.test.d.ts +0 -1
  30. package/dist/test/utils.test.d.ts +0 -1
  31. /package/dist/{src/adapters → adapters}/client/browser-analytics.d.ts +0 -0
  32. /package/dist/{src/adapters → adapters}/server/server-analytics.d.ts +0 -0
  33. /package/dist/{src/client → client}/index.d.ts +0 -0
  34. /package/dist/{src/core → core}/events/index.d.ts +0 -0
  35. /package/dist/{src/core → core}/events/types.d.ts +0 -0
  36. /package/dist/{src/providers → providers}/base.provider.d.ts +0 -0
  37. /package/dist/{src/providers → providers}/client.d.ts +0 -0
  38. /package/dist/{src/providers → providers}/posthog/client.d.ts +0 -0
  39. /package/dist/{src/providers → providers}/posthog/server.d.ts +0 -0
  40. /package/dist/{src/server → server}/index.d.ts +0 -0
  41. /package/dist/{src/utils → utils}/environment.d.ts +0 -0
package/dist/client.js CHANGED
@@ -1,12 +1,578 @@
1
- import { c as s, c as t, g as c, i, a as n, p as r, r as l, b as y, t as g } from "./client-CyvENC-f.js";
1
+ var c = Object.defineProperty;
2
+ var u = (t, e, i) => e in t ? c(t, e, { enumerable: !0, configurable: !0, writable: !0, value: i }) : t[e] = i;
3
+ var n = (t, e, i) => u(t, typeof e != "symbol" ? e + "" : e, i);
4
+ import { i as h } from "./client-RZPcOfAk.js";
5
+ import { P } from "./client-RZPcOfAk.js";
6
+ import { B as O } from "./base.provider-AfFL5W_P.js";
7
+ class p {
8
+ /**
9
+ * Creates a new BrowserAnalytics instance for client-side event tracking.
10
+ *
11
+ * Automatically generates a session ID and sets up the analytics context.
12
+ * The instance will be ready to track events once initialized.
13
+ *
14
+ * @param config Analytics configuration including providers and default context
15
+ * @param config.providers Array of analytics provider instances (e.g., PostHogClientProvider)
16
+ * @param config.defaultContext Optional default context to include with all events
17
+ *
18
+ * @example
19
+ * ```typescript
20
+ * import { BrowserAnalytics } from '@stacksee/analytics/client';
21
+ * import { PostHogClientProvider } from '@stacksee/analytics/providers/posthog';
22
+ *
23
+ * const analytics = new BrowserAnalytics({
24
+ * providers: [
25
+ * new PostHogClientProvider({
26
+ * apiKey: 'your-posthog-api-key',
27
+ * host: 'https://app.posthog.com'
28
+ * })
29
+ * ],
30
+ * defaultContext: {
31
+ * app: { version: '1.0.0' }
32
+ * }
33
+ * });
34
+ *
35
+ * await analytics.initialize();
36
+ * ```
37
+ */
38
+ constructor(e) {
39
+ n(this, "providers", []);
40
+ n(this, "context", {});
41
+ n(this, "userId");
42
+ n(this, "sessionId");
43
+ n(this, "initialized", !1);
44
+ n(this, "initializePromise");
45
+ this.providers = e.providers, e.defaultContext && (this.context = { ...e.defaultContext }), this.sessionId = this.generateSessionId();
46
+ }
47
+ /**
48
+ * Initializes all analytics providers and sets up browser context.
49
+ *
50
+ * This method must be called before tracking events. It initializes all configured
51
+ * providers and automatically captures browser context including page information,
52
+ * device type, OS, and browser details.
53
+ *
54
+ * The method is safe to call multiple times and will not re-initialize if already done.
55
+ * If called while initialization is in progress, it returns the existing promise.
56
+ *
57
+ * @returns Promise that resolves when initialization is complete
58
+ *
59
+ * @example
60
+ * ```typescript
61
+ * const analytics = new BrowserAnalytics({ providers: [] });
62
+ *
63
+ * // Initialize before tracking events
64
+ * await analytics.initialize();
65
+ *
66
+ * // Now ready to track events
67
+ * analytics.track('page_viewed', { page: '/dashboard' });
68
+ * ```
69
+ *
70
+ * @example
71
+ * ```typescript
72
+ * // Safe to call multiple times
73
+ * await analytics.initialize(); // First call does the work
74
+ * await analytics.initialize(); // Subsequent calls return immediately
75
+ * ```
76
+ */
77
+ async initialize() {
78
+ if (h() && !this.initialized)
79
+ return this.initializePromise ? this.initializePromise : (this.initializePromise = this._doInitialize(), this.initializePromise);
80
+ }
81
+ async _doInitialize() {
82
+ const e = this.providers.map(
83
+ (i) => i.initialize()
84
+ );
85
+ await Promise.all(e), this.initialized = !0, this.updateContext({
86
+ page: {
87
+ path: window.location.pathname,
88
+ title: document.title,
89
+ referrer: document.referrer
90
+ },
91
+ device: {
92
+ type: this.getDeviceType(),
93
+ os: this.getOS(),
94
+ browser: this.getBrowser()
95
+ }
96
+ });
97
+ }
98
+ async ensureInitialized() {
99
+ !this.initialized && !this.initializePromise ? await this.initialize() : this.initializePromise && await this.initializePromise;
100
+ }
101
+ /**
102
+ * Identifies a user with optional traits.
103
+ *
104
+ * Associates subsequent events with the specified user ID and optionally
105
+ * sets user properties. This method should be called when a user logs in
106
+ * or when you want to associate events with a known user.
107
+ *
108
+ * The method automatically ensures initialization but doesn't block execution
109
+ * if initialization is still in progress.
110
+ *
111
+ * @param userId Unique identifier for the user (e.g., database ID, email)
112
+ * @param traits Optional user properties and characteristics
113
+ *
114
+ * @example
115
+ * ```typescript
116
+ * // Basic user identification
117
+ * analytics.identify('user-123');
118
+ * ```
119
+ *
120
+ * @example
121
+ * ```typescript
122
+ * // Identify with user traits
123
+ * analytics.identify('user-123', {
124
+ * email: 'john@example.com',
125
+ * name: 'John Doe',
126
+ * plan: 'pro',
127
+ * signupDate: '2024-01-15',
128
+ * preferences: {
129
+ * newsletter: true,
130
+ * notifications: false
131
+ * }
132
+ * });
133
+ * ```
134
+ *
135
+ * @example
136
+ * ```typescript
137
+ * // In a login handler
138
+ * async function handleLogin(email: string, password: string) {
139
+ * const user = await login(email, password);
140
+ *
141
+ * analytics.identify(user.id, {
142
+ * email: user.email,
143
+ * name: user.name,
144
+ * lastLogin: new Date().toISOString()
145
+ * });
146
+ * }
147
+ * ```
148
+ */
149
+ identify(e, i) {
150
+ this.userId = e, this.ensureInitialized().catch((r) => {
151
+ console.error("[Analytics] Failed to initialize during identify:", r);
152
+ });
153
+ for (const r of this.providers)
154
+ r.identify(e, i);
155
+ }
156
+ /**
157
+ * Tracks a custom event with properties.
158
+ *
159
+ * This is the main method for tracking user interactions and business events.
160
+ * The method ensures initialization before tracking and sends the event to all
161
+ * configured providers. Events are enriched with context information like
162
+ * timestamp, user ID, session ID, and browser context.
163
+ *
164
+ * If providers are configured, the method waits for all providers to complete
165
+ * tracking. Failed providers don't prevent others from succeeding.
166
+ *
167
+ * @param eventName Name of the event to track (must match your event definitions)
168
+ * @param properties Event-specific properties and data
169
+ * @returns Promise that resolves when tracking is complete for all providers
170
+ *
171
+ * @example
172
+ * ```typescript
173
+ * // Track a simple event
174
+ * await analytics.track('button_clicked', {
175
+ * buttonId: 'signup-cta',
176
+ * page: '/landing'
177
+ * });
178
+ * ```
179
+ *
180
+ * @example
181
+ * ```typescript
182
+ * // Track a purchase event
183
+ * await analytics.track('purchase_completed', {
184
+ * orderId: 'order-123',
185
+ * amount: 99.99,
186
+ * currency: 'USD',
187
+ * items: [
188
+ * { id: 'item-1', name: 'Product A', price: 49.99 },
189
+ * { id: 'item-2', name: 'Product B', price: 49.99 }
190
+ * ],
191
+ * paymentMethod: 'credit_card'
192
+ * });
193
+ * ```
194
+ *
195
+ * @example
196
+ * ```typescript
197
+ * // Fire-and-forget for non-critical events (client-side typical usage)
198
+ * analytics.track('feature_viewed', { feature: 'dashboard' });
199
+ * // Don't await - let it track in the background
200
+ * ```
201
+ *
202
+ * @example
203
+ * ```typescript
204
+ * // Error handling
205
+ * try {
206
+ * await analytics.track('critical_event', { data: 'important' });
207
+ * } catch (error) {
208
+ * // Individual provider failures are handled internally
209
+ * // This catch would only trigger for initialization failures
210
+ * console.error('Failed to track event:', error);
211
+ * }
212
+ * ```
213
+ */
214
+ async track(e, i) {
215
+ await this.ensureInitialized();
216
+ const r = {
217
+ action: e,
218
+ category: this.getCategoryFromEventName(e),
219
+ properties: i,
220
+ timestamp: Date.now(),
221
+ userId: this.userId,
222
+ sessionId: this.sessionId
223
+ }, o = this.providers.map(async (d) => {
224
+ try {
225
+ await d.track(r, this.context);
226
+ } catch (l) {
227
+ console.error(
228
+ `[Analytics] Provider ${d.name} failed to track event:`,
229
+ l
230
+ );
231
+ }
232
+ });
233
+ await Promise.all(o);
234
+ }
235
+ /**
236
+ * Tracks a page view event.
237
+ *
238
+ * Automatically captures current page information (path, title, referrer) and
239
+ * updates the analytics context. This method should be called when users
240
+ * navigate to a new page or view.
241
+ *
242
+ * The method automatically ensures initialization but doesn't block execution
243
+ * if initialization is still in progress.
244
+ *
245
+ * @param properties Optional properties to include with the page view
246
+ *
247
+ * @example
248
+ * ```typescript
249
+ * // Basic page view tracking
250
+ * analytics.pageView();
251
+ * ```
252
+ *
253
+ * @example
254
+ * ```typescript
255
+ * // Page view with additional properties
256
+ * analytics.pageView({
257
+ * category: 'product',
258
+ * productId: 'prod-123',
259
+ * loadTime: 1200,
260
+ * source: 'organic_search'
261
+ * });
262
+ * ```
263
+ *
264
+ * @example
265
+ * ```typescript
266
+ * // In a SvelteKit app with automatic navigation tracking
267
+ * import { afterNavigate } from '$app/navigation';
268
+ *
269
+ * afterNavigate(() => {
270
+ * analytics.pageView({
271
+ * timestamp: Date.now(),
272
+ * userAgent: navigator.userAgent
273
+ * });
274
+ * });
275
+ * ```
276
+ *
277
+ * @example
278
+ * ```typescript
279
+ * // In a React app with React Router
280
+ * import { useEffect } from 'react';
281
+ * import { useLocation } from 'react-router-dom';
282
+ *
283
+ * function usePageTracking() {
284
+ * const location = useLocation();
285
+ *
286
+ * useEffect(() => {
287
+ * analytics.pageView({
288
+ * path: location.pathname,
289
+ * search: location.search
290
+ * });
291
+ * }, [location]);
292
+ * }
293
+ * ```
294
+ */
295
+ pageView(e) {
296
+ this.ensureInitialized().catch((i) => {
297
+ console.error("[Analytics] Failed to initialize during pageView:", i);
298
+ }), this.updateContext({
299
+ page: {
300
+ path: window.location.pathname,
301
+ title: document.title,
302
+ referrer: document.referrer
303
+ }
304
+ });
305
+ for (const i of this.providers)
306
+ i.pageView(e, this.context);
307
+ }
308
+ /**
309
+ * Tracks when a user leaves a page.
310
+ *
311
+ * This method should be called before navigation to track user engagement
312
+ * and session duration. It's useful for understanding how long users spend
313
+ * on different pages and their navigation patterns.
314
+ *
315
+ * Note: Not all analytics providers support page leave events. The method
316
+ * will only call providers that implement the pageLeave method.
317
+ *
318
+ * @param properties Optional properties to include with the page leave event
319
+ *
320
+ * @example
321
+ * ```typescript
322
+ * // Basic page leave tracking
323
+ * analytics.pageLeave();
324
+ * ```
325
+ *
326
+ * @example
327
+ * ```typescript
328
+ * // Page leave with engagement metrics
329
+ * analytics.pageLeave({
330
+ * timeOnPage: 45000, // 45 seconds
331
+ * scrollDepth: 80, // percentage
332
+ * interactions: 3, // number of clicks/interactions
333
+ * exitIntent: true // detected exit intent
334
+ * });
335
+ * ```
336
+ *
337
+ * @example
338
+ * ```typescript
339
+ * // In a SvelteKit app with automatic navigation tracking
340
+ * import { beforeNavigate } from '$app/navigation';
341
+ *
342
+ * let pageStartTime = Date.now();
343
+ *
344
+ * beforeNavigate(() => {
345
+ * analytics.pageLeave({
346
+ * duration: Date.now() - pageStartTime,
347
+ * exitType: 'navigation'
348
+ * });
349
+ * });
350
+ * ```
351
+ *
352
+ * @example
353
+ * ```typescript
354
+ * // Track page leave on browser unload
355
+ * window.addEventListener('beforeunload', () => {
356
+ * analytics.pageLeave({
357
+ * exitType: 'browser_close',
358
+ * sessionDuration: Date.now() - sessionStartTime
359
+ * });
360
+ * });
361
+ * ```
362
+ */
363
+ pageLeave(e) {
364
+ this.ensureInitialized().catch((i) => {
365
+ console.error("[Analytics] Failed to initialize during pageLeave:", i);
366
+ });
367
+ for (const i of this.providers)
368
+ i.pageLeave && i.pageLeave(e, this.context);
369
+ }
370
+ /**
371
+ * Resets the analytics state, clearing user ID and generating a new session.
372
+ *
373
+ * This method should be called when a user logs out or when you want to
374
+ * start tracking a new user session. It clears the current user ID,
375
+ * generates a new session ID, and calls reset on all providers.
376
+ *
377
+ * Use this method to ensure user privacy and accurate session tracking
378
+ * when users switch accounts or log out.
379
+ *
380
+ * @example
381
+ * ```typescript
382
+ * // Basic reset on logout
383
+ * analytics.reset();
384
+ * ```
385
+ *
386
+ * @example
387
+ * ```typescript
388
+ * // In a logout handler
389
+ * async function handleLogout() {
390
+ * // Track logout event before resetting
391
+ * await analytics.track('user_logged_out', {
392
+ * sessionDuration: Date.now() - sessionStartTime
393
+ * });
394
+ *
395
+ * // Reset analytics state
396
+ * analytics.reset();
397
+ *
398
+ * // Clear user data and redirect
399
+ * clearUserData();
400
+ * window.location.href = '/login';
401
+ * }
402
+ * ```
403
+ *
404
+ * @example
405
+ * ```typescript
406
+ * // Account switching scenario
407
+ * async function switchAccount(newUserId: string) {
408
+ * // Reset to clear previous user
409
+ * analytics.reset();
410
+ *
411
+ * // Identify the new user
412
+ * analytics.identify(newUserId);
413
+ *
414
+ * // Track account switch
415
+ * analytics.track('account_switched', {
416
+ * newUserId,
417
+ * timestamp: Date.now()
418
+ * });
419
+ * }
420
+ * ```
421
+ */
422
+ reset() {
423
+ this.userId = void 0, this.sessionId = this.generateSessionId();
424
+ for (const e of this.providers)
425
+ e.reset();
426
+ }
427
+ /**
428
+ * Updates the analytics context with new information.
429
+ *
430
+ * The context is included with all tracked events and provides additional
431
+ * metadata about the user's environment, current page, device, and other
432
+ * relevant information. This method merges new context with existing context.
433
+ *
434
+ * Context typically includes page information, device details, UTM parameters,
435
+ * and custom application context.
436
+ *
437
+ * @param context Partial context to merge with existing context
438
+ * @param context.page Page-related context (path, title, referrer)
439
+ * @param context.device Device-related context (type, OS, browser)
440
+ * @param context.utm UTM campaign tracking parameters
441
+ * @param context.app Application-specific context
442
+ *
443
+ * @example
444
+ * ```typescript
445
+ * // Update page context
446
+ * analytics.updateContext({
447
+ * page: {
448
+ * path: '/dashboard',
449
+ * title: 'User Dashboard',
450
+ * referrer: 'https://google.com'
451
+ * }
452
+ * });
453
+ * ```
454
+ *
455
+ * @example
456
+ * ```typescript
457
+ * // Add UTM parameters from URL
458
+ * const urlParams = new URLSearchParams(window.location.search);
459
+ * analytics.updateContext({
460
+ * utm: {
461
+ * source: urlParams.get('utm_source') || undefined,
462
+ * medium: urlParams.get('utm_medium') || undefined,
463
+ * campaign: urlParams.get('utm_campaign') || undefined,
464
+ * term: urlParams.get('utm_term') || undefined,
465
+ * content: urlParams.get('utm_content') || undefined
466
+ * }
467
+ * });
468
+ * ```
469
+ *
470
+ * @example
471
+ * ```typescript
472
+ * // Update application context
473
+ * analytics.updateContext({
474
+ * app: {
475
+ * version: '2.1.0',
476
+ * feature: 'beta-dashboard',
477
+ * theme: 'dark'
478
+ * },
479
+ * device: {
480
+ * screenWidth: window.innerWidth,
481
+ * screenHeight: window.innerHeight,
482
+ * timezone: Intl.DateTimeFormat().resolvedOptions().timeZone
483
+ * }
484
+ * });
485
+ * ```
486
+ */
487
+ updateContext(e) {
488
+ var i, r, o;
489
+ this.context = {
490
+ ...this.context,
491
+ ...e,
492
+ page: e.page ? {
493
+ path: e.page.path || ((i = this.context.page) == null ? void 0 : i.path) || window.location.pathname,
494
+ title: e.page.title || ((r = this.context.page) == null ? void 0 : r.title),
495
+ referrer: e.page.referrer || ((o = this.context.page) == null ? void 0 : o.referrer)
496
+ } : this.context.page,
497
+ device: {
498
+ ...this.context.device,
499
+ ...e.device
500
+ },
501
+ utm: {
502
+ ...this.context.utm,
503
+ ...e.utm
504
+ }
505
+ };
506
+ }
507
+ getCategoryFromEventName(e) {
508
+ const i = e.split("_");
509
+ return i.length > 1 && i[0] ? i[0] : "engagement";
510
+ }
511
+ generateSessionId() {
512
+ return `${Date.now()}-${Math.random().toString(36).substring(2, 11)}`;
513
+ }
514
+ getDeviceType() {
515
+ const e = navigator.userAgent;
516
+ return /tablet|ipad|playbook|silk/i.test(e) ? "tablet" : /mobile|iphone|ipod|android|blackberry|opera|mini|windows\sce|palm|smartphone|iemobile/i.test(
517
+ e
518
+ ) ? "mobile" : "desktop";
519
+ }
520
+ getOS() {
521
+ const e = navigator.userAgent;
522
+ return e.indexOf("Win") !== -1 ? "Windows" : e.indexOf("Mac") !== -1 ? "macOS" : e.indexOf("Linux") !== -1 ? "Linux" : e.indexOf("Android") !== -1 ? "Android" : e.indexOf("iOS") !== -1 ? "iOS" : "Unknown";
523
+ }
524
+ getBrowser() {
525
+ const e = navigator.userAgent;
526
+ return e.indexOf("Chrome") !== -1 ? "Chrome" : e.indexOf("Safari") !== -1 ? "Safari" : e.indexOf("Firefox") !== -1 ? "Firefox" : e.indexOf("Edge") !== -1 ? "Edge" : "Unknown";
527
+ }
528
+ }
529
+ let s = null;
530
+ function m(t) {
531
+ if (s)
532
+ return console.warn("[Analytics] Already initialized"), s;
533
+ const e = {
534
+ providers: t.providers || [],
535
+ debug: t.debug,
536
+ enabled: t.enabled
537
+ };
538
+ return s = new p(
539
+ e
540
+ ), s.initialize().catch((i) => {
541
+ console.error("[Analytics] Failed to initialize:", i);
542
+ }), s;
543
+ }
544
+ function a() {
545
+ if (!s)
546
+ throw new Error(
547
+ "[Analytics] Not initialized. Call createAnalytics() first."
548
+ );
549
+ return s;
550
+ }
551
+ function v(t, e) {
552
+ return a().track(t, e);
553
+ }
554
+ function y(t, e) {
555
+ a().identify(t, e);
556
+ }
557
+ function w(t) {
558
+ a().pageView(t);
559
+ }
560
+ function z(t) {
561
+ a().pageLeave(t);
562
+ }
563
+ function x() {
564
+ a().reset();
565
+ }
2
566
  export {
3
- s as createAnalytics,
4
- t as createClientAnalytics,
5
- c as getAnalytics,
6
- i as identify,
7
- n as pageLeave,
8
- r as pageView,
9
- l as reset,
10
- y as resetAnalyticsInstance,
11
- g as track
567
+ O as BaseAnalyticsProvider,
568
+ p as BrowserAnalytics,
569
+ P as PostHogClientProvider,
570
+ m as createAnalytics,
571
+ m as createClientAnalytics,
572
+ a as getAnalytics,
573
+ y as identify,
574
+ z as pageLeave,
575
+ w as pageView,
576
+ x as reset,
577
+ v as track
12
578
  };
package/dist/index.d.ts CHANGED
@@ -1,2 +1,2 @@
1
- export * from './src/index'
2
- export {}
1
+ export type { EventCategory, BaseEvent, EventContext, AnalyticsProvider, AnalyticsConfig, } from './core/events/types.js';
2
+ export type { CreateEventDefinition, ExtractEventNames, ExtractEventPropertiesFromCollection, EventCollection, AnyEventName, AnyEventProperties, EventMapFromCollection, } from './core/events/index.js';
package/dist/index.js CHANGED
@@ -1,14 +1 @@
1
- import { B as t, c as s, g as i, i as r, a as n, p as l, r as o, t as c } from "./client-CyvENC-f.js";
2
- import { B as g, P as p } from "./client-MwIAm9fk.js";
3
- export {
4
- g as BaseAnalyticsProvider,
5
- t as BrowserAnalytics,
6
- p as PostHogClientProvider,
7
- s as createClientAnalytics,
8
- i as getAnalytics,
9
- r as identifyClient,
10
- n as pageLeaveClient,
11
- l as pageViewClient,
12
- o as resetClient,
13
- c as trackClient
14
- };
1
+
@@ -0,0 +1,6 @@
1
+ import { B as e } from "../base.provider-AfFL5W_P.js";
2
+ import { P as t } from "../client-RZPcOfAk.js";
3
+ export {
4
+ e as BaseAnalyticsProvider,
5
+ t as PostHogClientProvider
6
+ };
@@ -1,5 +1,3 @@
1
1
  export { BaseAnalyticsProvider } from './base.provider.js';
2
- export { PostHogClientProvider } from './posthog/client.js';
3
2
  export { PostHogServerProvider } from './posthog/server.js';
4
- export type { PostHogConfig } from 'posthog-js';
5
3
  export type { PostHogOptions } from 'posthog-node';
@@ -0,0 +1,6 @@
1
+ import { B as e } from "../base.provider-AfFL5W_P.js";
2
+ import { P as a } from "../server-CMRw9K0d.js";
3
+ export {
4
+ e as BaseAnalyticsProvider,
5
+ a as PostHogServerProvider
6
+ };
@@ -1,8 +1,7 @@
1
1
  var l = Object.defineProperty;
2
2
  var h = (r, s, i) => s in r ? l(r, s, { enumerable: !0, configurable: !0, writable: !0, value: i }) : r[s] = i;
3
3
  var t = (r, s, i) => h(r, typeof s != "symbol" ? s + "" : s, i);
4
- import { B as n } from "./client-MwIAm9fk.js";
5
- import { P as m } from "./client-MwIAm9fk.js";
4
+ import { B as n } from "./base.provider-AfFL5W_P.js";
6
5
  import { PostHog as p } from "posthog-node";
7
6
  class u extends n {
8
7
  constructor(i) {
@@ -81,7 +80,5 @@ class u extends n {
81
80
  }
82
81
  }
83
82
  export {
84
- n as BaseAnalyticsProvider,
85
- m as PostHogClientProvider,
86
- u as PostHogServerProvider
83
+ u as P
87
84
  };
package/dist/server.d.ts CHANGED
@@ -1,2 +1,38 @@
1
- export * from './src/server'
2
- export {}
1
+ import { ServerAnalytics } from './adapters/server/server-analytics.js';
2
+ import { AnalyticsProvider } from './core/events/types.js';
3
+ import { EventMapFromCollection } from './core/events/index.js';
4
+ export interface ServerAnalyticsConfig {
5
+ providers?: AnalyticsProvider[];
6
+ debug?: boolean;
7
+ enabled?: boolean;
8
+ }
9
+ /**
10
+ * Create a server analytics instance
11
+ *
12
+ * @example
13
+ * ```typescript
14
+ * import { createServerAnalytics } from '@stacksee/analytics/server';
15
+ * import { PostHogServerProvider } from '@stacksee/analytics/providers/posthog';
16
+ * import { AppEvents } from './events';
17
+ *
18
+ * const analytics = createServerAnalytics<typeof AppEvents>({
19
+ * providers: [
20
+ * new PostHogServerProvider({
21
+ * apiKey: process.env.POSTHOG_API_KEY,
22
+ * host: process.env.POSTHOG_HOST
23
+ * })
24
+ * ],
25
+ * debug: true,
26
+ * enabled: true
27
+ * });
28
+ *
29
+ * // Now event names and properties are fully typed!
30
+ * await analytics.track('user_signed_up', {
31
+ * userId: 'user-123',
32
+ * email: 'user@example.com',
33
+ * plan: 'pro'
34
+ * }, { userId: 'user-123' });
35
+ * ```
36
+ */
37
+ export declare function createServerAnalytics<TEvents = never>(config: ServerAnalyticsConfig): ServerAnalytics<EventMapFromCollection<TEvents>>;
38
+ export { ServerAnalytics };