@sylphx/sdk 0.3.0 → 0.3.2

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.
@@ -0,0 +1,90 @@
1
+ /**
2
+ * Web Analytics Tracker
3
+ *
4
+ * Lightweight page-view analytics tracker for Sylphx Platform SDK.
5
+ * Automatically tracks page views, bounce rate, and session data.
6
+ *
7
+ * @example
8
+ * ```typescript
9
+ * import { SDK_API_PATH } from "../../constants";
10
+ import { WebAnalyticsTracker } from '@sylphx/platform-sdk/web-analytics'
11
+ *
12
+ * const tracker = new WebAnalyticsTracker()
13
+ * tracker.init({
14
+ * appKey: 'app_prod_xxx',
15
+ * endpoint: 'https://your-app.com',
16
+ * })
17
+ * ```
18
+ */
19
+ interface WebAnalyticsOptions {
20
+ /** App key for authentication */
21
+ appKey: string;
22
+ /** Base endpoint URL (without trailing slash) */
23
+ endpoint: string;
24
+ /** Auto-track page views (default: true) */
25
+ trackPageViews?: boolean;
26
+ /** Track bounce rate (sessions with only 1 page view) (default: true) */
27
+ trackBounce?: boolean;
28
+ /** SPA hash routing mode (tracks hash changes) (default: false) */
29
+ hashMode?: boolean;
30
+ /** Debug logging (default: false) */
31
+ debug?: boolean;
32
+ }
33
+ interface PageViewPayload {
34
+ /** URL path (e.g. /about) */
35
+ path: string;
36
+ /** Document referrer */
37
+ referrer: string;
38
+ /** Navigator user agent */
39
+ userAgent: string;
40
+ /** Screen width in pixels */
41
+ screenWidth: number;
42
+ /** Session ID (UUID stored in sessionStorage) */
43
+ sessionId: string;
44
+ /** Unix timestamp (ms) */
45
+ timestamp: number;
46
+ }
47
+ interface IdentifyPayload {
48
+ /** User ID */
49
+ userId: string;
50
+ /** User traits/properties */
51
+ traits?: Record<string, unknown>;
52
+ /** Session ID */
53
+ sessionId: string;
54
+ }
55
+ declare class WebAnalyticsTracker {
56
+ private options;
57
+ private initialized;
58
+ private lastPath;
59
+ private pageViewCount;
60
+ private cleanupFns;
61
+ /**
62
+ * Initialize the tracker and start auto-tracking page views
63
+ */
64
+ init(options: WebAnalyticsOptions): void;
65
+ /**
66
+ * Manually track a page view
67
+ */
68
+ trackPageView(path?: string): void;
69
+ /**
70
+ * Identify a user
71
+ */
72
+ identify(userId: string, traits?: Record<string, unknown>): void;
73
+ /**
74
+ * Destroy the tracker and remove event listeners
75
+ */
76
+ destroy(): void;
77
+ private _send;
78
+ private _hookHistoryApi;
79
+ private _hookNextRouter;
80
+ }
81
+ /**
82
+ * Get or create the global WebAnalyticsTracker singleton
83
+ */
84
+ declare function getWebAnalyticsTracker(): WebAnalyticsTracker;
85
+ /**
86
+ * Initialize global web analytics tracker
87
+ */
88
+ declare function initWebAnalytics(options: WebAnalyticsOptions): void;
89
+
90
+ export { type IdentifyPayload, type PageViewPayload, type WebAnalyticsOptions, WebAnalyticsTracker, getWebAnalyticsTracker, initWebAnalytics };
@@ -0,0 +1,90 @@
1
+ /**
2
+ * Web Analytics Tracker
3
+ *
4
+ * Lightweight page-view analytics tracker for Sylphx Platform SDK.
5
+ * Automatically tracks page views, bounce rate, and session data.
6
+ *
7
+ * @example
8
+ * ```typescript
9
+ * import { SDK_API_PATH } from "../../constants";
10
+ import { WebAnalyticsTracker } from '@sylphx/platform-sdk/web-analytics'
11
+ *
12
+ * const tracker = new WebAnalyticsTracker()
13
+ * tracker.init({
14
+ * appKey: 'app_prod_xxx',
15
+ * endpoint: 'https://your-app.com',
16
+ * })
17
+ * ```
18
+ */
19
+ interface WebAnalyticsOptions {
20
+ /** App key for authentication */
21
+ appKey: string;
22
+ /** Base endpoint URL (without trailing slash) */
23
+ endpoint: string;
24
+ /** Auto-track page views (default: true) */
25
+ trackPageViews?: boolean;
26
+ /** Track bounce rate (sessions with only 1 page view) (default: true) */
27
+ trackBounce?: boolean;
28
+ /** SPA hash routing mode (tracks hash changes) (default: false) */
29
+ hashMode?: boolean;
30
+ /** Debug logging (default: false) */
31
+ debug?: boolean;
32
+ }
33
+ interface PageViewPayload {
34
+ /** URL path (e.g. /about) */
35
+ path: string;
36
+ /** Document referrer */
37
+ referrer: string;
38
+ /** Navigator user agent */
39
+ userAgent: string;
40
+ /** Screen width in pixels */
41
+ screenWidth: number;
42
+ /** Session ID (UUID stored in sessionStorage) */
43
+ sessionId: string;
44
+ /** Unix timestamp (ms) */
45
+ timestamp: number;
46
+ }
47
+ interface IdentifyPayload {
48
+ /** User ID */
49
+ userId: string;
50
+ /** User traits/properties */
51
+ traits?: Record<string, unknown>;
52
+ /** Session ID */
53
+ sessionId: string;
54
+ }
55
+ declare class WebAnalyticsTracker {
56
+ private options;
57
+ private initialized;
58
+ private lastPath;
59
+ private pageViewCount;
60
+ private cleanupFns;
61
+ /**
62
+ * Initialize the tracker and start auto-tracking page views
63
+ */
64
+ init(options: WebAnalyticsOptions): void;
65
+ /**
66
+ * Manually track a page view
67
+ */
68
+ trackPageView(path?: string): void;
69
+ /**
70
+ * Identify a user
71
+ */
72
+ identify(userId: string, traits?: Record<string, unknown>): void;
73
+ /**
74
+ * Destroy the tracker and remove event listeners
75
+ */
76
+ destroy(): void;
77
+ private _send;
78
+ private _hookHistoryApi;
79
+ private _hookNextRouter;
80
+ }
81
+ /**
82
+ * Get or create the global WebAnalyticsTracker singleton
83
+ */
84
+ declare function getWebAnalyticsTracker(): WebAnalyticsTracker;
85
+ /**
86
+ * Initialize global web analytics tracker
87
+ */
88
+ declare function initWebAnalytics(options: WebAnalyticsOptions): void;
89
+
90
+ export { type IdentifyPayload, type PageViewPayload, type WebAnalyticsOptions, WebAnalyticsTracker, getWebAnalyticsTracker, initWebAnalytics };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sylphx/sdk",
3
- "version": "0.3.0",
3
+ "version": "0.3.2",
4
4
  "description": "Sylphx SDK - State-of-the-art platform SDK with pure functions",
5
5
  "type": "module",
6
6
  "sideEffects": false,
@@ -45,8 +45,6 @@
45
45
  "test": "bun test",
46
46
  "test:watch": "bun test --watch",
47
47
  "test:coverage": "bun test --coverage",
48
- "prepare": "tsup --no-dts",
49
- "prepublishOnly": "tsup",
50
48
  "generate:types": "openapi-typescript https://sylphx.com/api/openapi.json -o src/generated/api.d.ts",
51
49
  "generate:types:local": "openapi-typescript http://localhost:3002/api/openapi.json -o src/generated/api.d.ts",
52
50
  "build:docker": "tsup --no-dts"