@gurulu/web 0.1.0 → 1.0.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/react.d.ts DELETED
@@ -1,55 +0,0 @@
1
- /**
2
- * @gurulu/web/react — React/Next.js component for Gurulu analytics.
3
- *
4
- * Usage:
5
- * import { GuruluProvider } from '@gurulu/web/react';
6
- *
7
- * // In your root layout:
8
- * <GuruluProvider siteId="xxx" token="yyy" features={['errors', 'replay']} />
9
- */
10
- import { track, identify, getInstance } from './index';
11
- import type { GuruluConfig, GuruluInstance } from './index';
12
- export type { GuruluConfig, GuruluInstance };
13
- export { track, identify, getInstance };
14
- export interface GuruluProviderProps {
15
- siteId: string;
16
- token: string;
17
- endpoint?: string;
18
- features?: Array<'errors' | 'replay' | 'vitals'>;
19
- autoTrack?: boolean;
20
- consent?: 'full' | 'analytics' | 'necessary' | 'none';
21
- debug?: boolean;
22
- /** Auto-identify the current user (pass userId + email after auth) */
23
- userId?: string;
24
- userEmail?: string;
25
- }
26
- /**
27
- * Drop-in React component that initializes Gurulu tracking.
28
- * Renders nothing — just injects the tracker script and optionally identifies the user.
29
- *
30
- * ```tsx
31
- * // app/layout.tsx
32
- * import { GuruluProvider } from '@gurulu/web/react';
33
- *
34
- * export default function Layout({ children }) {
35
- * return (
36
- * <html>
37
- * <body>
38
- * {children}
39
- * <GuruluProvider
40
- * siteId="your-site-id"
41
- * token="your-token"
42
- * features={['errors', 'replay']}
43
- * />
44
- * </body>
45
- * </html>
46
- * );
47
- * }
48
- * ```
49
- */
50
- export declare function GuruluProvider({ siteId, token, endpoint, features, autoTrack, consent, debug, userId, userEmail, }: GuruluProviderProps): null;
51
- /**
52
- * Hook to get the Gurulu tracker instance.
53
- * Returns null until the tracker script has loaded.
54
- */
55
- export declare function useGurulu(): GuruluInstance | null;
package/dist/react.js DELETED
@@ -1,103 +0,0 @@
1
- "use strict";
2
- /**
3
- * @gurulu/web/react — React/Next.js component for Gurulu analytics.
4
- *
5
- * Usage:
6
- * import { GuruluProvider } from '@gurulu/web/react';
7
- *
8
- * // In your root layout:
9
- * <GuruluProvider siteId="xxx" token="yyy" features={['errors', 'replay']} />
10
- */
11
- 'use client';
12
- /**
13
- * @gurulu/web/react — React/Next.js component for Gurulu analytics.
14
- *
15
- * Usage:
16
- * import { GuruluProvider } from '@gurulu/web/react';
17
- *
18
- * // In your root layout:
19
- * <GuruluProvider siteId="xxx" token="yyy" features={['errors', 'replay']} />
20
- */
21
- Object.defineProperty(exports, "__esModule", { value: true });
22
- exports.getInstance = exports.identify = exports.track = void 0;
23
- exports.GuruluProvider = GuruluProvider;
24
- exports.useGurulu = useGurulu;
25
- const react_1 = require("react");
26
- const index_1 = require("./index");
27
- Object.defineProperty(exports, "track", { enumerable: true, get: function () { return index_1.track; } });
28
- Object.defineProperty(exports, "identify", { enumerable: true, get: function () { return index_1.identify; } });
29
- Object.defineProperty(exports, "getInstance", { enumerable: true, get: function () { return index_1.getInstance; } });
30
- /**
31
- * Drop-in React component that initializes Gurulu tracking.
32
- * Renders nothing — just injects the tracker script and optionally identifies the user.
33
- *
34
- * ```tsx
35
- * // app/layout.tsx
36
- * import { GuruluProvider } from '@gurulu/web/react';
37
- *
38
- * export default function Layout({ children }) {
39
- * return (
40
- * <html>
41
- * <body>
42
- * {children}
43
- * <GuruluProvider
44
- * siteId="your-site-id"
45
- * token="your-token"
46
- * features={['errors', 'replay']}
47
- * />
48
- * </body>
49
- * </html>
50
- * );
51
- * }
52
- * ```
53
- */
54
- function GuruluProvider({ siteId, token, endpoint, features, autoTrack = true, consent, debug, userId, userEmail, }) {
55
- const initialized = (0, react_1.useRef)(false);
56
- const identified = (0, react_1.useRef)(false);
57
- (0, react_1.useEffect)(() => {
58
- if (initialized.current)
59
- return;
60
- initialized.current = true;
61
- (0, index_1.init)({
62
- siteId,
63
- token,
64
- endpoint,
65
- features,
66
- autoTrack,
67
- consent,
68
- debug,
69
- });
70
- }, [siteId, token, endpoint, features, autoTrack, consent, debug]);
71
- // Auto-identify when userId is provided
72
- (0, react_1.useEffect)(() => {
73
- if (!userId || identified.current)
74
- return;
75
- const tryIdentify = () => {
76
- const g = (0, index_1.getInstance)();
77
- if (g) {
78
- g.identify(userId, userEmail ? { email: userEmail } : undefined);
79
- identified.current = true;
80
- return true;
81
- }
82
- return false;
83
- };
84
- if (tryIdentify())
85
- return;
86
- // Poll until tracker loads
87
- let attempts = 0;
88
- const interval = setInterval(() => {
89
- attempts++;
90
- if (tryIdentify() || attempts >= 20)
91
- clearInterval(interval);
92
- }, 100);
93
- return () => clearInterval(interval);
94
- }, [userId, userEmail]);
95
- return null;
96
- }
97
- /**
98
- * Hook to get the Gurulu tracker instance.
99
- * Returns null until the tracker script has loaded.
100
- */
101
- function useGurulu() {
102
- return (0, index_1.getInstance)();
103
- }