@databuddy/sdk 2.3.2 → 2.3.21
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/ai/vercel/index.d.mts +16 -5
- package/dist/ai/vercel/index.d.ts +16 -5
- package/dist/ai/vercel/index.mjs +12 -4
- package/dist/core/index.d.mts +3 -225
- package/dist/core/index.d.ts +3 -225
- package/dist/core/index.mjs +26 -3
- package/dist/node/index.mjs +1 -1
- package/dist/react/index.d.mts +2 -1
- package/dist/react/index.d.ts +2 -1
- package/dist/react/index.mjs +5 -4
- package/dist/shared/@databuddy/{sdk.C9b3SVYK.d.mts → sdk.BsF1xr6_.d.mts} +224 -1
- package/dist/shared/@databuddy/{sdk.C9b3SVYK.d.ts → sdk.BsF1xr6_.d.ts} +224 -1
- package/dist/shared/@databuddy/{sdk.F8Xt1uF7.mjs → sdk.C8vEu9Y4.mjs} +1 -1
- package/dist/shared/@databuddy/{sdk.Du7SE7-M.mjs → sdk.D0dyEsAb.mjs} +5 -2
- package/dist/shared/@databuddy/{sdk.3kaCzyfu.mjs → sdk.DCKr2Zpd.mjs} +4 -1
- package/dist/vue/index.mjs +3 -3
- package/package.json +1 -1
- package/dist/shared/@databuddy/sdk.BUsPV0LH.mjs +0 -25
|
@@ -57,8 +57,8 @@ type Transport = (call: AICall) => Promise<void> | void;
|
|
|
57
57
|
*/
|
|
58
58
|
interface DatabuddyLLMOptions {
|
|
59
59
|
/**
|
|
60
|
-
* API endpoint for sending logs
|
|
61
|
-
* @default process.env.
|
|
60
|
+
* API endpoint for sending logs (should include /llm path)
|
|
61
|
+
* @default process.env.DATABUDDY_API_URL or 'https://basket.databuddy.cc/llm'
|
|
62
62
|
*/
|
|
63
63
|
apiUrl?: string;
|
|
64
64
|
/**
|
|
@@ -66,6 +66,11 @@ interface DatabuddyLLMOptions {
|
|
|
66
66
|
* @default process.env.DATABUDDY_API_KEY
|
|
67
67
|
*/
|
|
68
68
|
apiKey?: string;
|
|
69
|
+
/**
|
|
70
|
+
* Client/Website ID for tracking
|
|
71
|
+
* @default process.env.DATABUDDY_CLIENT_ID
|
|
72
|
+
*/
|
|
73
|
+
clientId?: string;
|
|
69
74
|
/**
|
|
70
75
|
* Custom transport function to send log entries
|
|
71
76
|
* If provided, overrides default HTTP transport
|
|
@@ -116,8 +121,14 @@ interface TrackOptions {
|
|
|
116
121
|
* ```ts
|
|
117
122
|
* import { databuddyLLM } from "@databuddy/sdk/ai/vercel";
|
|
118
123
|
*
|
|
124
|
+
* // Use default endpoint (basket.databuddy.cc/llm)
|
|
125
|
+
* const { track } = databuddyLLM({
|
|
126
|
+
* apiKey: "your-api-key",
|
|
127
|
+
* });
|
|
128
|
+
*
|
|
129
|
+
* // Or override with custom endpoint
|
|
119
130
|
* const { track } = databuddyLLM({
|
|
120
|
-
* apiUrl: "https://
|
|
131
|
+
* apiUrl: "https://custom.example.com/llm",
|
|
121
132
|
* apiKey: "your-api-key",
|
|
122
133
|
* });
|
|
123
134
|
*
|
|
@@ -141,11 +152,11 @@ declare const databuddyLLM: (options?: DatabuddyLLMOptions) => {
|
|
|
141
152
|
* import { databuddyLLM, httpTransport } from "@databuddy/sdk/ai/vercel";
|
|
142
153
|
*
|
|
143
154
|
* const { track } = databuddyLLM({
|
|
144
|
-
* transport: httpTransport("https://api.example.com/ai-logs"),
|
|
155
|
+
* transport: httpTransport("https://api.example.com/ai-logs", "client-id", "api-key"),
|
|
145
156
|
* });
|
|
146
157
|
* ```
|
|
147
158
|
*/
|
|
148
|
-
declare const httpTransport: (url: string, apiKey?: string) => Transport;
|
|
159
|
+
declare const httpTransport: (url: string, clientId?: string, apiKey?: string) => Transport;
|
|
149
160
|
|
|
150
161
|
export { databuddyLLM, httpTransport };
|
|
151
162
|
export type { AICall, AIError, DatabuddyLLMOptions, TokenCost, TokenUsage, ToolCallInfo, TrackOptions, Transport };
|
|
@@ -57,8 +57,8 @@ type Transport = (call: AICall) => Promise<void> | void;
|
|
|
57
57
|
*/
|
|
58
58
|
interface DatabuddyLLMOptions {
|
|
59
59
|
/**
|
|
60
|
-
* API endpoint for sending logs
|
|
61
|
-
* @default process.env.
|
|
60
|
+
* API endpoint for sending logs (should include /llm path)
|
|
61
|
+
* @default process.env.DATABUDDY_API_URL or 'https://basket.databuddy.cc/llm'
|
|
62
62
|
*/
|
|
63
63
|
apiUrl?: string;
|
|
64
64
|
/**
|
|
@@ -66,6 +66,11 @@ interface DatabuddyLLMOptions {
|
|
|
66
66
|
* @default process.env.DATABUDDY_API_KEY
|
|
67
67
|
*/
|
|
68
68
|
apiKey?: string;
|
|
69
|
+
/**
|
|
70
|
+
* Client/Website ID for tracking
|
|
71
|
+
* @default process.env.DATABUDDY_CLIENT_ID
|
|
72
|
+
*/
|
|
73
|
+
clientId?: string;
|
|
69
74
|
/**
|
|
70
75
|
* Custom transport function to send log entries
|
|
71
76
|
* If provided, overrides default HTTP transport
|
|
@@ -116,8 +121,14 @@ interface TrackOptions {
|
|
|
116
121
|
* ```ts
|
|
117
122
|
* import { databuddyLLM } from "@databuddy/sdk/ai/vercel";
|
|
118
123
|
*
|
|
124
|
+
* // Use default endpoint (basket.databuddy.cc/llm)
|
|
125
|
+
* const { track } = databuddyLLM({
|
|
126
|
+
* apiKey: "your-api-key",
|
|
127
|
+
* });
|
|
128
|
+
*
|
|
129
|
+
* // Or override with custom endpoint
|
|
119
130
|
* const { track } = databuddyLLM({
|
|
120
|
-
* apiUrl: "https://
|
|
131
|
+
* apiUrl: "https://custom.example.com/llm",
|
|
121
132
|
* apiKey: "your-api-key",
|
|
122
133
|
* });
|
|
123
134
|
*
|
|
@@ -141,11 +152,11 @@ declare const databuddyLLM: (options?: DatabuddyLLMOptions) => {
|
|
|
141
152
|
* import { databuddyLLM, httpTransport } from "@databuddy/sdk/ai/vercel";
|
|
142
153
|
*
|
|
143
154
|
* const { track } = databuddyLLM({
|
|
144
|
-
* transport: httpTransport("https://api.example.com/ai-logs"),
|
|
155
|
+
* transport: httpTransport("https://api.example.com/ai-logs", "client-id", "api-key"),
|
|
145
156
|
* });
|
|
146
157
|
* ```
|
|
147
158
|
*/
|
|
148
|
-
declare const httpTransport: (url: string, apiKey?: string) => Transport;
|
|
159
|
+
declare const httpTransport: (url: string, clientId?: string, apiKey?: string) => Transport;
|
|
149
160
|
|
|
150
161
|
export { databuddyLLM, httpTransport };
|
|
151
162
|
export type { AICall, AIError, DatabuddyLLMOptions, TokenCost, TokenUsage, ToolCallInfo, TrackOptions, Transport };
|
package/dist/ai/vercel/index.mjs
CHANGED
|
@@ -34,7 +34,7 @@ const computeCosts = async (modelId, provider, usage) => {
|
|
|
34
34
|
return {};
|
|
35
35
|
}
|
|
36
36
|
};
|
|
37
|
-
const createDefaultTransport = (apiUrl, apiKey) => {
|
|
37
|
+
const createDefaultTransport = (apiUrl, clientId, apiKey) => {
|
|
38
38
|
return async (call) => {
|
|
39
39
|
const headers = {
|
|
40
40
|
"Content-Type": "application/json"
|
|
@@ -42,6 +42,9 @@ const createDefaultTransport = (apiUrl, apiKey) => {
|
|
|
42
42
|
if (apiKey) {
|
|
43
43
|
headers.Authorization = `Bearer ${apiKey}`;
|
|
44
44
|
}
|
|
45
|
+
if (clientId) {
|
|
46
|
+
headers["databuddy-client-id"] = clientId;
|
|
47
|
+
}
|
|
45
48
|
const response = await fetch(apiUrl, {
|
|
46
49
|
method: "POST",
|
|
47
50
|
headers,
|
|
@@ -180,6 +183,7 @@ const databuddyLLM = (options = {}) => {
|
|
|
180
183
|
const {
|
|
181
184
|
apiUrl,
|
|
182
185
|
apiKey,
|
|
186
|
+
clientId,
|
|
183
187
|
transport: customTransport,
|
|
184
188
|
computeCosts: defaultComputeCosts = true,
|
|
185
189
|
onSuccess: defaultOnSuccess,
|
|
@@ -189,9 +193,10 @@ const databuddyLLM = (options = {}) => {
|
|
|
189
193
|
if (customTransport) {
|
|
190
194
|
transport = customTransport;
|
|
191
195
|
} else {
|
|
192
|
-
const endpoint = apiUrl ??
|
|
196
|
+
const endpoint = apiUrl ?? process.env.DATABUDDY_API_URL ?? "https://basket.databuddy.cc/llm";
|
|
197
|
+
const client = clientId ?? process.env.DATABUDDY_CLIENT_ID;
|
|
193
198
|
const key = apiKey ?? process.env.DATABUDDY_API_KEY;
|
|
194
|
-
transport = createDefaultTransport(endpoint, key);
|
|
199
|
+
transport = createDefaultTransport(endpoint, client, key);
|
|
195
200
|
}
|
|
196
201
|
const track = (model, trackOptions = {}) => {
|
|
197
202
|
return wrapLanguageModel({
|
|
@@ -206,7 +211,7 @@ const databuddyLLM = (options = {}) => {
|
|
|
206
211
|
};
|
|
207
212
|
return { track };
|
|
208
213
|
};
|
|
209
|
-
const httpTransport = (url, apiKey) => {
|
|
214
|
+
const httpTransport = (url, clientId, apiKey) => {
|
|
210
215
|
return async (call) => {
|
|
211
216
|
const headers = {
|
|
212
217
|
"Content-Type": "application/json"
|
|
@@ -214,6 +219,9 @@ const httpTransport = (url, apiKey) => {
|
|
|
214
219
|
if (apiKey) {
|
|
215
220
|
headers.Authorization = `Bearer ${apiKey}`;
|
|
216
221
|
}
|
|
222
|
+
if (clientId) {
|
|
223
|
+
headers["databuddy-client-id"] = clientId;
|
|
224
|
+
}
|
|
217
225
|
const response = await fetch(url, {
|
|
218
226
|
method: "POST",
|
|
219
227
|
headers,
|
package/dist/core/index.d.mts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { D as DatabuddyConfig
|
|
2
|
-
export { B as BaseEventProperties,
|
|
1
|
+
import { D as DatabuddyConfig } from '../shared/@databuddy/sdk.BsF1xr6_.mjs';
|
|
2
|
+
export { B as BaseEventProperties, n as DataAttributes, m as DatabuddyTracker, l as EventName, E as EventProperties, k as EventTypeMap, P as PropertiesForEvent, S as ScreenViewFunction, o as SetGlobalPropertiesFunction, T as TrackFunction, c as clear, f as flush, d as getAnonymousId, e as getSessionId, g as getTracker, h as getTrackingIds, j as getTrackingParams, i as isTrackerAvailable, t as track, a as trackCustomEvent, b as trackError } from '../shared/@databuddy/sdk.BsF1xr6_.mjs';
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
5
|
* Auto-detect Databuddy client ID from environment variables
|
|
@@ -10,226 +10,4 @@ declare function detectClientId(providedClientId?: string): string | undefined;
|
|
|
10
10
|
declare function isScriptInjected(): boolean;
|
|
11
11
|
declare function createScript({ scriptUrl, sdkVersion, clientSecret, filter, debug, ...props }: DatabuddyConfig): HTMLScriptElement;
|
|
12
12
|
|
|
13
|
-
|
|
14
|
-
* Checks if the Databuddy tracker script has loaded and is available.
|
|
15
|
-
* Use this before calling tracking functions in conditional scenarios.
|
|
16
|
-
*
|
|
17
|
-
* @returns `true` if tracker is available, `false` if not loaded or on server
|
|
18
|
-
*
|
|
19
|
-
* @example
|
|
20
|
-
* ```ts
|
|
21
|
-
* import { isTrackerAvailable, track } from "@databuddy/sdk";
|
|
22
|
-
*
|
|
23
|
-
* if (isTrackerAvailable()) {
|
|
24
|
-
* track("feature_used", { feature: "export" });
|
|
25
|
-
* }
|
|
26
|
-
* ```
|
|
27
|
-
*/
|
|
28
|
-
declare function isTrackerAvailable(): boolean;
|
|
29
|
-
/**
|
|
30
|
-
* Returns the raw Databuddy tracker instance for advanced use cases.
|
|
31
|
-
* Prefer using the exported functions (`track`, `flush`, etc.) instead.
|
|
32
|
-
*
|
|
33
|
-
* @returns Tracker instance or `null` if not available
|
|
34
|
-
*
|
|
35
|
-
* @example
|
|
36
|
-
* ```ts
|
|
37
|
-
* import { getTracker, getAnonymousId, getSessionId } from "@databuddy/sdk";
|
|
38
|
-
*
|
|
39
|
-
* const tracker = getTracker();
|
|
40
|
-
* if (tracker) {
|
|
41
|
-
* // Access tracker methods
|
|
42
|
-
* tracker.track("event", { prop: "value" });
|
|
43
|
-
*
|
|
44
|
-
* // Get IDs using dedicated functions
|
|
45
|
-
* const anonId = getAnonymousId();
|
|
46
|
-
* const sessionId = getSessionId();
|
|
47
|
-
* }
|
|
48
|
-
* ```
|
|
49
|
-
*/
|
|
50
|
-
declare function getTracker(): DatabuddyTracker | null;
|
|
51
|
-
/**
|
|
52
|
-
* Tracks a custom event with optional properties.
|
|
53
|
-
* Events are batched and sent efficiently to minimize network overhead.
|
|
54
|
-
* Safe to call on server (no-op) or before tracker loads.
|
|
55
|
-
*
|
|
56
|
-
* @param name - Event name (e.g., "button_click", "purchase", "signup")
|
|
57
|
-
* @param properties - Key-value pairs of event data
|
|
58
|
-
*
|
|
59
|
-
* @example
|
|
60
|
-
* ```ts
|
|
61
|
-
* import { track } from "@databuddy/sdk";
|
|
62
|
-
*
|
|
63
|
-
* // Simple event
|
|
64
|
-
* track("signup_started");
|
|
65
|
-
*
|
|
66
|
-
* // Event with properties
|
|
67
|
-
* track("item_purchased", {
|
|
68
|
-
* itemId: "sku-123",
|
|
69
|
-
* price: 29.99,
|
|
70
|
-
* currency: "USD"
|
|
71
|
-
* });
|
|
72
|
-
*
|
|
73
|
-
* // In a React component
|
|
74
|
-
* function CheckoutButton() {
|
|
75
|
-
* return (
|
|
76
|
-
* <button onClick={() => track("checkout_clicked", { cartSize: 3 })}>
|
|
77
|
-
* Checkout
|
|
78
|
-
* </button>
|
|
79
|
-
* );
|
|
80
|
-
* }
|
|
81
|
-
* ```
|
|
82
|
-
*/
|
|
83
|
-
declare function track(name: string, properties?: Record<string, unknown>): void;
|
|
84
|
-
/** @deprecated Use `track()` instead. Will be removed in v3.0. */
|
|
85
|
-
declare function trackCustomEvent(name: string, properties?: Record<string, unknown>): void;
|
|
86
|
-
/**
|
|
87
|
-
* Clears the current user session and generates new anonymous/session IDs.
|
|
88
|
-
* Use after logout to ensure the next user gets a fresh identity.
|
|
89
|
-
*
|
|
90
|
-
* @example
|
|
91
|
-
* ```ts
|
|
92
|
-
* import { clear } from "@databuddy/sdk";
|
|
93
|
-
*
|
|
94
|
-
* async function handleLogout() {
|
|
95
|
-
* await signOut();
|
|
96
|
-
* clear(); // Reset tracking identity
|
|
97
|
-
* router.push("/login");
|
|
98
|
-
* }
|
|
99
|
-
* ```
|
|
100
|
-
*/
|
|
101
|
-
declare function clear(): void;
|
|
102
|
-
/**
|
|
103
|
-
* Forces all queued events to be sent immediately.
|
|
104
|
-
* Useful before navigation or when you need to ensure events are captured.
|
|
105
|
-
*
|
|
106
|
-
* @example
|
|
107
|
-
* ```ts
|
|
108
|
-
* import { track, flush } from "@databuddy/sdk";
|
|
109
|
-
*
|
|
110
|
-
* function handleExternalLink(url: string) {
|
|
111
|
-
* track("external_link_clicked", { url });
|
|
112
|
-
* flush(); // Ensure event is sent before leaving
|
|
113
|
-
* window.location.href = url;
|
|
114
|
-
* }
|
|
115
|
-
* ```
|
|
116
|
-
*/
|
|
117
|
-
declare function flush(): void;
|
|
118
|
-
/**
|
|
119
|
-
* Tracks an error event. Convenience wrapper around `track("error", ...)`.
|
|
120
|
-
*
|
|
121
|
-
* @param message - Error message
|
|
122
|
-
* @param properties - Additional error context (filename, line number, stack trace)
|
|
123
|
-
*
|
|
124
|
-
* @example
|
|
125
|
-
* ```ts
|
|
126
|
-
* import { trackError } from "@databuddy/sdk";
|
|
127
|
-
*
|
|
128
|
-
* try {
|
|
129
|
-
* await riskyOperation();
|
|
130
|
-
* } catch (error) {
|
|
131
|
-
* trackError(error.message, {
|
|
132
|
-
* stack: error.stack,
|
|
133
|
-
* error_type: error.name,
|
|
134
|
-
* context: "checkout_flow"
|
|
135
|
-
* });
|
|
136
|
-
* }
|
|
137
|
-
* ```
|
|
138
|
-
*/
|
|
139
|
-
declare function trackError(message: string, properties?: {
|
|
140
|
-
filename?: string;
|
|
141
|
-
lineno?: number;
|
|
142
|
-
colno?: number;
|
|
143
|
-
stack?: string;
|
|
144
|
-
error_type?: string;
|
|
145
|
-
[key: string]: string | number | boolean | null | undefined;
|
|
146
|
-
}): void;
|
|
147
|
-
/**
|
|
148
|
-
* Gets the anonymous user ID. Persists across sessions via localStorage.
|
|
149
|
-
* Useful for server-side identification or cross-domain tracking.
|
|
150
|
-
*
|
|
151
|
-
* @param urlParams - Optional URLSearchParams to check for `anonId` param (highest priority)
|
|
152
|
-
* @returns Anonymous ID or `null` if unavailable
|
|
153
|
-
*
|
|
154
|
-
* Priority: URL params → tracker instance → localStorage
|
|
155
|
-
*
|
|
156
|
-
* @example
|
|
157
|
-
* ```ts
|
|
158
|
-
* import { getAnonymousId } from "@databuddy/sdk";
|
|
159
|
-
*
|
|
160
|
-
* // Get from tracker
|
|
161
|
-
* const anonId = getAnonymousId();
|
|
162
|
-
*
|
|
163
|
-
* // Check URL params first (for cross-domain tracking)
|
|
164
|
-
* const params = new URLSearchParams(window.location.search);
|
|
165
|
-
* const anonId = getAnonymousId(params);
|
|
166
|
-
*
|
|
167
|
-
* // Pass to server
|
|
168
|
-
* await fetch("/api/identify", {
|
|
169
|
-
* body: JSON.stringify({ anonId })
|
|
170
|
-
* });
|
|
171
|
-
* ```
|
|
172
|
-
*/
|
|
173
|
-
declare function getAnonymousId(urlParams?: URLSearchParams): string | null;
|
|
174
|
-
/**
|
|
175
|
-
* Gets the current session ID. Resets after 30 min of inactivity.
|
|
176
|
-
* Useful for correlating events within a single browsing session.
|
|
177
|
-
*
|
|
178
|
-
* @param urlParams - Optional URLSearchParams to check for `sessionId` param (highest priority)
|
|
179
|
-
* @returns Session ID or `null` if unavailable
|
|
180
|
-
*
|
|
181
|
-
* Priority: URL params → tracker instance → sessionStorage
|
|
182
|
-
*
|
|
183
|
-
* @example
|
|
184
|
-
* ```ts
|
|
185
|
-
* import { getSessionId } from "@databuddy/sdk";
|
|
186
|
-
*
|
|
187
|
-
* const sessionId = getSessionId();
|
|
188
|
-
* console.log("Current session:", sessionId);
|
|
189
|
-
* ```
|
|
190
|
-
*/
|
|
191
|
-
declare function getSessionId(urlParams?: URLSearchParams): string | null;
|
|
192
|
-
/**
|
|
193
|
-
* Gets both anonymous ID and session ID in a single call.
|
|
194
|
-
*
|
|
195
|
-
* @param urlParams - Optional URLSearchParams to check for tracking params
|
|
196
|
-
* @returns Object with `anonId` and `sessionId` (either may be null)
|
|
197
|
-
*
|
|
198
|
-
* @example
|
|
199
|
-
* ```ts
|
|
200
|
-
* import { getTrackingIds } from "@databuddy/sdk";
|
|
201
|
-
*
|
|
202
|
-
* const { anonId, sessionId } = getTrackingIds();
|
|
203
|
-
*
|
|
204
|
-
* // Send to your backend
|
|
205
|
-
* await api.identify({ anonId, sessionId, userId: user.id });
|
|
206
|
-
* ```
|
|
207
|
-
*/
|
|
208
|
-
declare function getTrackingIds(urlParams?: URLSearchParams): {
|
|
209
|
-
anonId: string | null;
|
|
210
|
-
sessionId: string | null;
|
|
211
|
-
};
|
|
212
|
-
/**
|
|
213
|
-
* Returns tracking IDs as a URL query string for cross-domain tracking.
|
|
214
|
-
* Append to URLs when linking to other domains you own.
|
|
215
|
-
*
|
|
216
|
-
* @param urlParams - Optional URLSearchParams to preserve existing params
|
|
217
|
-
* @returns Query string like `"anonId=xxx&sessionId=yyy"` or empty string
|
|
218
|
-
*
|
|
219
|
-
* @example
|
|
220
|
-
* ```ts
|
|
221
|
-
* import { getTrackingParams } from "@databuddy/sdk";
|
|
222
|
-
*
|
|
223
|
-
* // Link to subdomain with tracking continuity
|
|
224
|
-
* const params = getTrackingParams();
|
|
225
|
-
* const url = `https://app.example.com/dashboard${params ? `?${params}` : ""}`;
|
|
226
|
-
*
|
|
227
|
-
* // In a component
|
|
228
|
-
* <a href={`https://shop.example.com?${getTrackingParams()}`}>
|
|
229
|
-
* Visit Shop
|
|
230
|
-
* </a>
|
|
231
|
-
* ```
|
|
232
|
-
*/
|
|
233
|
-
declare function getTrackingParams(urlParams?: URLSearchParams): string;
|
|
234
|
-
|
|
235
|
-
export { DatabuddyConfig, DatabuddyTracker, clear, createScript, detectClientId, flush, getAnonymousId, getSessionId, getTracker, getTrackingIds, getTrackingParams, isScriptInjected, isTrackerAvailable, track, trackCustomEvent, trackError };
|
|
13
|
+
export { DatabuddyConfig, createScript, detectClientId, isScriptInjected };
|
package/dist/core/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { D as DatabuddyConfig
|
|
2
|
-
export { B as BaseEventProperties,
|
|
1
|
+
import { D as DatabuddyConfig } from '../shared/@databuddy/sdk.BsF1xr6_.js';
|
|
2
|
+
export { B as BaseEventProperties, n as DataAttributes, m as DatabuddyTracker, l as EventName, E as EventProperties, k as EventTypeMap, P as PropertiesForEvent, S as ScreenViewFunction, o as SetGlobalPropertiesFunction, T as TrackFunction, c as clear, f as flush, d as getAnonymousId, e as getSessionId, g as getTracker, h as getTrackingIds, j as getTrackingParams, i as isTrackerAvailable, t as track, a as trackCustomEvent, b as trackError } from '../shared/@databuddy/sdk.BsF1xr6_.js';
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
5
|
* Auto-detect Databuddy client ID from environment variables
|
|
@@ -10,226 +10,4 @@ declare function detectClientId(providedClientId?: string): string | undefined;
|
|
|
10
10
|
declare function isScriptInjected(): boolean;
|
|
11
11
|
declare function createScript({ scriptUrl, sdkVersion, clientSecret, filter, debug, ...props }: DatabuddyConfig): HTMLScriptElement;
|
|
12
12
|
|
|
13
|
-
|
|
14
|
-
* Checks if the Databuddy tracker script has loaded and is available.
|
|
15
|
-
* Use this before calling tracking functions in conditional scenarios.
|
|
16
|
-
*
|
|
17
|
-
* @returns `true` if tracker is available, `false` if not loaded or on server
|
|
18
|
-
*
|
|
19
|
-
* @example
|
|
20
|
-
* ```ts
|
|
21
|
-
* import { isTrackerAvailable, track } from "@databuddy/sdk";
|
|
22
|
-
*
|
|
23
|
-
* if (isTrackerAvailable()) {
|
|
24
|
-
* track("feature_used", { feature: "export" });
|
|
25
|
-
* }
|
|
26
|
-
* ```
|
|
27
|
-
*/
|
|
28
|
-
declare function isTrackerAvailable(): boolean;
|
|
29
|
-
/**
|
|
30
|
-
* Returns the raw Databuddy tracker instance for advanced use cases.
|
|
31
|
-
* Prefer using the exported functions (`track`, `flush`, etc.) instead.
|
|
32
|
-
*
|
|
33
|
-
* @returns Tracker instance or `null` if not available
|
|
34
|
-
*
|
|
35
|
-
* @example
|
|
36
|
-
* ```ts
|
|
37
|
-
* import { getTracker, getAnonymousId, getSessionId } from "@databuddy/sdk";
|
|
38
|
-
*
|
|
39
|
-
* const tracker = getTracker();
|
|
40
|
-
* if (tracker) {
|
|
41
|
-
* // Access tracker methods
|
|
42
|
-
* tracker.track("event", { prop: "value" });
|
|
43
|
-
*
|
|
44
|
-
* // Get IDs using dedicated functions
|
|
45
|
-
* const anonId = getAnonymousId();
|
|
46
|
-
* const sessionId = getSessionId();
|
|
47
|
-
* }
|
|
48
|
-
* ```
|
|
49
|
-
*/
|
|
50
|
-
declare function getTracker(): DatabuddyTracker | null;
|
|
51
|
-
/**
|
|
52
|
-
* Tracks a custom event with optional properties.
|
|
53
|
-
* Events are batched and sent efficiently to minimize network overhead.
|
|
54
|
-
* Safe to call on server (no-op) or before tracker loads.
|
|
55
|
-
*
|
|
56
|
-
* @param name - Event name (e.g., "button_click", "purchase", "signup")
|
|
57
|
-
* @param properties - Key-value pairs of event data
|
|
58
|
-
*
|
|
59
|
-
* @example
|
|
60
|
-
* ```ts
|
|
61
|
-
* import { track } from "@databuddy/sdk";
|
|
62
|
-
*
|
|
63
|
-
* // Simple event
|
|
64
|
-
* track("signup_started");
|
|
65
|
-
*
|
|
66
|
-
* // Event with properties
|
|
67
|
-
* track("item_purchased", {
|
|
68
|
-
* itemId: "sku-123",
|
|
69
|
-
* price: 29.99,
|
|
70
|
-
* currency: "USD"
|
|
71
|
-
* });
|
|
72
|
-
*
|
|
73
|
-
* // In a React component
|
|
74
|
-
* function CheckoutButton() {
|
|
75
|
-
* return (
|
|
76
|
-
* <button onClick={() => track("checkout_clicked", { cartSize: 3 })}>
|
|
77
|
-
* Checkout
|
|
78
|
-
* </button>
|
|
79
|
-
* );
|
|
80
|
-
* }
|
|
81
|
-
* ```
|
|
82
|
-
*/
|
|
83
|
-
declare function track(name: string, properties?: Record<string, unknown>): void;
|
|
84
|
-
/** @deprecated Use `track()` instead. Will be removed in v3.0. */
|
|
85
|
-
declare function trackCustomEvent(name: string, properties?: Record<string, unknown>): void;
|
|
86
|
-
/**
|
|
87
|
-
* Clears the current user session and generates new anonymous/session IDs.
|
|
88
|
-
* Use after logout to ensure the next user gets a fresh identity.
|
|
89
|
-
*
|
|
90
|
-
* @example
|
|
91
|
-
* ```ts
|
|
92
|
-
* import { clear } from "@databuddy/sdk";
|
|
93
|
-
*
|
|
94
|
-
* async function handleLogout() {
|
|
95
|
-
* await signOut();
|
|
96
|
-
* clear(); // Reset tracking identity
|
|
97
|
-
* router.push("/login");
|
|
98
|
-
* }
|
|
99
|
-
* ```
|
|
100
|
-
*/
|
|
101
|
-
declare function clear(): void;
|
|
102
|
-
/**
|
|
103
|
-
* Forces all queued events to be sent immediately.
|
|
104
|
-
* Useful before navigation or when you need to ensure events are captured.
|
|
105
|
-
*
|
|
106
|
-
* @example
|
|
107
|
-
* ```ts
|
|
108
|
-
* import { track, flush } from "@databuddy/sdk";
|
|
109
|
-
*
|
|
110
|
-
* function handleExternalLink(url: string) {
|
|
111
|
-
* track("external_link_clicked", { url });
|
|
112
|
-
* flush(); // Ensure event is sent before leaving
|
|
113
|
-
* window.location.href = url;
|
|
114
|
-
* }
|
|
115
|
-
* ```
|
|
116
|
-
*/
|
|
117
|
-
declare function flush(): void;
|
|
118
|
-
/**
|
|
119
|
-
* Tracks an error event. Convenience wrapper around `track("error", ...)`.
|
|
120
|
-
*
|
|
121
|
-
* @param message - Error message
|
|
122
|
-
* @param properties - Additional error context (filename, line number, stack trace)
|
|
123
|
-
*
|
|
124
|
-
* @example
|
|
125
|
-
* ```ts
|
|
126
|
-
* import { trackError } from "@databuddy/sdk";
|
|
127
|
-
*
|
|
128
|
-
* try {
|
|
129
|
-
* await riskyOperation();
|
|
130
|
-
* } catch (error) {
|
|
131
|
-
* trackError(error.message, {
|
|
132
|
-
* stack: error.stack,
|
|
133
|
-
* error_type: error.name,
|
|
134
|
-
* context: "checkout_flow"
|
|
135
|
-
* });
|
|
136
|
-
* }
|
|
137
|
-
* ```
|
|
138
|
-
*/
|
|
139
|
-
declare function trackError(message: string, properties?: {
|
|
140
|
-
filename?: string;
|
|
141
|
-
lineno?: number;
|
|
142
|
-
colno?: number;
|
|
143
|
-
stack?: string;
|
|
144
|
-
error_type?: string;
|
|
145
|
-
[key: string]: string | number | boolean | null | undefined;
|
|
146
|
-
}): void;
|
|
147
|
-
/**
|
|
148
|
-
* Gets the anonymous user ID. Persists across sessions via localStorage.
|
|
149
|
-
* Useful for server-side identification or cross-domain tracking.
|
|
150
|
-
*
|
|
151
|
-
* @param urlParams - Optional URLSearchParams to check for `anonId` param (highest priority)
|
|
152
|
-
* @returns Anonymous ID or `null` if unavailable
|
|
153
|
-
*
|
|
154
|
-
* Priority: URL params → tracker instance → localStorage
|
|
155
|
-
*
|
|
156
|
-
* @example
|
|
157
|
-
* ```ts
|
|
158
|
-
* import { getAnonymousId } from "@databuddy/sdk";
|
|
159
|
-
*
|
|
160
|
-
* // Get from tracker
|
|
161
|
-
* const anonId = getAnonymousId();
|
|
162
|
-
*
|
|
163
|
-
* // Check URL params first (for cross-domain tracking)
|
|
164
|
-
* const params = new URLSearchParams(window.location.search);
|
|
165
|
-
* const anonId = getAnonymousId(params);
|
|
166
|
-
*
|
|
167
|
-
* // Pass to server
|
|
168
|
-
* await fetch("/api/identify", {
|
|
169
|
-
* body: JSON.stringify({ anonId })
|
|
170
|
-
* });
|
|
171
|
-
* ```
|
|
172
|
-
*/
|
|
173
|
-
declare function getAnonymousId(urlParams?: URLSearchParams): string | null;
|
|
174
|
-
/**
|
|
175
|
-
* Gets the current session ID. Resets after 30 min of inactivity.
|
|
176
|
-
* Useful for correlating events within a single browsing session.
|
|
177
|
-
*
|
|
178
|
-
* @param urlParams - Optional URLSearchParams to check for `sessionId` param (highest priority)
|
|
179
|
-
* @returns Session ID or `null` if unavailable
|
|
180
|
-
*
|
|
181
|
-
* Priority: URL params → tracker instance → sessionStorage
|
|
182
|
-
*
|
|
183
|
-
* @example
|
|
184
|
-
* ```ts
|
|
185
|
-
* import { getSessionId } from "@databuddy/sdk";
|
|
186
|
-
*
|
|
187
|
-
* const sessionId = getSessionId();
|
|
188
|
-
* console.log("Current session:", sessionId);
|
|
189
|
-
* ```
|
|
190
|
-
*/
|
|
191
|
-
declare function getSessionId(urlParams?: URLSearchParams): string | null;
|
|
192
|
-
/**
|
|
193
|
-
* Gets both anonymous ID and session ID in a single call.
|
|
194
|
-
*
|
|
195
|
-
* @param urlParams - Optional URLSearchParams to check for tracking params
|
|
196
|
-
* @returns Object with `anonId` and `sessionId` (either may be null)
|
|
197
|
-
*
|
|
198
|
-
* @example
|
|
199
|
-
* ```ts
|
|
200
|
-
* import { getTrackingIds } from "@databuddy/sdk";
|
|
201
|
-
*
|
|
202
|
-
* const { anonId, sessionId } = getTrackingIds();
|
|
203
|
-
*
|
|
204
|
-
* // Send to your backend
|
|
205
|
-
* await api.identify({ anonId, sessionId, userId: user.id });
|
|
206
|
-
* ```
|
|
207
|
-
*/
|
|
208
|
-
declare function getTrackingIds(urlParams?: URLSearchParams): {
|
|
209
|
-
anonId: string | null;
|
|
210
|
-
sessionId: string | null;
|
|
211
|
-
};
|
|
212
|
-
/**
|
|
213
|
-
* Returns tracking IDs as a URL query string for cross-domain tracking.
|
|
214
|
-
* Append to URLs when linking to other domains you own.
|
|
215
|
-
*
|
|
216
|
-
* @param urlParams - Optional URLSearchParams to preserve existing params
|
|
217
|
-
* @returns Query string like `"anonId=xxx&sessionId=yyy"` or empty string
|
|
218
|
-
*
|
|
219
|
-
* @example
|
|
220
|
-
* ```ts
|
|
221
|
-
* import { getTrackingParams } from "@databuddy/sdk";
|
|
222
|
-
*
|
|
223
|
-
* // Link to subdomain with tracking continuity
|
|
224
|
-
* const params = getTrackingParams();
|
|
225
|
-
* const url = `https://app.example.com/dashboard${params ? `?${params}` : ""}`;
|
|
226
|
-
*
|
|
227
|
-
* // In a component
|
|
228
|
-
* <a href={`https://shop.example.com?${getTrackingParams()}`}>
|
|
229
|
-
* Visit Shop
|
|
230
|
-
* </a>
|
|
231
|
-
* ```
|
|
232
|
-
*/
|
|
233
|
-
declare function getTrackingParams(urlParams?: URLSearchParams): string;
|
|
234
|
-
|
|
235
|
-
export { DatabuddyConfig, DatabuddyTracker, clear, createScript, detectClientId, flush, getAnonymousId, getSessionId, getTracker, getTrackingIds, getTrackingParams, isScriptInjected, isTrackerAvailable, track, trackCustomEvent, trackError };
|
|
13
|
+
export { DatabuddyConfig, createScript, detectClientId, isScriptInjected };
|
package/dist/core/index.mjs
CHANGED
|
@@ -1,5 +1,28 @@
|
|
|
1
|
-
export {
|
|
2
|
-
|
|
1
|
+
export { c as createScript, i as isScriptInjected } from '../shared/@databuddy/sdk.C8vEu9Y4.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
|
+
}
|
|
3
26
|
|
|
4
27
|
function isTrackerAvailable() {
|
|
5
28
|
return typeof window !== "undefined" && (!!window.databuddy || !!window.db);
|
|
@@ -89,4 +112,4 @@ function getTrackingParams(urlParams) {
|
|
|
89
112
|
return params.toString();
|
|
90
113
|
}
|
|
91
114
|
|
|
92
|
-
export { clear, flush, getAnonymousId, getSessionId, getTracker, getTrackingIds, getTrackingParams, isTrackerAvailable, track, trackCustomEvent, trackError };
|
|
115
|
+
export { clear, detectClientId, flush, getAnonymousId, getSessionId, getTracker, getTrackingIds, getTrackingParams, isTrackerAvailable, track, trackCustomEvent, trackError };
|
package/dist/node/index.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { l as logger, i as isCacheValid, b as buildQueryParams, R as RequestBatcher, D as DEFAULT_RESULT, g as getCacheKey, a as isCacheStale, c as createCacheEntry, f as fetchAllFlags } from '../shared/@databuddy/sdk.
|
|
1
|
+
import { l as logger, i as isCacheValid, b as buildQueryParams, R as RequestBatcher, D as DEFAULT_RESULT, g as getCacheKey, a as isCacheStale, c as createCacheEntry, f as fetchAllFlags } from '../shared/@databuddy/sdk.DCKr2Zpd.mjs';
|
|
2
2
|
|
|
3
3
|
function createLogger(debug = false) {
|
|
4
4
|
return createConsoleLogger(debug);
|
package/dist/react/index.d.mts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import { D as DatabuddyConfig } from '../shared/@databuddy/sdk.
|
|
1
|
+
import { D as DatabuddyConfig } from '../shared/@databuddy/sdk.BsF1xr6_.mjs';
|
|
2
|
+
export { c as clear, f as flush, d as getAnonymousId, e as getSessionId, g as getTracker, h as getTrackingIds, j as getTrackingParams, i as isTrackerAvailable, t as track, b as trackError } from '../shared/@databuddy/sdk.BsF1xr6_.mjs';
|
|
2
3
|
import React, { ReactNode } from 'react';
|
|
3
4
|
import { F as FlagsConfig, a as FeatureState, b as FlagState, c as FlagsContext } from '../shared/@databuddy/sdk.B6nwxnPC.mjs';
|
|
4
5
|
|
package/dist/react/index.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import { D as DatabuddyConfig } from '../shared/@databuddy/sdk.
|
|
1
|
+
import { D as DatabuddyConfig } from '../shared/@databuddy/sdk.BsF1xr6_.js';
|
|
2
|
+
export { c as clear, f as flush, d as getAnonymousId, e as getSessionId, g as getTracker, h as getTrackingIds, j as getTrackingParams, i as isTrackerAvailable, t as track, b as trackError } from '../shared/@databuddy/sdk.BsF1xr6_.js';
|
|
2
3
|
import React, { ReactNode } from 'react';
|
|
3
4
|
import { F as FlagsConfig, a as FeatureState, b as FlagState, c as FlagsContext } from '../shared/@databuddy/sdk.B6nwxnPC.js';
|
|
4
5
|
|
package/dist/react/index.mjs
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
'use client';
|
|
2
2
|
|
|
3
|
-
import {
|
|
4
|
-
|
|
3
|
+
import { detectClientId } from '../core/index.mjs';
|
|
4
|
+
export { clear, flush, getAnonymousId, getSessionId, getTracker, getTrackingIds, getTrackingParams, isTrackerAvailable, track, trackError } from '../core/index.mjs';
|
|
5
|
+
import { i as isScriptInjected, c as createScript } from '../shared/@databuddy/sdk.C8vEu9Y4.mjs';
|
|
5
6
|
import React, { useRef, useMemo, useEffect, useSyncExternalStore, createContext, useContext } from 'react';
|
|
6
|
-
import { B as BrowserFlagStorage, C as CoreFlagsManager } from '../shared/@databuddy/sdk.
|
|
7
|
-
import { l as logger } from '../shared/@databuddy/sdk.
|
|
7
|
+
import { B as BrowserFlagStorage, C as CoreFlagsManager } from '../shared/@databuddy/sdk.D0dyEsAb.mjs';
|
|
8
|
+
import { l as logger } from '../shared/@databuddy/sdk.DCKr2Zpd.mjs';
|
|
8
9
|
|
|
9
10
|
function Databuddy(props) {
|
|
10
11
|
const clientId = detectClientId(props.clientId);
|
|
@@ -361,4 +361,227 @@ type TrackFunction = <T extends EventName>(eventName: T, properties?: Properties
|
|
|
361
361
|
type ScreenViewFunction = (properties?: Record<string, unknown>) => void;
|
|
362
362
|
type SetGlobalPropertiesFunction = (properties: EventProperties) => void;
|
|
363
363
|
|
|
364
|
-
|
|
364
|
+
/**
|
|
365
|
+
* Checks if the Databuddy tracker script has loaded and is available.
|
|
366
|
+
* Use this before calling tracking functions in conditional scenarios.
|
|
367
|
+
*
|
|
368
|
+
* @returns `true` if tracker is available, `false` if not loaded or on server
|
|
369
|
+
*
|
|
370
|
+
* @example
|
|
371
|
+
* ```ts
|
|
372
|
+
* import { isTrackerAvailable, track } from "@databuddy/sdk";
|
|
373
|
+
*
|
|
374
|
+
* if (isTrackerAvailable()) {
|
|
375
|
+
* track("feature_used", { feature: "export" });
|
|
376
|
+
* }
|
|
377
|
+
* ```
|
|
378
|
+
*/
|
|
379
|
+
declare function isTrackerAvailable(): boolean;
|
|
380
|
+
/**
|
|
381
|
+
* Returns the raw Databuddy tracker instance for advanced use cases.
|
|
382
|
+
* Prefer using the exported functions (`track`, `flush`, etc.) instead.
|
|
383
|
+
*
|
|
384
|
+
* @returns Tracker instance or `null` if not available
|
|
385
|
+
*
|
|
386
|
+
* @example
|
|
387
|
+
* ```ts
|
|
388
|
+
* import { getTracker, getAnonymousId, getSessionId } from "@databuddy/sdk";
|
|
389
|
+
*
|
|
390
|
+
* const tracker = getTracker();
|
|
391
|
+
* if (tracker) {
|
|
392
|
+
* // Access tracker methods
|
|
393
|
+
* tracker.track("event", { prop: "value" });
|
|
394
|
+
*
|
|
395
|
+
* // Get IDs using dedicated functions
|
|
396
|
+
* const anonId = getAnonymousId();
|
|
397
|
+
* const sessionId = getSessionId();
|
|
398
|
+
* }
|
|
399
|
+
* ```
|
|
400
|
+
*/
|
|
401
|
+
declare function getTracker(): DatabuddyTracker | null;
|
|
402
|
+
/**
|
|
403
|
+
* Tracks a custom event with optional properties.
|
|
404
|
+
* Events are batched and sent efficiently to minimize network overhead.
|
|
405
|
+
* Safe to call on server (no-op) or before tracker loads.
|
|
406
|
+
*
|
|
407
|
+
* @param name - Event name (e.g., "button_click", "purchase", "signup")
|
|
408
|
+
* @param properties - Key-value pairs of event data
|
|
409
|
+
*
|
|
410
|
+
* @example
|
|
411
|
+
* ```ts
|
|
412
|
+
* import { track } from "@databuddy/sdk";
|
|
413
|
+
*
|
|
414
|
+
* // Simple event
|
|
415
|
+
* track("signup_started");
|
|
416
|
+
*
|
|
417
|
+
* // Event with properties
|
|
418
|
+
* track("item_purchased", {
|
|
419
|
+
* itemId: "sku-123",
|
|
420
|
+
* price: 29.99,
|
|
421
|
+
* currency: "USD"
|
|
422
|
+
* });
|
|
423
|
+
*
|
|
424
|
+
* // In a React component
|
|
425
|
+
* function CheckoutButton() {
|
|
426
|
+
* return (
|
|
427
|
+
* <button onClick={() => track("checkout_clicked", { cartSize: 3 })}>
|
|
428
|
+
* Checkout
|
|
429
|
+
* </button>
|
|
430
|
+
* );
|
|
431
|
+
* }
|
|
432
|
+
* ```
|
|
433
|
+
*/
|
|
434
|
+
declare function track(name: string, properties?: Record<string, unknown>): void;
|
|
435
|
+
/** @deprecated Use `track()` instead. Will be removed in v3.0. */
|
|
436
|
+
declare function trackCustomEvent(name: string, properties?: Record<string, unknown>): void;
|
|
437
|
+
/**
|
|
438
|
+
* Clears the current user session and generates new anonymous/session IDs.
|
|
439
|
+
* Use after logout to ensure the next user gets a fresh identity.
|
|
440
|
+
*
|
|
441
|
+
* @example
|
|
442
|
+
* ```ts
|
|
443
|
+
* import { clear } from "@databuddy/sdk";
|
|
444
|
+
*
|
|
445
|
+
* async function handleLogout() {
|
|
446
|
+
* await signOut();
|
|
447
|
+
* clear(); // Reset tracking identity
|
|
448
|
+
* router.push("/login");
|
|
449
|
+
* }
|
|
450
|
+
* ```
|
|
451
|
+
*/
|
|
452
|
+
declare function clear(): void;
|
|
453
|
+
/**
|
|
454
|
+
* Forces all queued events to be sent immediately.
|
|
455
|
+
* Useful before navigation or when you need to ensure events are captured.
|
|
456
|
+
*
|
|
457
|
+
* @example
|
|
458
|
+
* ```ts
|
|
459
|
+
* import { track, flush } from "@databuddy/sdk";
|
|
460
|
+
*
|
|
461
|
+
* function handleExternalLink(url: string) {
|
|
462
|
+
* track("external_link_clicked", { url });
|
|
463
|
+
* flush(); // Ensure event is sent before leaving
|
|
464
|
+
* window.location.href = url;
|
|
465
|
+
* }
|
|
466
|
+
* ```
|
|
467
|
+
*/
|
|
468
|
+
declare function flush(): void;
|
|
469
|
+
/**
|
|
470
|
+
* Tracks an error event. Convenience wrapper around `track("error", ...)`.
|
|
471
|
+
*
|
|
472
|
+
* @param message - Error message
|
|
473
|
+
* @param properties - Additional error context (filename, line number, stack trace)
|
|
474
|
+
*
|
|
475
|
+
* @example
|
|
476
|
+
* ```ts
|
|
477
|
+
* import { trackError } from "@databuddy/sdk";
|
|
478
|
+
*
|
|
479
|
+
* try {
|
|
480
|
+
* await riskyOperation();
|
|
481
|
+
* } catch (error) {
|
|
482
|
+
* trackError(error.message, {
|
|
483
|
+
* stack: error.stack,
|
|
484
|
+
* error_type: error.name,
|
|
485
|
+
* context: "checkout_flow"
|
|
486
|
+
* });
|
|
487
|
+
* }
|
|
488
|
+
* ```
|
|
489
|
+
*/
|
|
490
|
+
declare function trackError(message: string, properties?: {
|
|
491
|
+
filename?: string;
|
|
492
|
+
lineno?: number;
|
|
493
|
+
colno?: number;
|
|
494
|
+
stack?: string;
|
|
495
|
+
error_type?: string;
|
|
496
|
+
[key: string]: string | number | boolean | null | undefined;
|
|
497
|
+
}): void;
|
|
498
|
+
/**
|
|
499
|
+
* Gets the anonymous user ID. Persists across sessions via localStorage.
|
|
500
|
+
* Useful for server-side identification or cross-domain tracking.
|
|
501
|
+
*
|
|
502
|
+
* @param urlParams - Optional URLSearchParams to check for `anonId` param (highest priority)
|
|
503
|
+
* @returns Anonymous ID or `null` if unavailable
|
|
504
|
+
*
|
|
505
|
+
* Priority: URL params → tracker instance → localStorage
|
|
506
|
+
*
|
|
507
|
+
* @example
|
|
508
|
+
* ```ts
|
|
509
|
+
* import { getAnonymousId } from "@databuddy/sdk";
|
|
510
|
+
*
|
|
511
|
+
* // Get from tracker
|
|
512
|
+
* const anonId = getAnonymousId();
|
|
513
|
+
*
|
|
514
|
+
* // Check URL params first (for cross-domain tracking)
|
|
515
|
+
* const params = new URLSearchParams(window.location.search);
|
|
516
|
+
* const anonId = getAnonymousId(params);
|
|
517
|
+
*
|
|
518
|
+
* // Pass to server
|
|
519
|
+
* await fetch("/api/identify", {
|
|
520
|
+
* body: JSON.stringify({ anonId })
|
|
521
|
+
* });
|
|
522
|
+
* ```
|
|
523
|
+
*/
|
|
524
|
+
declare function getAnonymousId(urlParams?: URLSearchParams): string | null;
|
|
525
|
+
/**
|
|
526
|
+
* Gets the current session ID. Resets after 30 min of inactivity.
|
|
527
|
+
* Useful for correlating events within a single browsing session.
|
|
528
|
+
*
|
|
529
|
+
* @param urlParams - Optional URLSearchParams to check for `sessionId` param (highest priority)
|
|
530
|
+
* @returns Session ID or `null` if unavailable
|
|
531
|
+
*
|
|
532
|
+
* Priority: URL params → tracker instance → sessionStorage
|
|
533
|
+
*
|
|
534
|
+
* @example
|
|
535
|
+
* ```ts
|
|
536
|
+
* import { getSessionId } from "@databuddy/sdk";
|
|
537
|
+
*
|
|
538
|
+
* const sessionId = getSessionId();
|
|
539
|
+
* console.log("Current session:", sessionId);
|
|
540
|
+
* ```
|
|
541
|
+
*/
|
|
542
|
+
declare function getSessionId(urlParams?: URLSearchParams): string | null;
|
|
543
|
+
/**
|
|
544
|
+
* Gets both anonymous ID and session ID in a single call.
|
|
545
|
+
*
|
|
546
|
+
* @param urlParams - Optional URLSearchParams to check for tracking params
|
|
547
|
+
* @returns Object with `anonId` and `sessionId` (either may be null)
|
|
548
|
+
*
|
|
549
|
+
* @example
|
|
550
|
+
* ```ts
|
|
551
|
+
* import { getTrackingIds } from "@databuddy/sdk";
|
|
552
|
+
*
|
|
553
|
+
* const { anonId, sessionId } = getTrackingIds();
|
|
554
|
+
*
|
|
555
|
+
* // Send to your backend
|
|
556
|
+
* await api.identify({ anonId, sessionId, userId: user.id });
|
|
557
|
+
* ```
|
|
558
|
+
*/
|
|
559
|
+
declare function getTrackingIds(urlParams?: URLSearchParams): {
|
|
560
|
+
anonId: string | null;
|
|
561
|
+
sessionId: string | null;
|
|
562
|
+
};
|
|
563
|
+
/**
|
|
564
|
+
* Returns tracking IDs as a URL query string for cross-domain tracking.
|
|
565
|
+
* Append to URLs when linking to other domains you own.
|
|
566
|
+
*
|
|
567
|
+
* @param urlParams - Optional URLSearchParams to preserve existing params
|
|
568
|
+
* @returns Query string like `"anonId=xxx&sessionId=yyy"` or empty string
|
|
569
|
+
*
|
|
570
|
+
* @example
|
|
571
|
+
* ```ts
|
|
572
|
+
* import { getTrackingParams } from "@databuddy/sdk";
|
|
573
|
+
*
|
|
574
|
+
* // Link to subdomain with tracking continuity
|
|
575
|
+
* const params = getTrackingParams();
|
|
576
|
+
* const url = `https://app.example.com/dashboard${params ? `?${params}` : ""}`;
|
|
577
|
+
*
|
|
578
|
+
* // In a component
|
|
579
|
+
* <a href={`https://shop.example.com?${getTrackingParams()}`}>
|
|
580
|
+
* Visit Shop
|
|
581
|
+
* </a>
|
|
582
|
+
* ```
|
|
583
|
+
*/
|
|
584
|
+
declare function getTrackingParams(urlParams?: URLSearchParams): string;
|
|
585
|
+
|
|
586
|
+
export { trackCustomEvent as a, trackError as b, clear as c, getAnonymousId as d, getSessionId as e, flush as f, getTracker as g, getTrackingIds as h, isTrackerAvailable as i, getTrackingParams as j, track as t };
|
|
587
|
+
export type { BaseEventProperties as B, DatabuddyConfig as D, EventProperties as E, PropertiesForEvent as P, ScreenViewFunction as S, TrackFunction as T, EventTypeMap as k, EventName as l, DatabuddyTracker as m, DataAttributes as n, SetGlobalPropertiesFunction as o };
|
|
@@ -361,4 +361,227 @@ type TrackFunction = <T extends EventName>(eventName: T, properties?: Properties
|
|
|
361
361
|
type ScreenViewFunction = (properties?: Record<string, unknown>) => void;
|
|
362
362
|
type SetGlobalPropertiesFunction = (properties: EventProperties) => void;
|
|
363
363
|
|
|
364
|
-
|
|
364
|
+
/**
|
|
365
|
+
* Checks if the Databuddy tracker script has loaded and is available.
|
|
366
|
+
* Use this before calling tracking functions in conditional scenarios.
|
|
367
|
+
*
|
|
368
|
+
* @returns `true` if tracker is available, `false` if not loaded or on server
|
|
369
|
+
*
|
|
370
|
+
* @example
|
|
371
|
+
* ```ts
|
|
372
|
+
* import { isTrackerAvailable, track } from "@databuddy/sdk";
|
|
373
|
+
*
|
|
374
|
+
* if (isTrackerAvailable()) {
|
|
375
|
+
* track("feature_used", { feature: "export" });
|
|
376
|
+
* }
|
|
377
|
+
* ```
|
|
378
|
+
*/
|
|
379
|
+
declare function isTrackerAvailable(): boolean;
|
|
380
|
+
/**
|
|
381
|
+
* Returns the raw Databuddy tracker instance for advanced use cases.
|
|
382
|
+
* Prefer using the exported functions (`track`, `flush`, etc.) instead.
|
|
383
|
+
*
|
|
384
|
+
* @returns Tracker instance or `null` if not available
|
|
385
|
+
*
|
|
386
|
+
* @example
|
|
387
|
+
* ```ts
|
|
388
|
+
* import { getTracker, getAnonymousId, getSessionId } from "@databuddy/sdk";
|
|
389
|
+
*
|
|
390
|
+
* const tracker = getTracker();
|
|
391
|
+
* if (tracker) {
|
|
392
|
+
* // Access tracker methods
|
|
393
|
+
* tracker.track("event", { prop: "value" });
|
|
394
|
+
*
|
|
395
|
+
* // Get IDs using dedicated functions
|
|
396
|
+
* const anonId = getAnonymousId();
|
|
397
|
+
* const sessionId = getSessionId();
|
|
398
|
+
* }
|
|
399
|
+
* ```
|
|
400
|
+
*/
|
|
401
|
+
declare function getTracker(): DatabuddyTracker | null;
|
|
402
|
+
/**
|
|
403
|
+
* Tracks a custom event with optional properties.
|
|
404
|
+
* Events are batched and sent efficiently to minimize network overhead.
|
|
405
|
+
* Safe to call on server (no-op) or before tracker loads.
|
|
406
|
+
*
|
|
407
|
+
* @param name - Event name (e.g., "button_click", "purchase", "signup")
|
|
408
|
+
* @param properties - Key-value pairs of event data
|
|
409
|
+
*
|
|
410
|
+
* @example
|
|
411
|
+
* ```ts
|
|
412
|
+
* import { track } from "@databuddy/sdk";
|
|
413
|
+
*
|
|
414
|
+
* // Simple event
|
|
415
|
+
* track("signup_started");
|
|
416
|
+
*
|
|
417
|
+
* // Event with properties
|
|
418
|
+
* track("item_purchased", {
|
|
419
|
+
* itemId: "sku-123",
|
|
420
|
+
* price: 29.99,
|
|
421
|
+
* currency: "USD"
|
|
422
|
+
* });
|
|
423
|
+
*
|
|
424
|
+
* // In a React component
|
|
425
|
+
* function CheckoutButton() {
|
|
426
|
+
* return (
|
|
427
|
+
* <button onClick={() => track("checkout_clicked", { cartSize: 3 })}>
|
|
428
|
+
* Checkout
|
|
429
|
+
* </button>
|
|
430
|
+
* );
|
|
431
|
+
* }
|
|
432
|
+
* ```
|
|
433
|
+
*/
|
|
434
|
+
declare function track(name: string, properties?: Record<string, unknown>): void;
|
|
435
|
+
/** @deprecated Use `track()` instead. Will be removed in v3.0. */
|
|
436
|
+
declare function trackCustomEvent(name: string, properties?: Record<string, unknown>): void;
|
|
437
|
+
/**
|
|
438
|
+
* Clears the current user session and generates new anonymous/session IDs.
|
|
439
|
+
* Use after logout to ensure the next user gets a fresh identity.
|
|
440
|
+
*
|
|
441
|
+
* @example
|
|
442
|
+
* ```ts
|
|
443
|
+
* import { clear } from "@databuddy/sdk";
|
|
444
|
+
*
|
|
445
|
+
* async function handleLogout() {
|
|
446
|
+
* await signOut();
|
|
447
|
+
* clear(); // Reset tracking identity
|
|
448
|
+
* router.push("/login");
|
|
449
|
+
* }
|
|
450
|
+
* ```
|
|
451
|
+
*/
|
|
452
|
+
declare function clear(): void;
|
|
453
|
+
/**
|
|
454
|
+
* Forces all queued events to be sent immediately.
|
|
455
|
+
* Useful before navigation or when you need to ensure events are captured.
|
|
456
|
+
*
|
|
457
|
+
* @example
|
|
458
|
+
* ```ts
|
|
459
|
+
* import { track, flush } from "@databuddy/sdk";
|
|
460
|
+
*
|
|
461
|
+
* function handleExternalLink(url: string) {
|
|
462
|
+
* track("external_link_clicked", { url });
|
|
463
|
+
* flush(); // Ensure event is sent before leaving
|
|
464
|
+
* window.location.href = url;
|
|
465
|
+
* }
|
|
466
|
+
* ```
|
|
467
|
+
*/
|
|
468
|
+
declare function flush(): void;
|
|
469
|
+
/**
|
|
470
|
+
* Tracks an error event. Convenience wrapper around `track("error", ...)`.
|
|
471
|
+
*
|
|
472
|
+
* @param message - Error message
|
|
473
|
+
* @param properties - Additional error context (filename, line number, stack trace)
|
|
474
|
+
*
|
|
475
|
+
* @example
|
|
476
|
+
* ```ts
|
|
477
|
+
* import { trackError } from "@databuddy/sdk";
|
|
478
|
+
*
|
|
479
|
+
* try {
|
|
480
|
+
* await riskyOperation();
|
|
481
|
+
* } catch (error) {
|
|
482
|
+
* trackError(error.message, {
|
|
483
|
+
* stack: error.stack,
|
|
484
|
+
* error_type: error.name,
|
|
485
|
+
* context: "checkout_flow"
|
|
486
|
+
* });
|
|
487
|
+
* }
|
|
488
|
+
* ```
|
|
489
|
+
*/
|
|
490
|
+
declare function trackError(message: string, properties?: {
|
|
491
|
+
filename?: string;
|
|
492
|
+
lineno?: number;
|
|
493
|
+
colno?: number;
|
|
494
|
+
stack?: string;
|
|
495
|
+
error_type?: string;
|
|
496
|
+
[key: string]: string | number | boolean | null | undefined;
|
|
497
|
+
}): void;
|
|
498
|
+
/**
|
|
499
|
+
* Gets the anonymous user ID. Persists across sessions via localStorage.
|
|
500
|
+
* Useful for server-side identification or cross-domain tracking.
|
|
501
|
+
*
|
|
502
|
+
* @param urlParams - Optional URLSearchParams to check for `anonId` param (highest priority)
|
|
503
|
+
* @returns Anonymous ID or `null` if unavailable
|
|
504
|
+
*
|
|
505
|
+
* Priority: URL params → tracker instance → localStorage
|
|
506
|
+
*
|
|
507
|
+
* @example
|
|
508
|
+
* ```ts
|
|
509
|
+
* import { getAnonymousId } from "@databuddy/sdk";
|
|
510
|
+
*
|
|
511
|
+
* // Get from tracker
|
|
512
|
+
* const anonId = getAnonymousId();
|
|
513
|
+
*
|
|
514
|
+
* // Check URL params first (for cross-domain tracking)
|
|
515
|
+
* const params = new URLSearchParams(window.location.search);
|
|
516
|
+
* const anonId = getAnonymousId(params);
|
|
517
|
+
*
|
|
518
|
+
* // Pass to server
|
|
519
|
+
* await fetch("/api/identify", {
|
|
520
|
+
* body: JSON.stringify({ anonId })
|
|
521
|
+
* });
|
|
522
|
+
* ```
|
|
523
|
+
*/
|
|
524
|
+
declare function getAnonymousId(urlParams?: URLSearchParams): string | null;
|
|
525
|
+
/**
|
|
526
|
+
* Gets the current session ID. Resets after 30 min of inactivity.
|
|
527
|
+
* Useful for correlating events within a single browsing session.
|
|
528
|
+
*
|
|
529
|
+
* @param urlParams - Optional URLSearchParams to check for `sessionId` param (highest priority)
|
|
530
|
+
* @returns Session ID or `null` if unavailable
|
|
531
|
+
*
|
|
532
|
+
* Priority: URL params → tracker instance → sessionStorage
|
|
533
|
+
*
|
|
534
|
+
* @example
|
|
535
|
+
* ```ts
|
|
536
|
+
* import { getSessionId } from "@databuddy/sdk";
|
|
537
|
+
*
|
|
538
|
+
* const sessionId = getSessionId();
|
|
539
|
+
* console.log("Current session:", sessionId);
|
|
540
|
+
* ```
|
|
541
|
+
*/
|
|
542
|
+
declare function getSessionId(urlParams?: URLSearchParams): string | null;
|
|
543
|
+
/**
|
|
544
|
+
* Gets both anonymous ID and session ID in a single call.
|
|
545
|
+
*
|
|
546
|
+
* @param urlParams - Optional URLSearchParams to check for tracking params
|
|
547
|
+
* @returns Object with `anonId` and `sessionId` (either may be null)
|
|
548
|
+
*
|
|
549
|
+
* @example
|
|
550
|
+
* ```ts
|
|
551
|
+
* import { getTrackingIds } from "@databuddy/sdk";
|
|
552
|
+
*
|
|
553
|
+
* const { anonId, sessionId } = getTrackingIds();
|
|
554
|
+
*
|
|
555
|
+
* // Send to your backend
|
|
556
|
+
* await api.identify({ anonId, sessionId, userId: user.id });
|
|
557
|
+
* ```
|
|
558
|
+
*/
|
|
559
|
+
declare function getTrackingIds(urlParams?: URLSearchParams): {
|
|
560
|
+
anonId: string | null;
|
|
561
|
+
sessionId: string | null;
|
|
562
|
+
};
|
|
563
|
+
/**
|
|
564
|
+
* Returns tracking IDs as a URL query string for cross-domain tracking.
|
|
565
|
+
* Append to URLs when linking to other domains you own.
|
|
566
|
+
*
|
|
567
|
+
* @param urlParams - Optional URLSearchParams to preserve existing params
|
|
568
|
+
* @returns Query string like `"anonId=xxx&sessionId=yyy"` or empty string
|
|
569
|
+
*
|
|
570
|
+
* @example
|
|
571
|
+
* ```ts
|
|
572
|
+
* import { getTrackingParams } from "@databuddy/sdk";
|
|
573
|
+
*
|
|
574
|
+
* // Link to subdomain with tracking continuity
|
|
575
|
+
* const params = getTrackingParams();
|
|
576
|
+
* const url = `https://app.example.com/dashboard${params ? `?${params}` : ""}`;
|
|
577
|
+
*
|
|
578
|
+
* // In a component
|
|
579
|
+
* <a href={`https://shop.example.com?${getTrackingParams()}`}>
|
|
580
|
+
* Visit Shop
|
|
581
|
+
* </a>
|
|
582
|
+
* ```
|
|
583
|
+
*/
|
|
584
|
+
declare function getTrackingParams(urlParams?: URLSearchParams): string;
|
|
585
|
+
|
|
586
|
+
export { trackCustomEvent as a, trackError as b, clear as c, getAnonymousId as d, getSessionId as e, flush as f, getTracker as g, getTrackingIds as h, isTrackerAvailable as i, getTrackingParams as j, track as t };
|
|
587
|
+
export type { BaseEventProperties as B, DatabuddyConfig as D, EventProperties as E, PropertiesForEvent as P, ScreenViewFunction as S, TrackFunction as T, EventTypeMap as k, EventName as l, DatabuddyTracker as m, DataAttributes as n, SetGlobalPropertiesFunction as o };
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { l as logger, c as createCacheEntry, i as isCacheValid, b as buildQueryParams, R as RequestBatcher, a as isCacheStale, D as DEFAULT_RESULT, g as getCacheKey, f as fetchAllFlags } from './sdk.
|
|
1
|
+
import { l as logger, c as createCacheEntry, i as isCacheValid, b as buildQueryParams, R as RequestBatcher, a as isCacheStale, D as DEFAULT_RESULT, g as getCacheKey, f as fetchAllFlags } from './sdk.DCKr2Zpd.mjs';
|
|
2
2
|
|
|
3
3
|
class BrowserFlagStorage {
|
|
4
4
|
ttl = 24 * 60 * 60 * 1e3;
|
|
@@ -201,7 +201,10 @@ class CoreFlagsManager {
|
|
|
201
201
|
const staleTime = this.config.staleTime ?? ttl / 2;
|
|
202
202
|
for (const [key, value] of Object.entries(stored)) {
|
|
203
203
|
if (value && typeof value === "object") {
|
|
204
|
-
this.cache.set(
|
|
204
|
+
this.cache.set(
|
|
205
|
+
key,
|
|
206
|
+
createCacheEntry(value, ttl, staleTime)
|
|
207
|
+
);
|
|
205
208
|
}
|
|
206
209
|
}
|
|
207
210
|
if (this.cache.size > 0) {
|
|
@@ -173,7 +173,10 @@ class RequestBatcher {
|
|
|
173
173
|
try {
|
|
174
174
|
const results = await fetchFlags(this.apiUrl, keys, this.params);
|
|
175
175
|
for (const [key, cbs] of callbacks) {
|
|
176
|
-
const result = results[key] ?? {
|
|
176
|
+
const result = results[key] ?? {
|
|
177
|
+
...DEFAULT_RESULT,
|
|
178
|
+
reason: "NOT_FOUND"
|
|
179
|
+
};
|
|
177
180
|
for (const cb of cbs) {
|
|
178
181
|
cb.resolve(result);
|
|
179
182
|
}
|
package/dist/vue/index.mjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { defineComponent, ref, onMounted, onUnmounted, watch, reactive, watchEffect, computed } from 'vue';
|
|
2
|
-
import { i as isScriptInjected, c as createScript } from '../shared/@databuddy/sdk.
|
|
3
|
-
import { B as BrowserFlagStorage, C as CoreFlagsManager } from '../shared/@databuddy/sdk.
|
|
4
|
-
import '../shared/@databuddy/sdk.
|
|
2
|
+
import { i as isScriptInjected, c as createScript } from '../shared/@databuddy/sdk.C8vEu9Y4.mjs';
|
|
3
|
+
import { B as BrowserFlagStorage, C as CoreFlagsManager } from '../shared/@databuddy/sdk.D0dyEsAb.mjs';
|
|
4
|
+
import '../shared/@databuddy/sdk.DCKr2Zpd.mjs';
|
|
5
5
|
|
|
6
6
|
const Databuddy = defineComponent({
|
|
7
7
|
props: {},
|
package/package.json
CHANGED
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
function detectClientId(providedClientId) {
|
|
2
|
-
if (providedClientId) {
|
|
3
|
-
return providedClientId;
|
|
4
|
-
}
|
|
5
|
-
if (typeof process !== "undefined" && process.env) {
|
|
6
|
-
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;
|
|
7
|
-
}
|
|
8
|
-
if (typeof window !== "undefined") {
|
|
9
|
-
const nextEnv = window.__NEXT_DATA__?.env?.NEXT_PUBLIC_DATABUDDY_CLIENT_ID;
|
|
10
|
-
if (nextEnv) {
|
|
11
|
-
return nextEnv;
|
|
12
|
-
}
|
|
13
|
-
const nuxtEnv = window.__NUXT__?.env?.NUXT_PUBLIC_DATABUDDY_CLIENT_ID;
|
|
14
|
-
if (nuxtEnv) {
|
|
15
|
-
return nuxtEnv;
|
|
16
|
-
}
|
|
17
|
-
const viteEnv = window.__VITE_ENV__?.VITE_DATABUDDY_CLIENT_ID;
|
|
18
|
-
if (viteEnv) {
|
|
19
|
-
return viteEnv;
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
|
-
return;
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
export { detectClientId as d };
|