@databuddy/sdk 1.4.2 → 2.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/README.md +3 -2
- package/dist/core/index.d.mts +55 -0
- package/dist/core/index.d.ts +55 -0
- package/dist/core/index.mjs +59 -0
- package/dist/react/index.d.mts +1 -0
- package/dist/react/index.d.ts +1 -0
- package/dist/react/index.mjs +4 -0
- package/dist/shared/@databuddy/sdk.B72MFYNj.mjs +44 -0
- package/dist/{types.d.ts → shared/@databuddy/sdk.ClgMzRh8.d.mts} +53 -13
- package/dist/shared/@databuddy/sdk.ClgMzRh8.d.ts +338 -0
- package/dist/shared/@databuddy/sdk.CtTNAIIE.mjs +25 -0
- package/dist/vue/index.d.mts +182 -0
- package/dist/vue/index.d.ts +182 -0
- package/dist/vue/index.mjs +40 -0
- package/package.json +58 -34
- package/dist/Databuddy.d.ts +0 -8
- package/dist/Databuddy.js +0 -50
- package/dist/index.d.ts +0 -3
- package/dist/index.js +0 -3
- package/dist/tracker.d.ts +0 -43
- package/dist/tracker.js +0 -83
- package/dist/types.js +0 -1
package/README.md
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
[](https://www.npmjs.com/package/@databuddy/sdk)
|
|
4
4
|
[](./LICENSE)
|
|
5
|
-
[](https://
|
|
5
|
+
[](https://www.databuddy.cc/docs)
|
|
6
6
|
|
|
7
7
|
> **The easiest, privacy-first way to add analytics to your web app.**
|
|
8
8
|
|
|
@@ -16,6 +16,7 @@
|
|
|
16
16
|
- 🧩 **Drop-in React/Next.js component: `<Databuddy />`**
|
|
17
17
|
- 🛡️ **Privacy-first: anonymized by default, sampling, batching, and more**
|
|
18
18
|
- 🛠️ **Type-safe config and autocompletion**
|
|
19
|
+
- 📋 **Observability: logging, error tracking, and distributed tracing**
|
|
19
20
|
|
|
20
21
|
---
|
|
21
22
|
|
|
@@ -120,7 +121,7 @@ A: In your [Databuddy dashboard](https://app.databuddy.cc).
|
|
|
120
121
|
|
|
121
122
|
## 📚 Documentation & Support
|
|
122
123
|
|
|
123
|
-
- [Databuddy Docs](https://
|
|
124
|
+
- [Databuddy Docs](https://www.databuddy.cc/docs)
|
|
124
125
|
- [Dashboard](https://app.databuddy.cc)
|
|
125
126
|
- [Contact Support](https://www.databuddy.cc/contact)
|
|
126
127
|
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { D as DatabuddyConfig, a as DatabuddyTracker, T as TrackFunction, b as Databuddy$1 } from '../shared/@databuddy/sdk.ClgMzRh8.mjs';
|
|
2
|
+
export { B as BaseEventProperties, e as DataAttributes, d as EventName, E as EventProperties, c as EventTypeMap, P as PropertiesForEvent, S as ScreenViewFunction, f as SetGlobalPropertiesFunction } from '../shared/@databuddy/sdk.ClgMzRh8.mjs';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Auto-detect Databuddy client ID from environment variables
|
|
6
|
+
* Supports Next.js, Nuxt, and other frameworks
|
|
7
|
+
*/
|
|
8
|
+
declare function detectClientId(providedClientId?: string): string | undefined;
|
|
9
|
+
|
|
10
|
+
declare function isScriptInjected(): boolean;
|
|
11
|
+
declare function createScript({ scriptUrl, sdkVersion, ...props }: DatabuddyConfig): HTMLScriptElement;
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Databuddy SDK Client-side Tracker
|
|
15
|
+
* Provides type-safe tracking functions
|
|
16
|
+
*/
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Check if the Databuddy tracker is available
|
|
20
|
+
*/
|
|
21
|
+
declare function isTrackerAvailable(): boolean;
|
|
22
|
+
/**
|
|
23
|
+
* Get the Databuddy tracker instance
|
|
24
|
+
*/
|
|
25
|
+
declare function getTracker(): DatabuddyTracker | null;
|
|
26
|
+
/**
|
|
27
|
+
* Type-safe track function
|
|
28
|
+
*/
|
|
29
|
+
declare const track: TrackFunction;
|
|
30
|
+
/**
|
|
31
|
+
* Clear the current session
|
|
32
|
+
*/
|
|
33
|
+
declare function clear(): void;
|
|
34
|
+
/**
|
|
35
|
+
* Flush any queued events
|
|
36
|
+
*/
|
|
37
|
+
declare function flush(): void;
|
|
38
|
+
/**
|
|
39
|
+
* Track an error event
|
|
40
|
+
*/
|
|
41
|
+
declare function trackError(message: string, properties?: {
|
|
42
|
+
filename?: string;
|
|
43
|
+
lineno?: number;
|
|
44
|
+
colno?: number;
|
|
45
|
+
stack?: string;
|
|
46
|
+
error_type?: string;
|
|
47
|
+
[key: string]: any;
|
|
48
|
+
}): Promise<void>;
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* @deprecated Use Databuddy from `@databuddy/sdk/react` instead
|
|
52
|
+
*/
|
|
53
|
+
declare const Databuddy: typeof Databuddy$1;
|
|
54
|
+
|
|
55
|
+
export { Databuddy, DatabuddyConfig, DatabuddyTracker, TrackFunction, clear, createScript, detectClientId, flush, getTracker, isScriptInjected, isTrackerAvailable, track, trackError };
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { D as DatabuddyConfig, a as DatabuddyTracker, T as TrackFunction, b as Databuddy$1 } from '../shared/@databuddy/sdk.ClgMzRh8.js';
|
|
2
|
+
export { B as BaseEventProperties, e as DataAttributes, d as EventName, E as EventProperties, c as EventTypeMap, P as PropertiesForEvent, S as ScreenViewFunction, f as SetGlobalPropertiesFunction } from '../shared/@databuddy/sdk.ClgMzRh8.js';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Auto-detect Databuddy client ID from environment variables
|
|
6
|
+
* Supports Next.js, Nuxt, and other frameworks
|
|
7
|
+
*/
|
|
8
|
+
declare function detectClientId(providedClientId?: string): string | undefined;
|
|
9
|
+
|
|
10
|
+
declare function isScriptInjected(): boolean;
|
|
11
|
+
declare function createScript({ scriptUrl, sdkVersion, ...props }: DatabuddyConfig): HTMLScriptElement;
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Databuddy SDK Client-side Tracker
|
|
15
|
+
* Provides type-safe tracking functions
|
|
16
|
+
*/
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Check if the Databuddy tracker is available
|
|
20
|
+
*/
|
|
21
|
+
declare function isTrackerAvailable(): boolean;
|
|
22
|
+
/**
|
|
23
|
+
* Get the Databuddy tracker instance
|
|
24
|
+
*/
|
|
25
|
+
declare function getTracker(): DatabuddyTracker | null;
|
|
26
|
+
/**
|
|
27
|
+
* Type-safe track function
|
|
28
|
+
*/
|
|
29
|
+
declare const track: TrackFunction;
|
|
30
|
+
/**
|
|
31
|
+
* Clear the current session
|
|
32
|
+
*/
|
|
33
|
+
declare function clear(): void;
|
|
34
|
+
/**
|
|
35
|
+
* Flush any queued events
|
|
36
|
+
*/
|
|
37
|
+
declare function flush(): void;
|
|
38
|
+
/**
|
|
39
|
+
* Track an error event
|
|
40
|
+
*/
|
|
41
|
+
declare function trackError(message: string, properties?: {
|
|
42
|
+
filename?: string;
|
|
43
|
+
lineno?: number;
|
|
44
|
+
colno?: number;
|
|
45
|
+
stack?: string;
|
|
46
|
+
error_type?: string;
|
|
47
|
+
[key: string]: any;
|
|
48
|
+
}): Promise<void>;
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* @deprecated Use Databuddy from `@databuddy/sdk/react` instead
|
|
52
|
+
*/
|
|
53
|
+
declare const Databuddy: typeof Databuddy$1;
|
|
54
|
+
|
|
55
|
+
export { Databuddy, DatabuddyConfig, DatabuddyTracker, TrackFunction, clear, createScript, detectClientId, flush, getTracker, isScriptInjected, isTrackerAvailable, track, trackError };
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { D as Databuddy$1 } from '../shared/@databuddy/sdk.B72MFYNj.mjs';
|
|
2
|
+
export { d as detectClientId } from '../shared/@databuddy/sdk.B72MFYNj.mjs';
|
|
3
|
+
export { c as createScript, i as isScriptInjected } from '../shared/@databuddy/sdk.CtTNAIIE.mjs';
|
|
4
|
+
|
|
5
|
+
function isTrackerAvailable() {
|
|
6
|
+
return typeof window !== "undefined" && (!!window.databuddy || !!window.db);
|
|
7
|
+
}
|
|
8
|
+
function getTracker() {
|
|
9
|
+
if (typeof window === "undefined") {
|
|
10
|
+
return null;
|
|
11
|
+
}
|
|
12
|
+
return window.databuddy || null;
|
|
13
|
+
}
|
|
14
|
+
const track = async (eventName, properties) => {
|
|
15
|
+
if (typeof window === "undefined") {
|
|
16
|
+
return;
|
|
17
|
+
}
|
|
18
|
+
const tracker = window.db?.track || window.databuddy?.track;
|
|
19
|
+
if (!tracker) {
|
|
20
|
+
return;
|
|
21
|
+
}
|
|
22
|
+
try {
|
|
23
|
+
await tracker(eventName, properties);
|
|
24
|
+
} catch (_error) {
|
|
25
|
+
}
|
|
26
|
+
};
|
|
27
|
+
function clear() {
|
|
28
|
+
if (typeof window === "undefined") {
|
|
29
|
+
return;
|
|
30
|
+
}
|
|
31
|
+
const tracker = window.db?.clear || window.databuddy?.clear;
|
|
32
|
+
if (!tracker) {
|
|
33
|
+
return;
|
|
34
|
+
}
|
|
35
|
+
try {
|
|
36
|
+
tracker();
|
|
37
|
+
} catch (_error) {
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
function flush() {
|
|
41
|
+
if (typeof window === "undefined") {
|
|
42
|
+
return;
|
|
43
|
+
}
|
|
44
|
+
const tracker = window.db?.flush || window.databuddy?.flush;
|
|
45
|
+
if (!tracker) {
|
|
46
|
+
return;
|
|
47
|
+
}
|
|
48
|
+
try {
|
|
49
|
+
tracker();
|
|
50
|
+
} catch (_error) {
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
function trackError(message, properties) {
|
|
54
|
+
return track("error", { message, ...properties });
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
const Databuddy = Databuddy$1;
|
|
58
|
+
|
|
59
|
+
export { Databuddy, clear, flush, getTracker, isTrackerAvailable, track, trackError };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { b as Databuddy } from '../shared/@databuddy/sdk.ClgMzRh8.mjs';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { b as Databuddy } from '../shared/@databuddy/sdk.ClgMzRh8.js';
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { i as isScriptInjected, c as createScript } from './sdk.CtTNAIIE.mjs';
|
|
2
|
+
|
|
3
|
+
function detectClientId(providedClientId) {
|
|
4
|
+
if (providedClientId) {
|
|
5
|
+
return providedClientId;
|
|
6
|
+
}
|
|
7
|
+
if (typeof process !== "undefined" && process.env) {
|
|
8
|
+
return process.env.NEXT_PUBLIC_DATABUDDY_CLIENT_ID || process.env.NUXT_PUBLIC_DATABUDDY_CLIENT_ID || process.env.VITE_DATABUDDY_CLIENT_ID || process.env.REACT_APP_DATABUDDY_CLIENT_ID;
|
|
9
|
+
}
|
|
10
|
+
if (typeof window !== "undefined") {
|
|
11
|
+
const nextEnv = window.__NEXT_DATA__?.env?.NEXT_PUBLIC_DATABUDDY_CLIENT_ID;
|
|
12
|
+
if (nextEnv) {
|
|
13
|
+
return nextEnv;
|
|
14
|
+
}
|
|
15
|
+
const nuxtEnv = window.__NUXT__?.env?.NUXT_PUBLIC_DATABUDDY_CLIENT_ID;
|
|
16
|
+
if (nuxtEnv) {
|
|
17
|
+
return nuxtEnv;
|
|
18
|
+
}
|
|
19
|
+
const viteEnv = window.__VITE_ENV__?.VITE_DATABUDDY_CLIENT_ID;
|
|
20
|
+
if (viteEnv) {
|
|
21
|
+
return viteEnv;
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
return;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
function Databuddy(props) {
|
|
28
|
+
const clientId = detectClientId(props.clientId);
|
|
29
|
+
if (!clientId) {
|
|
30
|
+
if (typeof window !== "undefined" && !props.disabled) {
|
|
31
|
+
console.warn(
|
|
32
|
+
"Databuddy: No client ID found. Please provide clientId prop or set NEXT_PUBLIC_DATABUDDY_CLIENT_ID environment variable."
|
|
33
|
+
);
|
|
34
|
+
}
|
|
35
|
+
return null;
|
|
36
|
+
}
|
|
37
|
+
if (typeof window !== "undefined" && !props.disabled && !isScriptInjected()) {
|
|
38
|
+
const script = createScript({ ...props, clientId });
|
|
39
|
+
document.head.appendChild(script);
|
|
40
|
+
}
|
|
41
|
+
return null;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
export { Databuddy as D, detectClientId as d };
|
|
@@ -2,13 +2,14 @@
|
|
|
2
2
|
* Configuration options for the Databuddy SDK and <Databuddy /> component.
|
|
3
3
|
* All options are passed as data attributes to the injected script.
|
|
4
4
|
*/
|
|
5
|
-
|
|
5
|
+
interface DatabuddyConfig {
|
|
6
6
|
/**
|
|
7
|
-
* Your Databuddy project client ID
|
|
7
|
+
* Your Databuddy project client ID.
|
|
8
|
+
* If not provided, will automatically detect from NEXT_PUBLIC_DATABUDDY_CLIENT_ID environment variable.
|
|
8
9
|
* Get this from your Databuddy dashboard.
|
|
9
10
|
* Example: '3ed1fce1-5a56-4cbc-a917-66864f6d18e3'
|
|
10
11
|
*/
|
|
11
|
-
clientId
|
|
12
|
+
clientId?: string;
|
|
12
13
|
/**
|
|
13
14
|
* (Advanced) Your Databuddy client secret for server-side operations.
|
|
14
15
|
* Not required for browser usage.
|
|
@@ -95,6 +96,34 @@ export interface DatabuddyConfig {
|
|
|
95
96
|
* Track JavaScript errors (default: false).
|
|
96
97
|
*/
|
|
97
98
|
trackErrors?: boolean;
|
|
99
|
+
/**
|
|
100
|
+
* Enable observability features (logging, error tracking, tracing) (default: false).
|
|
101
|
+
*/
|
|
102
|
+
enableObservability?: boolean;
|
|
103
|
+
/**
|
|
104
|
+
* Service name for observability events.
|
|
105
|
+
*/
|
|
106
|
+
observabilityService?: string;
|
|
107
|
+
/**
|
|
108
|
+
* Environment for observability events.
|
|
109
|
+
*/
|
|
110
|
+
observabilityEnvironment?: string;
|
|
111
|
+
/**
|
|
112
|
+
* Service version for observability events.
|
|
113
|
+
*/
|
|
114
|
+
observabilityVersion?: string;
|
|
115
|
+
/**
|
|
116
|
+
* Enable structured logging (default: false).
|
|
117
|
+
*/
|
|
118
|
+
enableLogging?: boolean;
|
|
119
|
+
/**
|
|
120
|
+
* Enable distributed tracing (default: false).
|
|
121
|
+
*/
|
|
122
|
+
enableTracing?: boolean;
|
|
123
|
+
/**
|
|
124
|
+
* Enable error tracking (default: false).
|
|
125
|
+
*/
|
|
126
|
+
enableErrorTracking?: boolean;
|
|
98
127
|
/**
|
|
99
128
|
* Sampling rate for events (0.0 to 1.0, default: 1.0).
|
|
100
129
|
* Example: 0.5 = 50% of events sent.
|
|
@@ -134,7 +163,7 @@ export interface DatabuddyConfig {
|
|
|
134
163
|
/**
|
|
135
164
|
* Base event properties that can be attached to any event
|
|
136
165
|
*/
|
|
137
|
-
|
|
166
|
+
interface BaseEventProperties {
|
|
138
167
|
/** Page URL */
|
|
139
168
|
__path?: string;
|
|
140
169
|
/** Page title */
|
|
@@ -167,14 +196,14 @@ export interface BaseEventProperties {
|
|
|
167
196
|
/**
|
|
168
197
|
* Custom event properties that can be attached to any event
|
|
169
198
|
*/
|
|
170
|
-
|
|
199
|
+
interface EventProperties extends BaseEventProperties {
|
|
171
200
|
/** Custom properties for the event */
|
|
172
201
|
[key: string]: string | number | boolean | null | undefined;
|
|
173
202
|
}
|
|
174
203
|
/**
|
|
175
204
|
* Pre-defined event types with their specific properties
|
|
176
205
|
*/
|
|
177
|
-
|
|
206
|
+
interface EventTypeMap {
|
|
178
207
|
screen_view: {
|
|
179
208
|
time_on_page?: number;
|
|
180
209
|
scroll_depth?: number;
|
|
@@ -231,15 +260,15 @@ export interface EventTypeMap {
|
|
|
231
260
|
/**
|
|
232
261
|
* Available event names
|
|
233
262
|
*/
|
|
234
|
-
|
|
263
|
+
type EventName = keyof EventTypeMap;
|
|
235
264
|
/**
|
|
236
265
|
* Properties for a specific event type
|
|
237
266
|
*/
|
|
238
|
-
|
|
267
|
+
type PropertiesForEvent<T extends EventName> = T extends keyof EventTypeMap ? EventTypeMap[T] & EventProperties : EventProperties;
|
|
239
268
|
/**
|
|
240
269
|
* Databuddy tracker instance interface
|
|
241
270
|
*/
|
|
242
|
-
|
|
271
|
+
interface DatabuddyTracker {
|
|
243
272
|
/**
|
|
244
273
|
* Track a custom event
|
|
245
274
|
*/
|
|
@@ -284,7 +313,7 @@ declare global {
|
|
|
284
313
|
/**
|
|
285
314
|
* Helper type for HTML data attributes for automatic tracking
|
|
286
315
|
*/
|
|
287
|
-
|
|
316
|
+
interface DataAttributes {
|
|
288
317
|
/** Event name to track when element is clicked */
|
|
289
318
|
'data-track': string;
|
|
290
319
|
/** Additional data attributes (converted to camelCase) */
|
|
@@ -293,6 +322,17 @@ export interface DataAttributes {
|
|
|
293
322
|
/**
|
|
294
323
|
* Utility types for creating typed event tracking functions
|
|
295
324
|
*/
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
325
|
+
type TrackFunction = <T extends EventName>(eventName: T, properties?: PropertiesForEvent<T>) => Promise<void>;
|
|
326
|
+
type ScreenViewFunction = (path?: string, properties?: EventProperties) => void;
|
|
327
|
+
type SetGlobalPropertiesFunction = (properties: EventProperties) => void;
|
|
328
|
+
|
|
329
|
+
/**
|
|
330
|
+
* <Databuddy /> component for Next.js/React apps
|
|
331
|
+
* Injects the databuddy.js script with all config as data attributes
|
|
332
|
+
* Usage: <Databuddy clientId="..." trackScreenViews trackPerformance ... />
|
|
333
|
+
* Or simply: <Databuddy /> (auto-detects clientId from environment variables)
|
|
334
|
+
*/
|
|
335
|
+
declare function Databuddy(props: DatabuddyConfig): null;
|
|
336
|
+
|
|
337
|
+
export { Databuddy as b };
|
|
338
|
+
export type { BaseEventProperties as B, DatabuddyConfig as D, EventProperties as E, PropertiesForEvent as P, ScreenViewFunction as S, TrackFunction as T, DatabuddyTracker as a, EventTypeMap as c, EventName as d, DataAttributes as e, SetGlobalPropertiesFunction as f };
|