@gurulu/web 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/dist/index.d.ts +80 -0
- package/dist/index.js +83 -0
- package/dist/react.d.ts +55 -0
- package/dist/react.js +103 -0
- package/package.json +39 -0
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @gurulu/web — Gurulu Web SDK
|
|
3
|
+
*
|
|
4
|
+
* Programmatic interface for Gurulu analytics.
|
|
5
|
+
* For React/Next.js, use `@gurulu/web/react` instead.
|
|
6
|
+
*/
|
|
7
|
+
export interface GuruluConfig {
|
|
8
|
+
siteId: string;
|
|
9
|
+
token: string;
|
|
10
|
+
endpoint?: string;
|
|
11
|
+
features?: Array<'errors' | 'replay' | 'vitals'>;
|
|
12
|
+
autoTrack?: boolean;
|
|
13
|
+
consent?: 'full' | 'analytics' | 'necessary' | 'none';
|
|
14
|
+
debug?: boolean;
|
|
15
|
+
}
|
|
16
|
+
export interface GuruluInstance {
|
|
17
|
+
track: (eventName: string, properties?: Record<string, unknown>) => void;
|
|
18
|
+
identify: (userId: string, traits?: Record<string, unknown>) => void;
|
|
19
|
+
purchase: (params: {
|
|
20
|
+
value: number;
|
|
21
|
+
currency: string;
|
|
22
|
+
transaction_id?: string;
|
|
23
|
+
items?: unknown[];
|
|
24
|
+
}) => void;
|
|
25
|
+
subscribe: (params: {
|
|
26
|
+
value: number;
|
|
27
|
+
currency: string;
|
|
28
|
+
plan_id?: string;
|
|
29
|
+
interval?: string;
|
|
30
|
+
}) => void;
|
|
31
|
+
login: (params?: {
|
|
32
|
+
method?: string;
|
|
33
|
+
}) => void;
|
|
34
|
+
signup: (params?: {
|
|
35
|
+
method?: string;
|
|
36
|
+
}) => void;
|
|
37
|
+
logout: () => void;
|
|
38
|
+
setConsent: (level: string) => void;
|
|
39
|
+
destroy: () => void;
|
|
40
|
+
}
|
|
41
|
+
declare let _config: GuruluConfig | null;
|
|
42
|
+
/**
|
|
43
|
+
* Initialize the Gurulu tracker by injecting the script tag.
|
|
44
|
+
* Call once at app startup.
|
|
45
|
+
*/
|
|
46
|
+
export declare function init(config: GuruluConfig): void;
|
|
47
|
+
/**
|
|
48
|
+
* Get the global gurulu instance (available after tracker loads).
|
|
49
|
+
*/
|
|
50
|
+
export declare function getInstance(): GuruluInstance | null;
|
|
51
|
+
/**
|
|
52
|
+
* Track a custom event.
|
|
53
|
+
*/
|
|
54
|
+
export declare function track(eventName: string, properties?: Record<string, unknown>): void;
|
|
55
|
+
/**
|
|
56
|
+
* Identify a user with traits.
|
|
57
|
+
*/
|
|
58
|
+
export declare function identify(userId: string, traits?: Record<string, unknown>): void;
|
|
59
|
+
/**
|
|
60
|
+
* Track a purchase event.
|
|
61
|
+
*/
|
|
62
|
+
export declare function purchase(params: {
|
|
63
|
+
value: number;
|
|
64
|
+
currency: string;
|
|
65
|
+
transaction_id?: string;
|
|
66
|
+
}): void;
|
|
67
|
+
/**
|
|
68
|
+
* Track a subscription event.
|
|
69
|
+
*/
|
|
70
|
+
export declare function subscribe(params: {
|
|
71
|
+
value: number;
|
|
72
|
+
currency: string;
|
|
73
|
+
plan_id?: string;
|
|
74
|
+
interval?: string;
|
|
75
|
+
}): void;
|
|
76
|
+
/**
|
|
77
|
+
* Set consent level.
|
|
78
|
+
*/
|
|
79
|
+
export declare function setConsent(level: string): void;
|
|
80
|
+
export { _config as config };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* @gurulu/web — Gurulu Web SDK
|
|
4
|
+
*
|
|
5
|
+
* Programmatic interface for Gurulu analytics.
|
|
6
|
+
* For React/Next.js, use `@gurulu/web/react` instead.
|
|
7
|
+
*/
|
|
8
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
exports.config = void 0;
|
|
10
|
+
exports.init = init;
|
|
11
|
+
exports.getInstance = getInstance;
|
|
12
|
+
exports.track = track;
|
|
13
|
+
exports.identify = identify;
|
|
14
|
+
exports.purchase = purchase;
|
|
15
|
+
exports.subscribe = subscribe;
|
|
16
|
+
exports.setConsent = setConsent;
|
|
17
|
+
let _config = null;
|
|
18
|
+
exports.config = _config;
|
|
19
|
+
let _scriptLoaded = false;
|
|
20
|
+
/**
|
|
21
|
+
* Initialize the Gurulu tracker by injecting the script tag.
|
|
22
|
+
* Call once at app startup.
|
|
23
|
+
*/
|
|
24
|
+
function init(config) {
|
|
25
|
+
if (typeof window === 'undefined')
|
|
26
|
+
return; // SSR guard
|
|
27
|
+
if (_scriptLoaded)
|
|
28
|
+
return; // idempotent
|
|
29
|
+
exports.config = _config = config;
|
|
30
|
+
const endpoint = config.endpoint || 'https://gurulu.io';
|
|
31
|
+
const features = config.features?.join(',') || '';
|
|
32
|
+
const script = document.createElement('script');
|
|
33
|
+
script.src = `${endpoint}/t.js`;
|
|
34
|
+
script.defer = true;
|
|
35
|
+
script.setAttribute('data-site-id', config.siteId);
|
|
36
|
+
script.setAttribute('data-token', config.token);
|
|
37
|
+
if (features)
|
|
38
|
+
script.setAttribute('data-features', features);
|
|
39
|
+
if (config.consent)
|
|
40
|
+
script.setAttribute('data-consent', config.consent);
|
|
41
|
+
if (config.debug)
|
|
42
|
+
script.setAttribute('data-debug', 'true');
|
|
43
|
+
document.head.appendChild(script);
|
|
44
|
+
_scriptLoaded = true;
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Get the global gurulu instance (available after tracker loads).
|
|
48
|
+
*/
|
|
49
|
+
function getInstance() {
|
|
50
|
+
if (typeof window === 'undefined')
|
|
51
|
+
return null;
|
|
52
|
+
return window.gurulu || null;
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Track a custom event.
|
|
56
|
+
*/
|
|
57
|
+
function track(eventName, properties) {
|
|
58
|
+
getInstance()?.track(eventName, properties);
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Identify a user with traits.
|
|
62
|
+
*/
|
|
63
|
+
function identify(userId, traits) {
|
|
64
|
+
getInstance()?.identify(userId, traits);
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Track a purchase event.
|
|
68
|
+
*/
|
|
69
|
+
function purchase(params) {
|
|
70
|
+
getInstance()?.purchase(params);
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Track a subscription event.
|
|
74
|
+
*/
|
|
75
|
+
function subscribe(params) {
|
|
76
|
+
getInstance()?.subscribe(params);
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Set consent level.
|
|
80
|
+
*/
|
|
81
|
+
function setConsent(level) {
|
|
82
|
+
getInstance()?.setConsent(level);
|
|
83
|
+
}
|
package/dist/react.d.ts
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
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
ADDED
|
@@ -0,0 +1,103 @@
|
|
|
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
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@gurulu/web",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Gurulu Web SDK — zero-config analytics, error tracking, and session replay",
|
|
5
|
+
"main": "dist/index.js",
|
|
6
|
+
"types": "dist/index.d.ts",
|
|
7
|
+
"exports": {
|
|
8
|
+
".": {
|
|
9
|
+
"require": "./dist/index.js",
|
|
10
|
+
"types": "./dist/index.d.ts"
|
|
11
|
+
},
|
|
12
|
+
"./react": {
|
|
13
|
+
"require": "./dist/react.js",
|
|
14
|
+
"types": "./dist/react.d.ts"
|
|
15
|
+
}
|
|
16
|
+
},
|
|
17
|
+
"files": ["dist"],
|
|
18
|
+
"scripts": {
|
|
19
|
+
"build": "tsc",
|
|
20
|
+
"dev": "tsc --watch"
|
|
21
|
+
},
|
|
22
|
+
"peerDependencies": {
|
|
23
|
+
"react": ">=17.0.0"
|
|
24
|
+
},
|
|
25
|
+
"peerDependenciesMeta": {
|
|
26
|
+
"react": { "optional": true }
|
|
27
|
+
},
|
|
28
|
+
"devDependencies": {
|
|
29
|
+
"tsup": "^8.0.0",
|
|
30
|
+
"typescript": "^5.3.0",
|
|
31
|
+
"@types/node": "^20.0.0",
|
|
32
|
+
"@types/react": "^18.0.0"
|
|
33
|
+
},
|
|
34
|
+
"engines": {
|
|
35
|
+
"node": ">=16.0.0"
|
|
36
|
+
},
|
|
37
|
+
"license": "MIT",
|
|
38
|
+
"keywords": ["analytics", "tracking", "error-tracking", "session-replay", "gurulu"]
|
|
39
|
+
}
|