@databuddy/sdk 2.3.2 → 2.3.22

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.
@@ -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.DATABUDDY_BASKET_URL + '/llm' or 'https://basket.databuddy.cc/llm'
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://api.databuddy.cc/ai-logs",
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.DATABUDDY_BASKET_URL + '/llm' or 'https://basket.databuddy.cc/llm'
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://api.databuddy.cc/ai-logs",
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 };
@@ -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 ?? (process.env.DATABUDDY_BASKET_URL ? `${process.env.DATABUDDY_BASKET_URL}/llm` : process.env.DATABUDDY_API_URL ? `${process.env.DATABUDDY_API_URL}/llm` : "https://basket.databuddy.cc/llm");
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,
@@ -1,5 +1,5 @@
1
- import { D as DatabuddyConfig, a as DatabuddyTracker } from '../shared/@databuddy/sdk.C9b3SVYK.mjs';
2
- export { B as BaseEventProperties, d as DataAttributes, c as EventName, E as EventProperties, b as EventTypeMap, P as PropertiesForEvent, S as ScreenViewFunction, e as SetGlobalPropertiesFunction, T as TrackFunction } from '../shared/@databuddy/sdk.C9b3SVYK.mjs';
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 };
@@ -1,5 +1,5 @@
1
- import { D as DatabuddyConfig, a as DatabuddyTracker } from '../shared/@databuddy/sdk.C9b3SVYK.js';
2
- export { B as BaseEventProperties, d as DataAttributes, c as EventName, E as EventProperties, b as EventTypeMap, P as PropertiesForEvent, S as ScreenViewFunction, e as SetGlobalPropertiesFunction, T as TrackFunction } from '../shared/@databuddy/sdk.C9b3SVYK.js';
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 };
@@ -1,5 +1,28 @@
1
- export { d as detectClientId } from '../shared/@databuddy/sdk.BUsPV0LH.mjs';
2
- export { c as createScript, i as isScriptInjected } from '../shared/@databuddy/sdk.F8Xt1uF7.mjs';
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 };
@@ -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.3kaCzyfu.mjs';
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);
@@ -1,4 +1,5 @@
1
- import { D as DatabuddyConfig } from '../shared/@databuddy/sdk.C9b3SVYK.mjs';
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