@databuddy/sdk 1.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.
@@ -0,0 +1,8 @@
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;
@@ -0,0 +1,31 @@
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;
@@ -0,0 +1,2 @@
1
+ export * from './DatabuddyProvider';
2
+ export * from './types';
package/dist/index.js ADDED
@@ -0,0 +1,2 @@
1
+ export * from './DatabuddyProvider';
2
+ export * from './types';
@@ -0,0 +1,140 @@
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
+ export 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://api.databuddy.cc'
20
+ */
21
+ apiUrl?: string;
22
+ /**
23
+ * Custom script URL for the Databuddy browser bundle.
24
+ * Default: 'https://app.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 (default: '1.0.0').
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 data-* attributes on elements (default: false).
56
+ */
57
+ trackAttributes?: boolean;
58
+ /**
59
+ * Track clicks on outgoing links (default: false).
60
+ */
61
+ trackOutgoingLinks?: boolean;
62
+ /**
63
+ * Track user sessions (default: false).
64
+ */
65
+ trackSessions?: boolean;
66
+ /**
67
+ * Track page performance metrics (default: true).
68
+ */
69
+ trackPerformance?: boolean;
70
+ /**
71
+ * Track Web Vitals metrics (default: true).
72
+ */
73
+ trackWebVitals?: boolean;
74
+ /**
75
+ * Track user engagement metrics (default: false).
76
+ */
77
+ trackEngagement?: boolean;
78
+ /**
79
+ * Track scroll depth (default: false).
80
+ */
81
+ trackScrollDepth?: boolean;
82
+ /**
83
+ * Track exit intent (default: false).
84
+ */
85
+ trackExitIntent?: boolean;
86
+ /**
87
+ * Track user interactions (default: false).
88
+ */
89
+ trackInteractions?: boolean;
90
+ /**
91
+ * Track JavaScript errors (default: true).
92
+ */
93
+ trackErrors?: boolean;
94
+ /**
95
+ * Track bounce rate (default: false).
96
+ */
97
+ trackBounceRate?: 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: true).
119
+ */
120
+ enableBatching?: boolean;
121
+ /**
122
+ * Number of events to batch before sending (default: 20).
123
+ * Only used if enableBatching is true.
124
+ * Min: 1, Max: 50
125
+ */
126
+ batchSize?: number;
127
+ /**
128
+ * Batch timeout in milliseconds (default: 5000).
129
+ * Only used if enableBatching is true.
130
+ * Min: 100, Max: 30000
131
+ */
132
+ batchTimeout?: number;
133
+ }
134
+ /**
135
+ * Event properties that can be attached to any event
136
+ */
137
+ export interface EventProperties {
138
+ /** Custom properties for the event */
139
+ [key: string]: string | number | boolean | null | undefined | EventProperties;
140
+ }
package/dist/types.js ADDED
@@ -0,0 +1 @@
1
+ export {};
package/package.json ADDED
@@ -0,0 +1,25 @@
1
+ {
2
+ "name": "@databuddy/sdk",
3
+ "version": "1.0.0",
4
+ "private": false,
5
+ "description": "Official Databuddy Analytics SDK",
6
+ "main": "dist/index.js",
7
+ "exports": {
8
+ ".": "./dist/index.js"
9
+ },
10
+ "keywords": [
11
+ "analytics",
12
+ "tracking",
13
+ "databuddy",
14
+ "sdk"
15
+ ],
16
+ "scripts": {
17
+ "build": "tsc --project tsconfig.json"
18
+ },
19
+ "author": "Databuddy",
20
+ "license": "MIT",
21
+ "devDependencies": {
22
+ "@types/node": "^20.0.0",
23
+ "typescript": "^5.0.0"
24
+ }
25
+ }
@@ -0,0 +1,33 @@
1
+ 'use client';
2
+
3
+ import { useEffect } from 'react';
4
+ import type { DatabuddyConfig } from './types';
5
+
6
+ /**
7
+ * <Databuddy /> component for Next.js/React apps
8
+ * Injects the databuddy.js script with all config as data attributes
9
+ * Usage: <Databuddy clientId="..." trackScreenViews trackPerformance ... />
10
+ */
11
+ export function Databuddy(props: DatabuddyConfig) {
12
+ useEffect(() => {
13
+ if (typeof window === 'undefined') return;
14
+ if (document.querySelector('script[data-databuddy-injected]')) return;
15
+ const script = document.createElement('script');
16
+ script.src = props.scriptUrl || 'https://app.databuddy.cc/databuddy.js';
17
+ script.defer = true;
18
+ script.setAttribute('data-databuddy-injected', 'true');
19
+ for (const [key, value] of Object.entries(props)) {
20
+ if (value !== undefined) {
21
+ const dataKey = `data-${key.replace(/([A-Z])/g, '-$1').toLowerCase()}`;
22
+ script.setAttribute(dataKey, String(value));
23
+ }
24
+ }
25
+ document.head.appendChild(script);
26
+ return () => {
27
+ script.remove();
28
+ };
29
+ }, [props]);
30
+ return null;
31
+ }
32
+
33
+ export default Databuddy;
package/src/index.ts ADDED
@@ -0,0 +1,2 @@
1
+ export * from './DatabuddyProvider';
2
+ export * from './types';
package/src/types.ts ADDED
@@ -0,0 +1,173 @@
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
+ export 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
+ /**
14
+ * (Advanced) Your Databuddy client secret for server-side operations.
15
+ * Not required for browser usage.
16
+ */
17
+ clientSecret?: string;
18
+
19
+ /**
20
+ * Custom API endpoint for event ingestion.
21
+ * Default: 'https://api.databuddy.cc'
22
+ */
23
+ apiUrl?: string;
24
+
25
+ /**
26
+ * Custom script URL for the Databuddy browser bundle.
27
+ * Default: 'https://app.databuddy.cc/databuddy.js'
28
+ */
29
+ scriptUrl?: string;
30
+
31
+ /**
32
+ * SDK name for analytics (default: 'web').
33
+ * Only override if you are building a custom integration.
34
+ */
35
+ sdk?: string;
36
+
37
+ /**
38
+ * SDK version (default: '1.0.0').
39
+ * Only override for custom builds.
40
+ */
41
+ sdkVersion?: string;
42
+
43
+ /**
44
+ * Disable all tracking (default: false).
45
+ * If true, no events will be sent.
46
+ */
47
+ disabled?: boolean;
48
+
49
+ /**
50
+ * Wait for user profile before sending events (advanced, default: false).
51
+ */
52
+ waitForProfile?: boolean;
53
+
54
+ // --- Tracking Features ---
55
+
56
+ /**
57
+ * Automatically track screen/page views (default: true).
58
+ */
59
+ trackScreenViews?: boolean;
60
+
61
+ /**
62
+ * Track hash changes in the URL (default: false).
63
+ */
64
+ trackHashChanges?: boolean;
65
+
66
+ /**
67
+ * Track data-* attributes on elements (default: false).
68
+ */
69
+ trackAttributes?: boolean;
70
+
71
+ /**
72
+ * Track clicks on outgoing links (default: false).
73
+ */
74
+ trackOutgoingLinks?: boolean;
75
+
76
+ /**
77
+ * Track user sessions (default: false).
78
+ */
79
+ trackSessions?: boolean;
80
+
81
+ /**
82
+ * Track page performance metrics (default: true).
83
+ */
84
+ trackPerformance?: boolean;
85
+
86
+ /**
87
+ * Track Web Vitals metrics (default: true).
88
+ */
89
+ trackWebVitals?: boolean;
90
+
91
+ /**
92
+ * Track user engagement metrics (default: false).
93
+ */
94
+ trackEngagement?: boolean;
95
+
96
+ /**
97
+ * Track scroll depth (default: false).
98
+ */
99
+ trackScrollDepth?: boolean;
100
+
101
+ /**
102
+ * Track exit intent (default: false).
103
+ */
104
+ trackExitIntent?: boolean;
105
+
106
+ /**
107
+ * Track user interactions (default: false).
108
+ */
109
+ trackInteractions?: boolean;
110
+
111
+ /**
112
+ * Track JavaScript errors (default: true).
113
+ */
114
+ trackErrors?: boolean;
115
+
116
+ /**
117
+ * Track bounce rate (default: false).
118
+ */
119
+ trackBounceRate?: boolean;
120
+
121
+ // --- Advanced/Performance ---
122
+
123
+ /**
124
+ * Sampling rate for events (0.0 to 1.0, default: 1.0).
125
+ * Example: 0.5 = 50% of events sent.
126
+ */
127
+ samplingRate?: number;
128
+
129
+ /**
130
+ * Enable retries for failed requests (default: true).
131
+ */
132
+ enableRetries?: boolean;
133
+
134
+ /**
135
+ * Maximum number of retries for failed requests (default: 3).
136
+ * Only used if enableRetries is true.
137
+ */
138
+ maxRetries?: number;
139
+
140
+ /**
141
+ * Initial retry delay in milliseconds (default: 500).
142
+ * Only used if enableRetries is true.
143
+ */
144
+ initialRetryDelay?: number;
145
+
146
+ /**
147
+ * Enable event batching (default: true).
148
+ */
149
+ enableBatching?: boolean;
150
+
151
+ /**
152
+ * Number of events to batch before sending (default: 20).
153
+ * Only used if enableBatching is true.
154
+ * Min: 1, Max: 50
155
+ */
156
+ batchSize?: number;
157
+
158
+ /**
159
+ * Batch timeout in milliseconds (default: 5000).
160
+ * Only used if enableBatching is true.
161
+ * Min: 100, Max: 30000
162
+ */
163
+ batchTimeout?: number;
164
+ }
165
+
166
+ /**
167
+ * Event properties that can be attached to any event
168
+ */
169
+ export interface EventProperties {
170
+ /** Custom properties for the event */
171
+ [key: string]: string | number | boolean | null | undefined | EventProperties;
172
+ }
173
+
package/tsconfig.json ADDED
@@ -0,0 +1,19 @@
1
+ {
2
+ "compilerOptions": {
3
+ "target": "es2018",
4
+ "module": "esnext",
5
+ "lib": ["dom", "esnext"],
6
+ "declaration": true,
7
+ "declarationDir": "dist",
8
+ "strict": true,
9
+ "moduleResolution": "node",
10
+ "esModuleInterop": true,
11
+ "skipLibCheck": true,
12
+ "forceConsistentCasingInFileNames": true,
13
+ "outDir": "dist",
14
+ "rootDir": "src",
15
+ "jsx": "react-jsx"
16
+ },
17
+ "include": ["src/**/*"],
18
+ "exclude": ["node_modules", "dist", "**/*.test.ts"]
19
+ }