@databuddy/sdk 1.4.1 → 2.0.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/core/index.d.mts +49 -0
- package/dist/core/index.d.ts +49 -0
- package/dist/core/index.mjs +58 -0
- package/dist/react/index.d.mts +1 -0
- package/dist/react/index.d.ts +1 -0
- package/dist/react/index.mjs +13 -0
- package/dist/shared/@databuddy/sdk.CtTNAIIE.mjs +25 -0
- package/dist/{types.d.ts → shared/@databuddy/sdk.Sqo9i0iN.d.mts} +21 -11
- package/dist/shared/@databuddy/sdk.Sqo9i0iN.d.ts +308 -0
- package/dist/vue/index.d.mts +148 -0
- package/dist/vue/index.d.ts +148 -0
- package/dist/vue/index.mjs +40 -0
- package/package.json +44 -13
- package/dist/Databuddy.d.ts +0 -8
- package/dist/Databuddy.js +0 -47
- package/dist/DatabuddyProvider.d.ts +0 -8
- package/dist/DatabuddyProvider.js +0 -31
- 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 -86
- package/dist/types.js +0 -1
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { D as DatabuddyConfig, a as DatabuddyTracker, T as TrackFunction, b as Databuddy$1 } from '../shared/@databuddy/sdk.Sqo9i0iN.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.Sqo9i0iN.mjs';
|
|
3
|
+
|
|
4
|
+
declare function isScriptInjected(): boolean;
|
|
5
|
+
declare function createScript({ scriptUrl, sdkVersion, ...props }: DatabuddyConfig): HTMLScriptElement;
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Databuddy SDK Client-side Tracker
|
|
9
|
+
* Provides type-safe tracking functions
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Check if the Databuddy tracker is available
|
|
14
|
+
*/
|
|
15
|
+
declare function isTrackerAvailable(): boolean;
|
|
16
|
+
/**
|
|
17
|
+
* Get the Databuddy tracker instance
|
|
18
|
+
*/
|
|
19
|
+
declare function getTracker(): DatabuddyTracker | null;
|
|
20
|
+
/**
|
|
21
|
+
* Type-safe track function
|
|
22
|
+
*/
|
|
23
|
+
declare const track: TrackFunction;
|
|
24
|
+
/**
|
|
25
|
+
* Clear the current session
|
|
26
|
+
*/
|
|
27
|
+
declare function clear(): void;
|
|
28
|
+
/**
|
|
29
|
+
* Flush any queued events
|
|
30
|
+
*/
|
|
31
|
+
declare function flush(): void;
|
|
32
|
+
/**
|
|
33
|
+
* Track an error event
|
|
34
|
+
*/
|
|
35
|
+
declare function trackError(message: string, properties?: {
|
|
36
|
+
filename?: string;
|
|
37
|
+
lineno?: number;
|
|
38
|
+
colno?: number;
|
|
39
|
+
stack?: string;
|
|
40
|
+
error_type?: string;
|
|
41
|
+
[key: string]: any;
|
|
42
|
+
}): Promise<void>;
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* @deprecated Use Databuddy from `@databuddy/sdk/react` instead
|
|
46
|
+
*/
|
|
47
|
+
declare const Databuddy: typeof Databuddy$1;
|
|
48
|
+
|
|
49
|
+
export { Databuddy, DatabuddyConfig, DatabuddyTracker, TrackFunction, clear, createScript, flush, getTracker, isScriptInjected, isTrackerAvailable, track, trackError };
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { D as DatabuddyConfig, a as DatabuddyTracker, T as TrackFunction, b as Databuddy$1 } from '../shared/@databuddy/sdk.Sqo9i0iN.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.Sqo9i0iN.js';
|
|
3
|
+
|
|
4
|
+
declare function isScriptInjected(): boolean;
|
|
5
|
+
declare function createScript({ scriptUrl, sdkVersion, ...props }: DatabuddyConfig): HTMLScriptElement;
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Databuddy SDK Client-side Tracker
|
|
9
|
+
* Provides type-safe tracking functions
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Check if the Databuddy tracker is available
|
|
14
|
+
*/
|
|
15
|
+
declare function isTrackerAvailable(): boolean;
|
|
16
|
+
/**
|
|
17
|
+
* Get the Databuddy tracker instance
|
|
18
|
+
*/
|
|
19
|
+
declare function getTracker(): DatabuddyTracker | null;
|
|
20
|
+
/**
|
|
21
|
+
* Type-safe track function
|
|
22
|
+
*/
|
|
23
|
+
declare const track: TrackFunction;
|
|
24
|
+
/**
|
|
25
|
+
* Clear the current session
|
|
26
|
+
*/
|
|
27
|
+
declare function clear(): void;
|
|
28
|
+
/**
|
|
29
|
+
* Flush any queued events
|
|
30
|
+
*/
|
|
31
|
+
declare function flush(): void;
|
|
32
|
+
/**
|
|
33
|
+
* Track an error event
|
|
34
|
+
*/
|
|
35
|
+
declare function trackError(message: string, properties?: {
|
|
36
|
+
filename?: string;
|
|
37
|
+
lineno?: number;
|
|
38
|
+
colno?: number;
|
|
39
|
+
stack?: string;
|
|
40
|
+
error_type?: string;
|
|
41
|
+
[key: string]: any;
|
|
42
|
+
}): Promise<void>;
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* @deprecated Use Databuddy from `@databuddy/sdk/react` instead
|
|
46
|
+
*/
|
|
47
|
+
declare const Databuddy: typeof Databuddy$1;
|
|
48
|
+
|
|
49
|
+
export { Databuddy, DatabuddyConfig, DatabuddyTracker, TrackFunction, clear, createScript, flush, getTracker, isScriptInjected, isTrackerAvailable, track, trackError };
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
export { c as createScript, i as isScriptInjected } from '../shared/@databuddy/sdk.CtTNAIIE.mjs';
|
|
2
|
+
import { Databuddy as Databuddy$1 } from '../react/index.mjs';
|
|
3
|
+
|
|
4
|
+
function isTrackerAvailable() {
|
|
5
|
+
return typeof window !== "undefined" && (!!window.databuddy || !!window.db);
|
|
6
|
+
}
|
|
7
|
+
function getTracker() {
|
|
8
|
+
if (typeof window === "undefined") {
|
|
9
|
+
return null;
|
|
10
|
+
}
|
|
11
|
+
return window.databuddy || null;
|
|
12
|
+
}
|
|
13
|
+
const track = async (eventName, properties) => {
|
|
14
|
+
if (typeof window === "undefined") {
|
|
15
|
+
return;
|
|
16
|
+
}
|
|
17
|
+
const tracker = window.db?.track || window.databuddy?.track;
|
|
18
|
+
if (!tracker) {
|
|
19
|
+
return;
|
|
20
|
+
}
|
|
21
|
+
try {
|
|
22
|
+
await tracker(eventName, properties);
|
|
23
|
+
} catch (_error) {
|
|
24
|
+
}
|
|
25
|
+
};
|
|
26
|
+
function clear() {
|
|
27
|
+
if (typeof window === "undefined") {
|
|
28
|
+
return;
|
|
29
|
+
}
|
|
30
|
+
const tracker = window.db?.clear || window.databuddy?.clear;
|
|
31
|
+
if (!tracker) {
|
|
32
|
+
return;
|
|
33
|
+
}
|
|
34
|
+
try {
|
|
35
|
+
tracker();
|
|
36
|
+
} catch (_error) {
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
function flush() {
|
|
40
|
+
if (typeof window === "undefined") {
|
|
41
|
+
return;
|
|
42
|
+
}
|
|
43
|
+
const tracker = window.db?.flush || window.databuddy?.flush;
|
|
44
|
+
if (!tracker) {
|
|
45
|
+
return;
|
|
46
|
+
}
|
|
47
|
+
try {
|
|
48
|
+
tracker();
|
|
49
|
+
} catch (_error) {
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
function trackError(message, properties) {
|
|
53
|
+
return track("error", { message, ...properties });
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
const Databuddy = Databuddy$1;
|
|
57
|
+
|
|
58
|
+
export { Databuddy, clear, flush, getTracker, isTrackerAvailable, track, trackError };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { b as Databuddy } from '../shared/@databuddy/sdk.Sqo9i0iN.mjs';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { b as Databuddy } from '../shared/@databuddy/sdk.Sqo9i0iN.js';
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
import { i as isScriptInjected, c as createScript } from '../shared/@databuddy/sdk.CtTNAIIE.mjs';
|
|
4
|
+
|
|
5
|
+
function Databuddy(props) {
|
|
6
|
+
if (typeof window !== "undefined" && !props.disabled && !isScriptInjected()) {
|
|
7
|
+
const script = createScript(props);
|
|
8
|
+
document.head.appendChild(script);
|
|
9
|
+
}
|
|
10
|
+
return null;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export { Databuddy };
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
const version = "2.0.0";
|
|
2
|
+
|
|
3
|
+
const INJECTED_SCRIPT_ATTRIBUTE = "data-databuddy-injected";
|
|
4
|
+
function isScriptInjected() {
|
|
5
|
+
return !!document.querySelector(`script[${INJECTED_SCRIPT_ATTRIBUTE}]`);
|
|
6
|
+
}
|
|
7
|
+
function createScript({
|
|
8
|
+
scriptUrl,
|
|
9
|
+
sdkVersion,
|
|
10
|
+
...props
|
|
11
|
+
}) {
|
|
12
|
+
const script = document.createElement("script");
|
|
13
|
+
script.src = scriptUrl || "https://cdn.databuddy.cc/databuddy.js";
|
|
14
|
+
script.async = true;
|
|
15
|
+
script.crossOrigin = "anonymous";
|
|
16
|
+
script.setAttribute(INJECTED_SCRIPT_ATTRIBUTE, "true");
|
|
17
|
+
script.setAttribute("data-sdk-version", sdkVersion || version);
|
|
18
|
+
for (const [key, value] of Object.entries(props)) {
|
|
19
|
+
const dataKey = `data-${key.replace(/([A-Z])/g, "-$1").toLowerCase()}`;
|
|
20
|
+
script.setAttribute(dataKey, String(value));
|
|
21
|
+
}
|
|
22
|
+
return script;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export { createScript as c, isScriptInjected as i };
|
|
@@ -2,7 +2,7 @@
|
|
|
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
7
|
* Your Databuddy project client ID (required).
|
|
8
8
|
* Get this from your Databuddy dashboard.
|
|
@@ -134,7 +134,7 @@ export interface DatabuddyConfig {
|
|
|
134
134
|
/**
|
|
135
135
|
* Base event properties that can be attached to any event
|
|
136
136
|
*/
|
|
137
|
-
|
|
137
|
+
interface BaseEventProperties {
|
|
138
138
|
/** Page URL */
|
|
139
139
|
__path?: string;
|
|
140
140
|
/** Page title */
|
|
@@ -167,14 +167,14 @@ export interface BaseEventProperties {
|
|
|
167
167
|
/**
|
|
168
168
|
* Custom event properties that can be attached to any event
|
|
169
169
|
*/
|
|
170
|
-
|
|
170
|
+
interface EventProperties extends BaseEventProperties {
|
|
171
171
|
/** Custom properties for the event */
|
|
172
172
|
[key: string]: string | number | boolean | null | undefined;
|
|
173
173
|
}
|
|
174
174
|
/**
|
|
175
175
|
* Pre-defined event types with their specific properties
|
|
176
176
|
*/
|
|
177
|
-
|
|
177
|
+
interface EventTypeMap {
|
|
178
178
|
screen_view: {
|
|
179
179
|
time_on_page?: number;
|
|
180
180
|
scroll_depth?: number;
|
|
@@ -231,15 +231,15 @@ export interface EventTypeMap {
|
|
|
231
231
|
/**
|
|
232
232
|
* Available event names
|
|
233
233
|
*/
|
|
234
|
-
|
|
234
|
+
type EventName = keyof EventTypeMap;
|
|
235
235
|
/**
|
|
236
236
|
* Properties for a specific event type
|
|
237
237
|
*/
|
|
238
|
-
|
|
238
|
+
type PropertiesForEvent<T extends EventName> = T extends keyof EventTypeMap ? EventTypeMap[T] & EventProperties : EventProperties;
|
|
239
239
|
/**
|
|
240
240
|
* Databuddy tracker instance interface
|
|
241
241
|
*/
|
|
242
|
-
|
|
242
|
+
interface DatabuddyTracker {
|
|
243
243
|
/**
|
|
244
244
|
* Track a custom event
|
|
245
245
|
*/
|
|
@@ -284,7 +284,7 @@ declare global {
|
|
|
284
284
|
/**
|
|
285
285
|
* Helper type for HTML data attributes for automatic tracking
|
|
286
286
|
*/
|
|
287
|
-
|
|
287
|
+
interface DataAttributes {
|
|
288
288
|
/** Event name to track when element is clicked */
|
|
289
289
|
'data-track': string;
|
|
290
290
|
/** Additional data attributes (converted to camelCase) */
|
|
@@ -293,6 +293,16 @@ export interface DataAttributes {
|
|
|
293
293
|
/**
|
|
294
294
|
* Utility types for creating typed event tracking functions
|
|
295
295
|
*/
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
296
|
+
type TrackFunction = <T extends EventName>(eventName: T, properties?: PropertiesForEvent<T>) => Promise<void>;
|
|
297
|
+
type ScreenViewFunction = (path?: string, properties?: EventProperties) => void;
|
|
298
|
+
type SetGlobalPropertiesFunction = (properties: EventProperties) => void;
|
|
299
|
+
|
|
300
|
+
/**
|
|
301
|
+
* <Databuddy /> component for Next.js/React apps
|
|
302
|
+
* Injects the databuddy.js script with all config as data attributes
|
|
303
|
+
* Usage: <Databuddy clientId="..." trackScreenViews trackPerformance ... />
|
|
304
|
+
*/
|
|
305
|
+
declare function Databuddy(props: DatabuddyConfig): null;
|
|
306
|
+
|
|
307
|
+
export { Databuddy as b };
|
|
308
|
+
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 };
|
|
@@ -0,0 +1,308 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Configuration options for the Databuddy SDK and <Databuddy /> component.
|
|
3
|
+
* All options are passed as data attributes to the injected script.
|
|
4
|
+
*/
|
|
5
|
+
interface DatabuddyConfig {
|
|
6
|
+
/**
|
|
7
|
+
* Your Databuddy project client ID (required).
|
|
8
|
+
* Get this from your Databuddy dashboard.
|
|
9
|
+
* Example: '3ed1fce1-5a56-4cbc-a917-66864f6d18e3'
|
|
10
|
+
*/
|
|
11
|
+
clientId: string;
|
|
12
|
+
/**
|
|
13
|
+
* (Advanced) Your Databuddy client secret for server-side operations.
|
|
14
|
+
* Not required for browser usage.
|
|
15
|
+
*/
|
|
16
|
+
clientSecret?: string;
|
|
17
|
+
/**
|
|
18
|
+
* Custom API endpoint for event ingestion.
|
|
19
|
+
* Default: 'https://basket.databuddy.cc'
|
|
20
|
+
*/
|
|
21
|
+
apiUrl?: string;
|
|
22
|
+
/**
|
|
23
|
+
* Custom script URL for the Databuddy browser bundle.
|
|
24
|
+
* Default: 'https://cdn.databuddy.cc/databuddy.js'
|
|
25
|
+
*/
|
|
26
|
+
scriptUrl?: string;
|
|
27
|
+
/**
|
|
28
|
+
* SDK name for analytics (default: 'web').
|
|
29
|
+
* Only override if you are building a custom integration.
|
|
30
|
+
*/
|
|
31
|
+
sdk?: string;
|
|
32
|
+
/**
|
|
33
|
+
* SDK version (defaults to package.json version).
|
|
34
|
+
* Only override for custom builds.
|
|
35
|
+
*/
|
|
36
|
+
sdkVersion?: string;
|
|
37
|
+
/**
|
|
38
|
+
* Disable all tracking (default: false).
|
|
39
|
+
* If true, no events will be sent.
|
|
40
|
+
*/
|
|
41
|
+
disabled?: boolean;
|
|
42
|
+
/**
|
|
43
|
+
* Wait for user profile before sending events (advanced, default: false).
|
|
44
|
+
*/
|
|
45
|
+
waitForProfile?: boolean;
|
|
46
|
+
/**
|
|
47
|
+
* Automatically track screen/page views (default: true).
|
|
48
|
+
*/
|
|
49
|
+
trackScreenViews?: boolean;
|
|
50
|
+
/**
|
|
51
|
+
* Track hash changes in the URL (default: false).
|
|
52
|
+
*/
|
|
53
|
+
trackHashChanges?: boolean;
|
|
54
|
+
/**
|
|
55
|
+
* Track user sessions (default: true).
|
|
56
|
+
*/
|
|
57
|
+
trackSessions?: boolean;
|
|
58
|
+
/**
|
|
59
|
+
* Track data-* attributes on elements (default: false).
|
|
60
|
+
*/
|
|
61
|
+
trackAttributes?: boolean;
|
|
62
|
+
/**
|
|
63
|
+
* Track clicks on outgoing links (default: false).
|
|
64
|
+
*/
|
|
65
|
+
trackOutgoingLinks?: boolean;
|
|
66
|
+
/**
|
|
67
|
+
* Track user interactions (default: false).
|
|
68
|
+
*/
|
|
69
|
+
trackInteractions?: boolean;
|
|
70
|
+
/**
|
|
71
|
+
* Track user engagement metrics (default: false).
|
|
72
|
+
*/
|
|
73
|
+
trackEngagement?: boolean;
|
|
74
|
+
/**
|
|
75
|
+
* Track scroll depth (default: false).
|
|
76
|
+
*/
|
|
77
|
+
trackScrollDepth?: boolean;
|
|
78
|
+
/**
|
|
79
|
+
* Track exit intent (default: false).
|
|
80
|
+
*/
|
|
81
|
+
trackExitIntent?: boolean;
|
|
82
|
+
/**
|
|
83
|
+
* Track bounce rate (default: false).
|
|
84
|
+
*/
|
|
85
|
+
trackBounceRate?: boolean;
|
|
86
|
+
/**
|
|
87
|
+
* Track page performance metrics (default: true).
|
|
88
|
+
*/
|
|
89
|
+
trackPerformance?: boolean;
|
|
90
|
+
/**
|
|
91
|
+
* Track Web Vitals metrics (default: false).
|
|
92
|
+
*/
|
|
93
|
+
trackWebVitals?: boolean;
|
|
94
|
+
/**
|
|
95
|
+
* Track JavaScript errors (default: false).
|
|
96
|
+
*/
|
|
97
|
+
trackErrors?: boolean;
|
|
98
|
+
/**
|
|
99
|
+
* Sampling rate for events (0.0 to 1.0, default: 1.0).
|
|
100
|
+
* Example: 0.5 = 50% of events sent.
|
|
101
|
+
*/
|
|
102
|
+
samplingRate?: number;
|
|
103
|
+
/**
|
|
104
|
+
* Enable retries for failed requests (default: true).
|
|
105
|
+
*/
|
|
106
|
+
enableRetries?: boolean;
|
|
107
|
+
/**
|
|
108
|
+
* Maximum number of retries for failed requests (default: 3).
|
|
109
|
+
* Only used if enableRetries is true.
|
|
110
|
+
*/
|
|
111
|
+
maxRetries?: number;
|
|
112
|
+
/**
|
|
113
|
+
* Initial retry delay in milliseconds (default: 500).
|
|
114
|
+
* Only used if enableRetries is true.
|
|
115
|
+
*/
|
|
116
|
+
initialRetryDelay?: number;
|
|
117
|
+
/**
|
|
118
|
+
* Enable event batching (default: false).
|
|
119
|
+
*/
|
|
120
|
+
enableBatching?: boolean;
|
|
121
|
+
/**
|
|
122
|
+
* Number of events to batch before sending (default: 10).
|
|
123
|
+
* Only used if enableBatching is true.
|
|
124
|
+
* Min: 1, Max: 50
|
|
125
|
+
*/
|
|
126
|
+
batchSize?: number;
|
|
127
|
+
/**
|
|
128
|
+
* Batch timeout in milliseconds (default: 2000).
|
|
129
|
+
* Only used if enableBatching is true.
|
|
130
|
+
* Min: 100, Max: 30000
|
|
131
|
+
*/
|
|
132
|
+
batchTimeout?: number;
|
|
133
|
+
}
|
|
134
|
+
/**
|
|
135
|
+
* Base event properties that can be attached to any event
|
|
136
|
+
*/
|
|
137
|
+
interface BaseEventProperties {
|
|
138
|
+
/** Page URL */
|
|
139
|
+
__path?: string;
|
|
140
|
+
/** Page title */
|
|
141
|
+
__title?: string;
|
|
142
|
+
/** Referrer URL */
|
|
143
|
+
__referrer?: string;
|
|
144
|
+
/** Event timestamp in milliseconds */
|
|
145
|
+
__timestamp_ms?: number;
|
|
146
|
+
/** Session ID */
|
|
147
|
+
sessionId?: string;
|
|
148
|
+
/** Session start time */
|
|
149
|
+
sessionStartTime?: number;
|
|
150
|
+
/** Page count in session */
|
|
151
|
+
page_count?: number;
|
|
152
|
+
/** Screen resolution */
|
|
153
|
+
screen_resolution?: string;
|
|
154
|
+
/** Viewport size */
|
|
155
|
+
viewport_size?: string;
|
|
156
|
+
/** User timezone */
|
|
157
|
+
timezone?: string;
|
|
158
|
+
/** User language */
|
|
159
|
+
language?: string;
|
|
160
|
+
/** UTM parameters */
|
|
161
|
+
utm_source?: string;
|
|
162
|
+
utm_medium?: string;
|
|
163
|
+
utm_campaign?: string;
|
|
164
|
+
utm_term?: string;
|
|
165
|
+
utm_content?: string;
|
|
166
|
+
}
|
|
167
|
+
/**
|
|
168
|
+
* Custom event properties that can be attached to any event
|
|
169
|
+
*/
|
|
170
|
+
interface EventProperties extends BaseEventProperties {
|
|
171
|
+
/** Custom properties for the event */
|
|
172
|
+
[key: string]: string | number | boolean | null | undefined;
|
|
173
|
+
}
|
|
174
|
+
/**
|
|
175
|
+
* Pre-defined event types with their specific properties
|
|
176
|
+
*/
|
|
177
|
+
interface EventTypeMap {
|
|
178
|
+
screen_view: {
|
|
179
|
+
time_on_page?: number;
|
|
180
|
+
scroll_depth?: number;
|
|
181
|
+
interaction_count?: number;
|
|
182
|
+
has_exit_intent?: boolean;
|
|
183
|
+
is_bounce?: 0 | 1;
|
|
184
|
+
};
|
|
185
|
+
page_exit: {
|
|
186
|
+
time_on_page: number;
|
|
187
|
+
scroll_depth: number;
|
|
188
|
+
interaction_count: number;
|
|
189
|
+
has_exit_intent: boolean;
|
|
190
|
+
page_count: number;
|
|
191
|
+
is_bounce: 0 | 1;
|
|
192
|
+
};
|
|
193
|
+
button_click: {
|
|
194
|
+
button_text?: string;
|
|
195
|
+
button_type?: string;
|
|
196
|
+
button_id?: string;
|
|
197
|
+
element_class?: string;
|
|
198
|
+
};
|
|
199
|
+
link_out: {
|
|
200
|
+
href: string;
|
|
201
|
+
text?: string;
|
|
202
|
+
target_domain?: string;
|
|
203
|
+
};
|
|
204
|
+
form_submit: {
|
|
205
|
+
form_id?: string;
|
|
206
|
+
form_name?: string;
|
|
207
|
+
form_type?: string;
|
|
208
|
+
success?: boolean;
|
|
209
|
+
};
|
|
210
|
+
web_vitals: {
|
|
211
|
+
fcp?: number;
|
|
212
|
+
lcp?: number;
|
|
213
|
+
cls?: string;
|
|
214
|
+
fid?: number;
|
|
215
|
+
ttfb?: number;
|
|
216
|
+
load_time?: number;
|
|
217
|
+
dom_ready_time?: number;
|
|
218
|
+
render_time?: number;
|
|
219
|
+
request_time?: number;
|
|
220
|
+
};
|
|
221
|
+
error: {
|
|
222
|
+
message: string;
|
|
223
|
+
filename?: string;
|
|
224
|
+
lineno?: number;
|
|
225
|
+
colno?: number;
|
|
226
|
+
stack?: string;
|
|
227
|
+
error_type?: string;
|
|
228
|
+
};
|
|
229
|
+
[eventName: string]: EventProperties;
|
|
230
|
+
}
|
|
231
|
+
/**
|
|
232
|
+
* Available event names
|
|
233
|
+
*/
|
|
234
|
+
type EventName = keyof EventTypeMap;
|
|
235
|
+
/**
|
|
236
|
+
* Properties for a specific event type
|
|
237
|
+
*/
|
|
238
|
+
type PropertiesForEvent<T extends EventName> = T extends keyof EventTypeMap ? EventTypeMap[T] & EventProperties : EventProperties;
|
|
239
|
+
/**
|
|
240
|
+
* Databuddy tracker instance interface
|
|
241
|
+
*/
|
|
242
|
+
interface DatabuddyTracker {
|
|
243
|
+
/**
|
|
244
|
+
* Track a custom event
|
|
245
|
+
*/
|
|
246
|
+
track<T extends EventName>(eventName: T, properties?: PropertiesForEvent<T>): Promise<void>;
|
|
247
|
+
/**
|
|
248
|
+
* Track a screen/page view
|
|
249
|
+
*/
|
|
250
|
+
screenView(path?: string, properties?: EventProperties): void;
|
|
251
|
+
/**
|
|
252
|
+
* Set global properties that will be attached to all events
|
|
253
|
+
*/
|
|
254
|
+
setGlobalProperties(properties: EventProperties): void;
|
|
255
|
+
/**
|
|
256
|
+
* Clear the current user session and generate new IDs
|
|
257
|
+
*/
|
|
258
|
+
clear(): void;
|
|
259
|
+
/**
|
|
260
|
+
* Flush any queued events immediately
|
|
261
|
+
*/
|
|
262
|
+
flush(): void;
|
|
263
|
+
/**
|
|
264
|
+
* Track a custom event with full type safety
|
|
265
|
+
*/
|
|
266
|
+
trackCustomEvent(eventName: string, properties?: EventProperties): void;
|
|
267
|
+
}
|
|
268
|
+
/**
|
|
269
|
+
* Global window interface extensions
|
|
270
|
+
*/
|
|
271
|
+
declare global {
|
|
272
|
+
interface Window {
|
|
273
|
+
databuddy?: DatabuddyTracker;
|
|
274
|
+
db?: {
|
|
275
|
+
track: DatabuddyTracker['track'];
|
|
276
|
+
screenView: DatabuddyTracker['screenView'];
|
|
277
|
+
clear: DatabuddyTracker['clear'];
|
|
278
|
+
flush: DatabuddyTracker['flush'];
|
|
279
|
+
setGlobalProperties: DatabuddyTracker['setGlobalProperties'];
|
|
280
|
+
trackCustomEvent: DatabuddyTracker['trackCustomEvent'];
|
|
281
|
+
};
|
|
282
|
+
}
|
|
283
|
+
}
|
|
284
|
+
/**
|
|
285
|
+
* Helper type for HTML data attributes for automatic tracking
|
|
286
|
+
*/
|
|
287
|
+
interface DataAttributes {
|
|
288
|
+
/** Event name to track when element is clicked */
|
|
289
|
+
'data-track': string;
|
|
290
|
+
/** Additional data attributes (converted to camelCase) */
|
|
291
|
+
[key: `data-${string}`]: string;
|
|
292
|
+
}
|
|
293
|
+
/**
|
|
294
|
+
* Utility types for creating typed event tracking functions
|
|
295
|
+
*/
|
|
296
|
+
type TrackFunction = <T extends EventName>(eventName: T, properties?: PropertiesForEvent<T>) => Promise<void>;
|
|
297
|
+
type ScreenViewFunction = (path?: string, properties?: EventProperties) => void;
|
|
298
|
+
type SetGlobalPropertiesFunction = (properties: EventProperties) => void;
|
|
299
|
+
|
|
300
|
+
/**
|
|
301
|
+
* <Databuddy /> component for Next.js/React apps
|
|
302
|
+
* Injects the databuddy.js script with all config as data attributes
|
|
303
|
+
* Usage: <Databuddy clientId="..." trackScreenViews trackPerformance ... />
|
|
304
|
+
*/
|
|
305
|
+
declare function Databuddy(props: DatabuddyConfig): null;
|
|
306
|
+
|
|
307
|
+
export { Databuddy as b };
|
|
308
|
+
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 };
|
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
import * as vue from 'vue';
|
|
2
|
+
|
|
3
|
+
declare const Databuddy: vue.DefineComponent<{
|
|
4
|
+
clientId: {
|
|
5
|
+
type: StringConstructor;
|
|
6
|
+
required: true;
|
|
7
|
+
};
|
|
8
|
+
clientSecret?: {
|
|
9
|
+
type: StringConstructor;
|
|
10
|
+
required: false;
|
|
11
|
+
} | undefined;
|
|
12
|
+
apiUrl?: {
|
|
13
|
+
type: StringConstructor;
|
|
14
|
+
required: false;
|
|
15
|
+
} | undefined;
|
|
16
|
+
scriptUrl?: {
|
|
17
|
+
type: StringConstructor;
|
|
18
|
+
required: false;
|
|
19
|
+
} | undefined;
|
|
20
|
+
sdk?: {
|
|
21
|
+
type: StringConstructor;
|
|
22
|
+
required: false;
|
|
23
|
+
} | undefined;
|
|
24
|
+
sdkVersion?: {
|
|
25
|
+
type: StringConstructor;
|
|
26
|
+
required: false;
|
|
27
|
+
} | undefined;
|
|
28
|
+
disabled?: {
|
|
29
|
+
type: BooleanConstructor;
|
|
30
|
+
required: false;
|
|
31
|
+
} | undefined;
|
|
32
|
+
waitForProfile?: {
|
|
33
|
+
type: BooleanConstructor;
|
|
34
|
+
required: false;
|
|
35
|
+
} | undefined;
|
|
36
|
+
trackScreenViews?: {
|
|
37
|
+
type: BooleanConstructor;
|
|
38
|
+
required: false;
|
|
39
|
+
} | undefined;
|
|
40
|
+
trackHashChanges?: {
|
|
41
|
+
type: BooleanConstructor;
|
|
42
|
+
required: false;
|
|
43
|
+
} | undefined;
|
|
44
|
+
trackSessions?: {
|
|
45
|
+
type: BooleanConstructor;
|
|
46
|
+
required: false;
|
|
47
|
+
} | undefined;
|
|
48
|
+
trackAttributes?: {
|
|
49
|
+
type: BooleanConstructor;
|
|
50
|
+
required: false;
|
|
51
|
+
} | undefined;
|
|
52
|
+
trackOutgoingLinks?: {
|
|
53
|
+
type: BooleanConstructor;
|
|
54
|
+
required: false;
|
|
55
|
+
} | undefined;
|
|
56
|
+
trackInteractions?: {
|
|
57
|
+
type: BooleanConstructor;
|
|
58
|
+
required: false;
|
|
59
|
+
} | undefined;
|
|
60
|
+
trackEngagement?: {
|
|
61
|
+
type: BooleanConstructor;
|
|
62
|
+
required: false;
|
|
63
|
+
} | undefined;
|
|
64
|
+
trackScrollDepth?: {
|
|
65
|
+
type: BooleanConstructor;
|
|
66
|
+
required: false;
|
|
67
|
+
} | undefined;
|
|
68
|
+
trackExitIntent?: {
|
|
69
|
+
type: BooleanConstructor;
|
|
70
|
+
required: false;
|
|
71
|
+
} | undefined;
|
|
72
|
+
trackBounceRate?: {
|
|
73
|
+
type: BooleanConstructor;
|
|
74
|
+
required: false;
|
|
75
|
+
} | undefined;
|
|
76
|
+
trackPerformance?: {
|
|
77
|
+
type: BooleanConstructor;
|
|
78
|
+
required: false;
|
|
79
|
+
} | undefined;
|
|
80
|
+
trackWebVitals?: {
|
|
81
|
+
type: BooleanConstructor;
|
|
82
|
+
required: false;
|
|
83
|
+
} | undefined;
|
|
84
|
+
trackErrors?: {
|
|
85
|
+
type: BooleanConstructor;
|
|
86
|
+
required: false;
|
|
87
|
+
} | undefined;
|
|
88
|
+
samplingRate?: {
|
|
89
|
+
type: NumberConstructor;
|
|
90
|
+
required: false;
|
|
91
|
+
} | undefined;
|
|
92
|
+
enableRetries?: {
|
|
93
|
+
type: BooleanConstructor;
|
|
94
|
+
required: false;
|
|
95
|
+
} | undefined;
|
|
96
|
+
maxRetries?: {
|
|
97
|
+
type: NumberConstructor;
|
|
98
|
+
required: false;
|
|
99
|
+
} | undefined;
|
|
100
|
+
initialRetryDelay?: {
|
|
101
|
+
type: NumberConstructor;
|
|
102
|
+
required: false;
|
|
103
|
+
} | undefined;
|
|
104
|
+
enableBatching?: {
|
|
105
|
+
type: BooleanConstructor;
|
|
106
|
+
required: false;
|
|
107
|
+
} | undefined;
|
|
108
|
+
batchSize?: {
|
|
109
|
+
type: NumberConstructor;
|
|
110
|
+
required: false;
|
|
111
|
+
} | undefined;
|
|
112
|
+
batchTimeout?: {
|
|
113
|
+
type: NumberConstructor;
|
|
114
|
+
required: false;
|
|
115
|
+
} | undefined;
|
|
116
|
+
}, () => null, unknown, {}, {}, vue.ComponentOptionsMixin, vue.ComponentOptionsMixin, Record<string, any>, string, vue.VNodeProps & vue.AllowedComponentProps & vue.ComponentCustomProps, Readonly<{
|
|
117
|
+
clientId: string;
|
|
118
|
+
} & {
|
|
119
|
+
clientSecret?: string | undefined;
|
|
120
|
+
apiUrl?: string | undefined;
|
|
121
|
+
scriptUrl?: string | undefined;
|
|
122
|
+
sdk?: string | undefined;
|
|
123
|
+
sdkVersion?: string | undefined;
|
|
124
|
+
disabled?: boolean | undefined;
|
|
125
|
+
waitForProfile?: boolean | undefined;
|
|
126
|
+
trackScreenViews?: boolean | undefined;
|
|
127
|
+
trackHashChanges?: boolean | undefined;
|
|
128
|
+
trackSessions?: boolean | undefined;
|
|
129
|
+
trackAttributes?: boolean | undefined;
|
|
130
|
+
trackOutgoingLinks?: boolean | undefined;
|
|
131
|
+
trackInteractions?: boolean | undefined;
|
|
132
|
+
trackEngagement?: boolean | undefined;
|
|
133
|
+
trackScrollDepth?: boolean | undefined;
|
|
134
|
+
trackExitIntent?: boolean | undefined;
|
|
135
|
+
trackBounceRate?: boolean | undefined;
|
|
136
|
+
trackPerformance?: boolean | undefined;
|
|
137
|
+
trackWebVitals?: boolean | undefined;
|
|
138
|
+
trackErrors?: boolean | undefined;
|
|
139
|
+
samplingRate?: number | undefined;
|
|
140
|
+
enableRetries?: boolean | undefined;
|
|
141
|
+
maxRetries?: number | undefined;
|
|
142
|
+
initialRetryDelay?: number | undefined;
|
|
143
|
+
enableBatching?: boolean | undefined;
|
|
144
|
+
batchSize?: number | undefined;
|
|
145
|
+
batchTimeout?: number | undefined;
|
|
146
|
+
}>, {}>;
|
|
147
|
+
|
|
148
|
+
export { Databuddy };
|
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
import * as vue from 'vue';
|
|
2
|
+
|
|
3
|
+
declare const Databuddy: vue.DefineComponent<{
|
|
4
|
+
clientId: {
|
|
5
|
+
type: StringConstructor;
|
|
6
|
+
required: true;
|
|
7
|
+
};
|
|
8
|
+
clientSecret?: {
|
|
9
|
+
type: StringConstructor;
|
|
10
|
+
required: false;
|
|
11
|
+
} | undefined;
|
|
12
|
+
apiUrl?: {
|
|
13
|
+
type: StringConstructor;
|
|
14
|
+
required: false;
|
|
15
|
+
} | undefined;
|
|
16
|
+
scriptUrl?: {
|
|
17
|
+
type: StringConstructor;
|
|
18
|
+
required: false;
|
|
19
|
+
} | undefined;
|
|
20
|
+
sdk?: {
|
|
21
|
+
type: StringConstructor;
|
|
22
|
+
required: false;
|
|
23
|
+
} | undefined;
|
|
24
|
+
sdkVersion?: {
|
|
25
|
+
type: StringConstructor;
|
|
26
|
+
required: false;
|
|
27
|
+
} | undefined;
|
|
28
|
+
disabled?: {
|
|
29
|
+
type: BooleanConstructor;
|
|
30
|
+
required: false;
|
|
31
|
+
} | undefined;
|
|
32
|
+
waitForProfile?: {
|
|
33
|
+
type: BooleanConstructor;
|
|
34
|
+
required: false;
|
|
35
|
+
} | undefined;
|
|
36
|
+
trackScreenViews?: {
|
|
37
|
+
type: BooleanConstructor;
|
|
38
|
+
required: false;
|
|
39
|
+
} | undefined;
|
|
40
|
+
trackHashChanges?: {
|
|
41
|
+
type: BooleanConstructor;
|
|
42
|
+
required: false;
|
|
43
|
+
} | undefined;
|
|
44
|
+
trackSessions?: {
|
|
45
|
+
type: BooleanConstructor;
|
|
46
|
+
required: false;
|
|
47
|
+
} | undefined;
|
|
48
|
+
trackAttributes?: {
|
|
49
|
+
type: BooleanConstructor;
|
|
50
|
+
required: false;
|
|
51
|
+
} | undefined;
|
|
52
|
+
trackOutgoingLinks?: {
|
|
53
|
+
type: BooleanConstructor;
|
|
54
|
+
required: false;
|
|
55
|
+
} | undefined;
|
|
56
|
+
trackInteractions?: {
|
|
57
|
+
type: BooleanConstructor;
|
|
58
|
+
required: false;
|
|
59
|
+
} | undefined;
|
|
60
|
+
trackEngagement?: {
|
|
61
|
+
type: BooleanConstructor;
|
|
62
|
+
required: false;
|
|
63
|
+
} | undefined;
|
|
64
|
+
trackScrollDepth?: {
|
|
65
|
+
type: BooleanConstructor;
|
|
66
|
+
required: false;
|
|
67
|
+
} | undefined;
|
|
68
|
+
trackExitIntent?: {
|
|
69
|
+
type: BooleanConstructor;
|
|
70
|
+
required: false;
|
|
71
|
+
} | undefined;
|
|
72
|
+
trackBounceRate?: {
|
|
73
|
+
type: BooleanConstructor;
|
|
74
|
+
required: false;
|
|
75
|
+
} | undefined;
|
|
76
|
+
trackPerformance?: {
|
|
77
|
+
type: BooleanConstructor;
|
|
78
|
+
required: false;
|
|
79
|
+
} | undefined;
|
|
80
|
+
trackWebVitals?: {
|
|
81
|
+
type: BooleanConstructor;
|
|
82
|
+
required: false;
|
|
83
|
+
} | undefined;
|
|
84
|
+
trackErrors?: {
|
|
85
|
+
type: BooleanConstructor;
|
|
86
|
+
required: false;
|
|
87
|
+
} | undefined;
|
|
88
|
+
samplingRate?: {
|
|
89
|
+
type: NumberConstructor;
|
|
90
|
+
required: false;
|
|
91
|
+
} | undefined;
|
|
92
|
+
enableRetries?: {
|
|
93
|
+
type: BooleanConstructor;
|
|
94
|
+
required: false;
|
|
95
|
+
} | undefined;
|
|
96
|
+
maxRetries?: {
|
|
97
|
+
type: NumberConstructor;
|
|
98
|
+
required: false;
|
|
99
|
+
} | undefined;
|
|
100
|
+
initialRetryDelay?: {
|
|
101
|
+
type: NumberConstructor;
|
|
102
|
+
required: false;
|
|
103
|
+
} | undefined;
|
|
104
|
+
enableBatching?: {
|
|
105
|
+
type: BooleanConstructor;
|
|
106
|
+
required: false;
|
|
107
|
+
} | undefined;
|
|
108
|
+
batchSize?: {
|
|
109
|
+
type: NumberConstructor;
|
|
110
|
+
required: false;
|
|
111
|
+
} | undefined;
|
|
112
|
+
batchTimeout?: {
|
|
113
|
+
type: NumberConstructor;
|
|
114
|
+
required: false;
|
|
115
|
+
} | undefined;
|
|
116
|
+
}, () => null, unknown, {}, {}, vue.ComponentOptionsMixin, vue.ComponentOptionsMixin, Record<string, any>, string, vue.VNodeProps & vue.AllowedComponentProps & vue.ComponentCustomProps, Readonly<{
|
|
117
|
+
clientId: string;
|
|
118
|
+
} & {
|
|
119
|
+
clientSecret?: string | undefined;
|
|
120
|
+
apiUrl?: string | undefined;
|
|
121
|
+
scriptUrl?: string | undefined;
|
|
122
|
+
sdk?: string | undefined;
|
|
123
|
+
sdkVersion?: string | undefined;
|
|
124
|
+
disabled?: boolean | undefined;
|
|
125
|
+
waitForProfile?: boolean | undefined;
|
|
126
|
+
trackScreenViews?: boolean | undefined;
|
|
127
|
+
trackHashChanges?: boolean | undefined;
|
|
128
|
+
trackSessions?: boolean | undefined;
|
|
129
|
+
trackAttributes?: boolean | undefined;
|
|
130
|
+
trackOutgoingLinks?: boolean | undefined;
|
|
131
|
+
trackInteractions?: boolean | undefined;
|
|
132
|
+
trackEngagement?: boolean | undefined;
|
|
133
|
+
trackScrollDepth?: boolean | undefined;
|
|
134
|
+
trackExitIntent?: boolean | undefined;
|
|
135
|
+
trackBounceRate?: boolean | undefined;
|
|
136
|
+
trackPerformance?: boolean | undefined;
|
|
137
|
+
trackWebVitals?: boolean | undefined;
|
|
138
|
+
trackErrors?: boolean | undefined;
|
|
139
|
+
samplingRate?: number | undefined;
|
|
140
|
+
enableRetries?: boolean | undefined;
|
|
141
|
+
maxRetries?: number | undefined;
|
|
142
|
+
initialRetryDelay?: number | undefined;
|
|
143
|
+
enableBatching?: boolean | undefined;
|
|
144
|
+
batchSize?: number | undefined;
|
|
145
|
+
batchTimeout?: number | undefined;
|
|
146
|
+
}>, {}>;
|
|
147
|
+
|
|
148
|
+
export { Databuddy };
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { defineComponent, ref, onMounted, onUnmounted, watch } from 'vue';
|
|
2
|
+
import { i as isScriptInjected, c as createScript } from '../shared/@databuddy/sdk.CtTNAIIE.mjs';
|
|
3
|
+
|
|
4
|
+
const Databuddy = defineComponent({
|
|
5
|
+
props: {},
|
|
6
|
+
setup(props) {
|
|
7
|
+
const scriptRef = ref(null);
|
|
8
|
+
const injectScript = () => {
|
|
9
|
+
if (props.disabled || isScriptInjected()) {
|
|
10
|
+
return;
|
|
11
|
+
}
|
|
12
|
+
const script = createScript(props);
|
|
13
|
+
document.head.appendChild(script);
|
|
14
|
+
scriptRef.value = script;
|
|
15
|
+
};
|
|
16
|
+
const removeScript = () => {
|
|
17
|
+
if (scriptRef.value) {
|
|
18
|
+
scriptRef.value.remove();
|
|
19
|
+
scriptRef.value = null;
|
|
20
|
+
}
|
|
21
|
+
};
|
|
22
|
+
onMounted(() => {
|
|
23
|
+
injectScript();
|
|
24
|
+
});
|
|
25
|
+
onUnmounted(() => {
|
|
26
|
+
removeScript();
|
|
27
|
+
});
|
|
28
|
+
watch(
|
|
29
|
+
() => props,
|
|
30
|
+
() => {
|
|
31
|
+
removeScript();
|
|
32
|
+
injectScript();
|
|
33
|
+
},
|
|
34
|
+
{ deep: true }
|
|
35
|
+
);
|
|
36
|
+
return () => null;
|
|
37
|
+
}
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
export { Databuddy };
|
package/package.json
CHANGED
|
@@ -1,15 +1,49 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@databuddy/sdk",
|
|
3
|
-
"version": "
|
|
4
|
-
"
|
|
3
|
+
"version": "2.0.0",
|
|
4
|
+
"description": "Official Databuddy Analytics SDK",
|
|
5
|
+
"main": "./dist/core/index.mjs",
|
|
6
|
+
"types": "./dist/core/index.d.ts",
|
|
7
|
+
"license": "MIT",
|
|
8
|
+
"private": false,
|
|
9
|
+
"scripts": {
|
|
10
|
+
"build": "unbuild"
|
|
11
|
+
},
|
|
5
12
|
"devDependencies": {
|
|
6
13
|
"@types/node": "^20.0.0",
|
|
7
|
-
"
|
|
14
|
+
"@vitejs/plugin-react": "^5.0.0",
|
|
15
|
+
"react": "18.0.0",
|
|
16
|
+
"typescript": "catalog:",
|
|
17
|
+
"unbuild": "^3.6.1",
|
|
18
|
+
"vue": "3.0.0",
|
|
19
|
+
"vue-sfc-transformer": "^0.1.16"
|
|
20
|
+
},
|
|
21
|
+
"peerDependencies": {
|
|
22
|
+
"react": ">=18",
|
|
23
|
+
"vue": ">=3"
|
|
24
|
+
},
|
|
25
|
+
"peerDependenciesMeta": {
|
|
26
|
+
"react": {
|
|
27
|
+
"optional": true
|
|
28
|
+
},
|
|
29
|
+
"vue": {
|
|
30
|
+
"optional": true
|
|
31
|
+
}
|
|
8
32
|
},
|
|
9
33
|
"exports": {
|
|
10
|
-
".":
|
|
34
|
+
".": {
|
|
35
|
+
"types": "./dist/core/index.d.ts",
|
|
36
|
+
"import": "./dist/core/index.mjs"
|
|
37
|
+
},
|
|
38
|
+
"./react": {
|
|
39
|
+
"types": "./dist/react/index.d.ts",
|
|
40
|
+
"import": "./dist/react/index.mjs"
|
|
41
|
+
},
|
|
42
|
+
"./vue": {
|
|
43
|
+
"types": "./dist/vue/index.d.ts",
|
|
44
|
+
"import": "./dist/vue/index.mjs"
|
|
45
|
+
}
|
|
11
46
|
},
|
|
12
|
-
"description": "Official Databuddy Analytics SDK",
|
|
13
47
|
"files": [
|
|
14
48
|
"dist"
|
|
15
49
|
],
|
|
@@ -17,11 +51,8 @@
|
|
|
17
51
|
"analytics",
|
|
18
52
|
"tracking",
|
|
19
53
|
"databuddy",
|
|
20
|
-
"sdk"
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
"build": "tsc --project tsconfig.json"
|
|
26
|
-
}
|
|
27
|
-
}
|
|
54
|
+
"sdk",
|
|
55
|
+
"react",
|
|
56
|
+
"vue"
|
|
57
|
+
]
|
|
58
|
+
}
|
package/dist/Databuddy.d.ts
DELETED
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import type { DatabuddyConfig } from './types';
|
|
2
|
-
/**
|
|
3
|
-
* <Databuddy /> component for Next.js/React apps
|
|
4
|
-
* Injects the databuddy.js script with all config as data attributes
|
|
5
|
-
* Usage: <Databuddy clientId="..." trackScreenViews trackPerformance ... />
|
|
6
|
-
*/
|
|
7
|
-
export declare function Databuddy(props: DatabuddyConfig): null;
|
|
8
|
-
export default Databuddy;
|
package/dist/Databuddy.js
DELETED
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
'use client';
|
|
2
|
-
import pkg from '../package.json';
|
|
3
|
-
import { useEffect } from 'react';
|
|
4
|
-
/**
|
|
5
|
-
* <Databuddy /> component for Next.js/React apps
|
|
6
|
-
* Injects the databuddy.js script with all config as data attributes
|
|
7
|
-
* Usage: <Databuddy clientId="..." trackScreenViews trackPerformance ... />
|
|
8
|
-
*/
|
|
9
|
-
export function Databuddy(props) {
|
|
10
|
-
useEffect(() => {
|
|
11
|
-
if (typeof window === 'undefined')
|
|
12
|
-
return;
|
|
13
|
-
if (props.disabled)
|
|
14
|
-
return;
|
|
15
|
-
if (document.querySelector('script[data-databuddy-injected]'))
|
|
16
|
-
return;
|
|
17
|
-
const script = document.createElement('script');
|
|
18
|
-
script.src = props.scriptUrl || 'https://cdn.databuddy.cc/databuddy.js';
|
|
19
|
-
script.async = true;
|
|
20
|
-
script.crossOrigin = 'anonymous';
|
|
21
|
-
script.setAttribute('data-databuddy-injected', 'true');
|
|
22
|
-
// Always set sdkVersion from package.json unless explicitly overridden
|
|
23
|
-
const sdkVersion = props.sdkVersion || pkg.version;
|
|
24
|
-
script.setAttribute('data-sdk-version', sdkVersion);
|
|
25
|
-
for (const [key, value] of Object.entries(props)) {
|
|
26
|
-
if (value !== undefined && key !== 'sdkVersion') {
|
|
27
|
-
const dataKey = `data-${key.replace(/([A-Z])/g, '-$1').toLowerCase()}`;
|
|
28
|
-
// Convert booleans and numbers to string for HTML attributes
|
|
29
|
-
if (typeof value === 'boolean') {
|
|
30
|
-
script.setAttribute(dataKey, value ? 'true' : 'false');
|
|
31
|
-
}
|
|
32
|
-
else if (typeof value === 'number') {
|
|
33
|
-
script.setAttribute(dataKey, value.toString());
|
|
34
|
-
}
|
|
35
|
-
else {
|
|
36
|
-
script.setAttribute(dataKey, String(value));
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
document.head.appendChild(script);
|
|
41
|
-
return () => {
|
|
42
|
-
script.remove();
|
|
43
|
-
};
|
|
44
|
-
}, [props]);
|
|
45
|
-
return null;
|
|
46
|
-
}
|
|
47
|
-
export default Databuddy;
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import type { DatabuddyConfig } from './types';
|
|
2
|
-
/**
|
|
3
|
-
* <Databuddy /> component for Next.js/React apps
|
|
4
|
-
* Injects the databuddy.js script with all config as data attributes
|
|
5
|
-
* Usage: <Databuddy clientId="..." trackScreenViews trackPerformance ... />
|
|
6
|
-
*/
|
|
7
|
-
export declare function Databuddy(props: DatabuddyConfig): null;
|
|
8
|
-
export default Databuddy;
|
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
'use client';
|
|
2
|
-
import { useEffect } from 'react';
|
|
3
|
-
/**
|
|
4
|
-
* <Databuddy /> component for Next.js/React apps
|
|
5
|
-
* Injects the databuddy.js script with all config as data attributes
|
|
6
|
-
* Usage: <Databuddy clientId="..." trackScreenViews trackPerformance ... />
|
|
7
|
-
*/
|
|
8
|
-
export function Databuddy(props) {
|
|
9
|
-
useEffect(() => {
|
|
10
|
-
if (typeof window === 'undefined')
|
|
11
|
-
return;
|
|
12
|
-
if (document.querySelector('script[data-databuddy-injected]'))
|
|
13
|
-
return;
|
|
14
|
-
const script = document.createElement('script');
|
|
15
|
-
script.src = props.scriptUrl || 'https://app.databuddy.cc/databuddy.js';
|
|
16
|
-
script.defer = true;
|
|
17
|
-
script.setAttribute('data-databuddy-injected', 'true');
|
|
18
|
-
for (const [key, value] of Object.entries(props)) {
|
|
19
|
-
if (value !== undefined) {
|
|
20
|
-
const dataKey = `data-${key.replace(/([A-Z])/g, '-$1').toLowerCase()}`;
|
|
21
|
-
script.setAttribute(dataKey, String(value));
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
document.head.appendChild(script);
|
|
25
|
-
return () => {
|
|
26
|
-
script.remove();
|
|
27
|
-
};
|
|
28
|
-
}, [props]);
|
|
29
|
-
return null;
|
|
30
|
-
}
|
|
31
|
-
export default Databuddy;
|
package/dist/index.d.ts
DELETED
package/dist/index.js
DELETED
package/dist/tracker.d.ts
DELETED
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Databuddy SDK Client-side Tracker
|
|
3
|
-
* Provides type-safe tracking functions
|
|
4
|
-
*/
|
|
5
|
-
import type { DatabuddyTracker, TrackFunction } from './types';
|
|
6
|
-
/**
|
|
7
|
-
* Check if the Databuddy tracker is available
|
|
8
|
-
*/
|
|
9
|
-
export declare function isTrackerAvailable(): boolean;
|
|
10
|
-
/**
|
|
11
|
-
* Get the Databuddy tracker instance
|
|
12
|
-
*/
|
|
13
|
-
export declare function getTracker(): DatabuddyTracker | null;
|
|
14
|
-
/**
|
|
15
|
-
* Type-safe track function
|
|
16
|
-
*/
|
|
17
|
-
export declare const track: TrackFunction;
|
|
18
|
-
/**
|
|
19
|
-
* Clear the current session
|
|
20
|
-
*/
|
|
21
|
-
export declare function clear(): void;
|
|
22
|
-
/**
|
|
23
|
-
* Flush any queued events
|
|
24
|
-
*/
|
|
25
|
-
export declare function flush(): void;
|
|
26
|
-
/**
|
|
27
|
-
* Track an error event
|
|
28
|
-
*/
|
|
29
|
-
export declare function trackError(message: string, properties?: {
|
|
30
|
-
filename?: string;
|
|
31
|
-
lineno?: number;
|
|
32
|
-
colno?: number;
|
|
33
|
-
stack?: string;
|
|
34
|
-
error_type?: string;
|
|
35
|
-
[key: string]: any;
|
|
36
|
-
}): Promise<void>;
|
|
37
|
-
declare const _default: {
|
|
38
|
-
track: TrackFunction;
|
|
39
|
-
clear: typeof clear;
|
|
40
|
-
flush: typeof flush;
|
|
41
|
-
trackError: typeof trackError;
|
|
42
|
-
};
|
|
43
|
-
export default _default;
|
package/dist/tracker.js
DELETED
|
@@ -1,86 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Databuddy SDK Client-side Tracker
|
|
3
|
-
* Provides type-safe tracking functions
|
|
4
|
-
*/
|
|
5
|
-
/**
|
|
6
|
-
* Check if the Databuddy tracker is available
|
|
7
|
-
*/
|
|
8
|
-
export function isTrackerAvailable() {
|
|
9
|
-
return typeof window !== 'undefined' &&
|
|
10
|
-
(!!window.databuddy || !!window.db);
|
|
11
|
-
}
|
|
12
|
-
/**
|
|
13
|
-
* Get the Databuddy tracker instance
|
|
14
|
-
*/
|
|
15
|
-
export function getTracker() {
|
|
16
|
-
if (typeof window === 'undefined')
|
|
17
|
-
return null;
|
|
18
|
-
return window.databuddy || null;
|
|
19
|
-
}
|
|
20
|
-
/**
|
|
21
|
-
* Type-safe track function
|
|
22
|
-
*/
|
|
23
|
-
export const track = async (eventName, properties) => {
|
|
24
|
-
var _a, _b;
|
|
25
|
-
if (typeof window === 'undefined') {
|
|
26
|
-
return;
|
|
27
|
-
}
|
|
28
|
-
// Try window.db first (shorthand), then window.databuddy
|
|
29
|
-
const tracker = ((_a = window.db) === null || _a === void 0 ? void 0 : _a.track) || ((_b = window.databuddy) === null || _b === void 0 ? void 0 : _b.track);
|
|
30
|
-
if (!tracker) {
|
|
31
|
-
return;
|
|
32
|
-
}
|
|
33
|
-
try {
|
|
34
|
-
await tracker(eventName, properties);
|
|
35
|
-
}
|
|
36
|
-
catch (error) {
|
|
37
|
-
}
|
|
38
|
-
};
|
|
39
|
-
/**
|
|
40
|
-
* Clear the current session
|
|
41
|
-
*/
|
|
42
|
-
export function clear() {
|
|
43
|
-
var _a, _b;
|
|
44
|
-
if (typeof window === 'undefined') {
|
|
45
|
-
return;
|
|
46
|
-
}
|
|
47
|
-
const tracker = ((_a = window.db) === null || _a === void 0 ? void 0 : _a.clear) || ((_b = window.databuddy) === null || _b === void 0 ? void 0 : _b.clear);
|
|
48
|
-
if (!tracker) {
|
|
49
|
-
return;
|
|
50
|
-
}
|
|
51
|
-
try {
|
|
52
|
-
tracker();
|
|
53
|
-
}
|
|
54
|
-
catch (error) {
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
/**
|
|
58
|
-
* Flush any queued events
|
|
59
|
-
*/
|
|
60
|
-
export function flush() {
|
|
61
|
-
var _a, _b;
|
|
62
|
-
if (typeof window === 'undefined') {
|
|
63
|
-
return;
|
|
64
|
-
}
|
|
65
|
-
const tracker = ((_a = window.db) === null || _a === void 0 ? void 0 : _a.flush) || ((_b = window.databuddy) === null || _b === void 0 ? void 0 : _b.flush);
|
|
66
|
-
if (!tracker) {
|
|
67
|
-
return;
|
|
68
|
-
}
|
|
69
|
-
try {
|
|
70
|
-
tracker();
|
|
71
|
-
}
|
|
72
|
-
catch (error) {
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
/**
|
|
76
|
-
* Track an error event
|
|
77
|
-
*/
|
|
78
|
-
export function trackError(message, properties) {
|
|
79
|
-
return track('error', { message, ...properties });
|
|
80
|
-
}
|
|
81
|
-
export default {
|
|
82
|
-
track,
|
|
83
|
-
clear,
|
|
84
|
-
flush,
|
|
85
|
-
trackError,
|
|
86
|
-
};
|
package/dist/types.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|