@databuddy/sdk 2.3.1 → 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 +157 -7
- package/dist/ai/vercel/index.d.ts +157 -7
- package/dist/ai/vercel/index.mjs +229 -34
- package/dist/core/index.d.mts +3 -265
- package/dist/core/index.d.ts +3 -265
- package/dist/core/index.mjs +26 -3
- package/dist/node/index.d.mts +121 -10
- package/dist/node/index.d.ts +121 -10
- package/dist/node/index.mjs +256 -2
- package/dist/react/index.d.mts +58 -17
- package/dist/react/index.d.ts +58 -17
- package/dist/react/index.mjs +179 -86
- package/dist/shared/@databuddy/sdk.B6nwxnPC.d.mts +128 -0
- package/dist/shared/@databuddy/sdk.B6nwxnPC.d.ts +128 -0
- package/dist/shared/@databuddy/{sdk.CeYE_kaj.d.mts → sdk.BsF1xr6_.d.mts} +234 -11
- package/dist/shared/@databuddy/{sdk.CeYE_kaj.d.ts → sdk.BsF1xr6_.d.ts} +234 -11
- package/dist/shared/@databuddy/sdk.C8vEu9Y4.mjs +35 -0
- package/dist/shared/@databuddy/sdk.D0dyEsAb.mjs +482 -0
- package/dist/shared/@databuddy/sdk.DCKr2Zpd.mjs +202 -0
- package/dist/vue/index.d.mts +11 -2
- package/dist/vue/index.d.ts +11 -2
- package/dist/vue/index.mjs +19 -9
- package/package.json +3 -4
- package/dist/shared/@databuddy/sdk.BUsPV0LH.mjs +0 -25
- package/dist/shared/@databuddy/sdk.ByNF_UxE.mjs +0 -471
- package/dist/shared/@databuddy/sdk.OK9Nbqlf.d.mts +0 -64
- package/dist/shared/@databuddy/sdk.OK9Nbqlf.d.ts +0 -64
package/dist/core/index.d.mts
CHANGED
|
@@ -1,7 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export { e as
|
|
3
|
-
import { D as DatabuddyConfig, a as DatabuddyTracker } from '../shared/@databuddy/sdk.CeYE_kaj.mjs';
|
|
4
|
-
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.CeYE_kaj.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';
|
|
5
3
|
|
|
6
4
|
/**
|
|
7
5
|
* Auto-detect Databuddy client ID from environment variables
|
|
@@ -9,267 +7,7 @@ export { B as BaseEventProperties, d as DataAttributes, c as EventName, E as Eve
|
|
|
9
7
|
*/
|
|
10
8
|
declare function detectClientId(providedClientId?: string): string | undefined;
|
|
11
9
|
|
|
12
|
-
declare class BrowserFlagStorage implements StorageInterface {
|
|
13
|
-
private ttl;
|
|
14
|
-
get(key: string): any;
|
|
15
|
-
set(key: string, value: unknown): void;
|
|
16
|
-
getAll(): Record<string, unknown>;
|
|
17
|
-
clear(): void;
|
|
18
|
-
private getFromLocalStorage;
|
|
19
|
-
private setToLocalStorage;
|
|
20
|
-
private isExpired;
|
|
21
|
-
delete(key: string): void;
|
|
22
|
-
deleteMultiple(keys: string[]): void;
|
|
23
|
-
setAll(flags: Record<string, unknown>): void;
|
|
24
|
-
cleanupExpired(): void;
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
declare class CoreFlagsManager implements FlagsManager {
|
|
28
|
-
private config;
|
|
29
|
-
private storage?;
|
|
30
|
-
private onFlagsUpdate?;
|
|
31
|
-
private onConfigUpdate?;
|
|
32
|
-
private memoryFlags;
|
|
33
|
-
private pendingFlags;
|
|
34
|
-
constructor(options: FlagsManagerOptions);
|
|
35
|
-
private withDefaults;
|
|
36
|
-
private initialize;
|
|
37
|
-
private loadCachedFlags;
|
|
38
|
-
fetchAllFlags(): Promise<void>;
|
|
39
|
-
getFlag(key: string): Promise<FlagResult>;
|
|
40
|
-
private fetchFlag;
|
|
41
|
-
isEnabled(key: string): FlagState;
|
|
42
|
-
refresh(forceClear?: boolean): void;
|
|
43
|
-
updateUser(user: FlagsConfig["user"]): void;
|
|
44
|
-
updateConfig(config: FlagsConfig): void;
|
|
45
|
-
getMemoryFlags(): Record<string, FlagResult>;
|
|
46
|
-
getPendingFlags(): Set<string>;
|
|
47
|
-
private notifyFlagsUpdate;
|
|
48
|
-
}
|
|
49
|
-
|
|
50
10
|
declare function isScriptInjected(): boolean;
|
|
51
11
|
declare function createScript({ scriptUrl, sdkVersion, clientSecret, filter, debug, ...props }: DatabuddyConfig): HTMLScriptElement;
|
|
52
12
|
|
|
53
|
-
|
|
54
|
-
* Checks if the Databuddy tracker script has loaded and is available.
|
|
55
|
-
* Use this before calling tracking functions in conditional scenarios.
|
|
56
|
-
*
|
|
57
|
-
* @returns `true` if tracker is available, `false` if not loaded or on server
|
|
58
|
-
*
|
|
59
|
-
* @example
|
|
60
|
-
* ```ts
|
|
61
|
-
* import { isTrackerAvailable, track } from "@databuddy/sdk";
|
|
62
|
-
*
|
|
63
|
-
* if (isTrackerAvailable()) {
|
|
64
|
-
* track("feature_used", { feature: "export" });
|
|
65
|
-
* }
|
|
66
|
-
* ```
|
|
67
|
-
*/
|
|
68
|
-
declare function isTrackerAvailable(): boolean;
|
|
69
|
-
/**
|
|
70
|
-
* Returns the raw Databuddy tracker instance for advanced use cases.
|
|
71
|
-
* Prefer using the exported functions (`track`, `flush`, etc.) instead.
|
|
72
|
-
*
|
|
73
|
-
* @returns Tracker instance or `null` if not available
|
|
74
|
-
*
|
|
75
|
-
* @example
|
|
76
|
-
* ```ts
|
|
77
|
-
* import { getTracker, getAnonymousId, getSessionId } from "@databuddy/sdk";
|
|
78
|
-
*
|
|
79
|
-
* const tracker = getTracker();
|
|
80
|
-
* if (tracker) {
|
|
81
|
-
* // Access tracker methods
|
|
82
|
-
* tracker.track("event", { prop: "value" });
|
|
83
|
-
*
|
|
84
|
-
* // Get IDs using dedicated functions
|
|
85
|
-
* const anonId = getAnonymousId();
|
|
86
|
-
* const sessionId = getSessionId();
|
|
87
|
-
* }
|
|
88
|
-
* ```
|
|
89
|
-
*/
|
|
90
|
-
declare function getTracker(): DatabuddyTracker | null;
|
|
91
|
-
/**
|
|
92
|
-
* Tracks a custom event with optional properties.
|
|
93
|
-
* Events are batched and sent efficiently to minimize network overhead.
|
|
94
|
-
* Safe to call on server (no-op) or before tracker loads.
|
|
95
|
-
*
|
|
96
|
-
* @param name - Event name (e.g., "button_click", "purchase", "signup")
|
|
97
|
-
* @param properties - Key-value pairs of event data
|
|
98
|
-
*
|
|
99
|
-
* @example
|
|
100
|
-
* ```ts
|
|
101
|
-
* import { track } from "@databuddy/sdk";
|
|
102
|
-
*
|
|
103
|
-
* // Simple event
|
|
104
|
-
* track("signup_started");
|
|
105
|
-
*
|
|
106
|
-
* // Event with properties
|
|
107
|
-
* track("item_purchased", {
|
|
108
|
-
* itemId: "sku-123",
|
|
109
|
-
* price: 29.99,
|
|
110
|
-
* currency: "USD"
|
|
111
|
-
* });
|
|
112
|
-
*
|
|
113
|
-
* // In a React component
|
|
114
|
-
* function CheckoutButton() {
|
|
115
|
-
* return (
|
|
116
|
-
* <button onClick={() => track("checkout_clicked", { cartSize: 3 })}>
|
|
117
|
-
* Checkout
|
|
118
|
-
* </button>
|
|
119
|
-
* );
|
|
120
|
-
* }
|
|
121
|
-
* ```
|
|
122
|
-
*/
|
|
123
|
-
declare function track(name: string, properties?: Record<string, unknown>): void;
|
|
124
|
-
/** @deprecated Use `track()` instead. Will be removed in v3.0. */
|
|
125
|
-
declare function trackCustomEvent(name: string, properties?: Record<string, unknown>): void;
|
|
126
|
-
/**
|
|
127
|
-
* Clears the current user session and generates new anonymous/session IDs.
|
|
128
|
-
* Use after logout to ensure the next user gets a fresh identity.
|
|
129
|
-
*
|
|
130
|
-
* @example
|
|
131
|
-
* ```ts
|
|
132
|
-
* import { clear } from "@databuddy/sdk";
|
|
133
|
-
*
|
|
134
|
-
* async function handleLogout() {
|
|
135
|
-
* await signOut();
|
|
136
|
-
* clear(); // Reset tracking identity
|
|
137
|
-
* router.push("/login");
|
|
138
|
-
* }
|
|
139
|
-
* ```
|
|
140
|
-
*/
|
|
141
|
-
declare function clear(): void;
|
|
142
|
-
/**
|
|
143
|
-
* Forces all queued events to be sent immediately.
|
|
144
|
-
* Useful before navigation or when you need to ensure events are captured.
|
|
145
|
-
*
|
|
146
|
-
* @example
|
|
147
|
-
* ```ts
|
|
148
|
-
* import { track, flush } from "@databuddy/sdk";
|
|
149
|
-
*
|
|
150
|
-
* function handleExternalLink(url: string) {
|
|
151
|
-
* track("external_link_clicked", { url });
|
|
152
|
-
* flush(); // Ensure event is sent before leaving
|
|
153
|
-
* window.location.href = url;
|
|
154
|
-
* }
|
|
155
|
-
* ```
|
|
156
|
-
*/
|
|
157
|
-
declare function flush(): void;
|
|
158
|
-
/**
|
|
159
|
-
* Tracks an error event. Convenience wrapper around `track("error", ...)`.
|
|
160
|
-
*
|
|
161
|
-
* @param message - Error message
|
|
162
|
-
* @param properties - Additional error context (filename, line number, stack trace)
|
|
163
|
-
*
|
|
164
|
-
* @example
|
|
165
|
-
* ```ts
|
|
166
|
-
* import { trackError } from "@databuddy/sdk";
|
|
167
|
-
*
|
|
168
|
-
* try {
|
|
169
|
-
* await riskyOperation();
|
|
170
|
-
* } catch (error) {
|
|
171
|
-
* trackError(error.message, {
|
|
172
|
-
* stack: error.stack,
|
|
173
|
-
* error_type: error.name,
|
|
174
|
-
* context: "checkout_flow"
|
|
175
|
-
* });
|
|
176
|
-
* }
|
|
177
|
-
* ```
|
|
178
|
-
*/
|
|
179
|
-
declare function trackError(message: string, properties?: {
|
|
180
|
-
filename?: string;
|
|
181
|
-
lineno?: number;
|
|
182
|
-
colno?: number;
|
|
183
|
-
stack?: string;
|
|
184
|
-
error_type?: string;
|
|
185
|
-
[key: string]: string | number | boolean | null | undefined;
|
|
186
|
-
}): void;
|
|
187
|
-
/**
|
|
188
|
-
* Gets the anonymous user ID. Persists across sessions via localStorage.
|
|
189
|
-
* Useful for server-side identification or cross-domain tracking.
|
|
190
|
-
*
|
|
191
|
-
* @param urlParams - Optional URLSearchParams to check for `anonId` param (highest priority)
|
|
192
|
-
* @returns Anonymous ID or `null` if unavailable
|
|
193
|
-
*
|
|
194
|
-
* Priority: URL params → tracker instance → localStorage
|
|
195
|
-
*
|
|
196
|
-
* @example
|
|
197
|
-
* ```ts
|
|
198
|
-
* import { getAnonymousId } from "@databuddy/sdk";
|
|
199
|
-
*
|
|
200
|
-
* // Get from tracker
|
|
201
|
-
* const anonId = getAnonymousId();
|
|
202
|
-
*
|
|
203
|
-
* // Check URL params first (for cross-domain tracking)
|
|
204
|
-
* const params = new URLSearchParams(window.location.search);
|
|
205
|
-
* const anonId = getAnonymousId(params);
|
|
206
|
-
*
|
|
207
|
-
* // Pass to server
|
|
208
|
-
* await fetch("/api/identify", {
|
|
209
|
-
* body: JSON.stringify({ anonId })
|
|
210
|
-
* });
|
|
211
|
-
* ```
|
|
212
|
-
*/
|
|
213
|
-
declare function getAnonymousId(urlParams?: URLSearchParams): string | null;
|
|
214
|
-
/**
|
|
215
|
-
* Gets the current session ID. Resets after 30 min of inactivity.
|
|
216
|
-
* Useful for correlating events within a single browsing session.
|
|
217
|
-
*
|
|
218
|
-
* @param urlParams - Optional URLSearchParams to check for `sessionId` param (highest priority)
|
|
219
|
-
* @returns Session ID or `null` if unavailable
|
|
220
|
-
*
|
|
221
|
-
* Priority: URL params → tracker instance → sessionStorage
|
|
222
|
-
*
|
|
223
|
-
* @example
|
|
224
|
-
* ```ts
|
|
225
|
-
* import { getSessionId } from "@databuddy/sdk";
|
|
226
|
-
*
|
|
227
|
-
* const sessionId = getSessionId();
|
|
228
|
-
* console.log("Current session:", sessionId);
|
|
229
|
-
* ```
|
|
230
|
-
*/
|
|
231
|
-
declare function getSessionId(urlParams?: URLSearchParams): string | null;
|
|
232
|
-
/**
|
|
233
|
-
* Gets both anonymous ID and session ID in a single call.
|
|
234
|
-
*
|
|
235
|
-
* @param urlParams - Optional URLSearchParams to check for tracking params
|
|
236
|
-
* @returns Object with `anonId` and `sessionId` (either may be null)
|
|
237
|
-
*
|
|
238
|
-
* @example
|
|
239
|
-
* ```ts
|
|
240
|
-
* import { getTrackingIds } from "@databuddy/sdk";
|
|
241
|
-
*
|
|
242
|
-
* const { anonId, sessionId } = getTrackingIds();
|
|
243
|
-
*
|
|
244
|
-
* // Send to your backend
|
|
245
|
-
* await api.identify({ anonId, sessionId, userId: user.id });
|
|
246
|
-
* ```
|
|
247
|
-
*/
|
|
248
|
-
declare function getTrackingIds(urlParams?: URLSearchParams): {
|
|
249
|
-
anonId: string | null;
|
|
250
|
-
sessionId: string | null;
|
|
251
|
-
};
|
|
252
|
-
/**
|
|
253
|
-
* Returns tracking IDs as a URL query string for cross-domain tracking.
|
|
254
|
-
* Append to URLs when linking to other domains you own.
|
|
255
|
-
*
|
|
256
|
-
* @param urlParams - Optional URLSearchParams to preserve existing params
|
|
257
|
-
* @returns Query string like `"anonId=xxx&sessionId=yyy"` or empty string
|
|
258
|
-
*
|
|
259
|
-
* @example
|
|
260
|
-
* ```ts
|
|
261
|
-
* import { getTrackingParams } from "@databuddy/sdk";
|
|
262
|
-
*
|
|
263
|
-
* // Link to subdomain with tracking continuity
|
|
264
|
-
* const params = getTrackingParams();
|
|
265
|
-
* const url = `https://app.example.com/dashboard${params ? `?${params}` : ""}`;
|
|
266
|
-
*
|
|
267
|
-
* // In a component
|
|
268
|
-
* <a href={`https://shop.example.com?${getTrackingParams()}`}>
|
|
269
|
-
* Visit Shop
|
|
270
|
-
* </a>
|
|
271
|
-
* ```
|
|
272
|
-
*/
|
|
273
|
-
declare function getTrackingParams(urlParams?: URLSearchParams): string;
|
|
274
|
-
|
|
275
|
-
export { BrowserFlagStorage, CoreFlagsManager, DatabuddyConfig, DatabuddyTracker, FlagResult, FlagState, FlagsConfig, FlagsManager, FlagsManagerOptions, StorageInterface, 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,7 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export { e as
|
|
3
|
-
import { D as DatabuddyConfig, a as DatabuddyTracker } from '../shared/@databuddy/sdk.CeYE_kaj.js';
|
|
4
|
-
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.CeYE_kaj.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';
|
|
5
3
|
|
|
6
4
|
/**
|
|
7
5
|
* Auto-detect Databuddy client ID from environment variables
|
|
@@ -9,267 +7,7 @@ export { B as BaseEventProperties, d as DataAttributes, c as EventName, E as Eve
|
|
|
9
7
|
*/
|
|
10
8
|
declare function detectClientId(providedClientId?: string): string | undefined;
|
|
11
9
|
|
|
12
|
-
declare class BrowserFlagStorage implements StorageInterface {
|
|
13
|
-
private ttl;
|
|
14
|
-
get(key: string): any;
|
|
15
|
-
set(key: string, value: unknown): void;
|
|
16
|
-
getAll(): Record<string, unknown>;
|
|
17
|
-
clear(): void;
|
|
18
|
-
private getFromLocalStorage;
|
|
19
|
-
private setToLocalStorage;
|
|
20
|
-
private isExpired;
|
|
21
|
-
delete(key: string): void;
|
|
22
|
-
deleteMultiple(keys: string[]): void;
|
|
23
|
-
setAll(flags: Record<string, unknown>): void;
|
|
24
|
-
cleanupExpired(): void;
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
declare class CoreFlagsManager implements FlagsManager {
|
|
28
|
-
private config;
|
|
29
|
-
private storage?;
|
|
30
|
-
private onFlagsUpdate?;
|
|
31
|
-
private onConfigUpdate?;
|
|
32
|
-
private memoryFlags;
|
|
33
|
-
private pendingFlags;
|
|
34
|
-
constructor(options: FlagsManagerOptions);
|
|
35
|
-
private withDefaults;
|
|
36
|
-
private initialize;
|
|
37
|
-
private loadCachedFlags;
|
|
38
|
-
fetchAllFlags(): Promise<void>;
|
|
39
|
-
getFlag(key: string): Promise<FlagResult>;
|
|
40
|
-
private fetchFlag;
|
|
41
|
-
isEnabled(key: string): FlagState;
|
|
42
|
-
refresh(forceClear?: boolean): void;
|
|
43
|
-
updateUser(user: FlagsConfig["user"]): void;
|
|
44
|
-
updateConfig(config: FlagsConfig): void;
|
|
45
|
-
getMemoryFlags(): Record<string, FlagResult>;
|
|
46
|
-
getPendingFlags(): Set<string>;
|
|
47
|
-
private notifyFlagsUpdate;
|
|
48
|
-
}
|
|
49
|
-
|
|
50
10
|
declare function isScriptInjected(): boolean;
|
|
51
11
|
declare function createScript({ scriptUrl, sdkVersion, clientSecret, filter, debug, ...props }: DatabuddyConfig): HTMLScriptElement;
|
|
52
12
|
|
|
53
|
-
|
|
54
|
-
* Checks if the Databuddy tracker script has loaded and is available.
|
|
55
|
-
* Use this before calling tracking functions in conditional scenarios.
|
|
56
|
-
*
|
|
57
|
-
* @returns `true` if tracker is available, `false` if not loaded or on server
|
|
58
|
-
*
|
|
59
|
-
* @example
|
|
60
|
-
* ```ts
|
|
61
|
-
* import { isTrackerAvailable, track } from "@databuddy/sdk";
|
|
62
|
-
*
|
|
63
|
-
* if (isTrackerAvailable()) {
|
|
64
|
-
* track("feature_used", { feature: "export" });
|
|
65
|
-
* }
|
|
66
|
-
* ```
|
|
67
|
-
*/
|
|
68
|
-
declare function isTrackerAvailable(): boolean;
|
|
69
|
-
/**
|
|
70
|
-
* Returns the raw Databuddy tracker instance for advanced use cases.
|
|
71
|
-
* Prefer using the exported functions (`track`, `flush`, etc.) instead.
|
|
72
|
-
*
|
|
73
|
-
* @returns Tracker instance or `null` if not available
|
|
74
|
-
*
|
|
75
|
-
* @example
|
|
76
|
-
* ```ts
|
|
77
|
-
* import { getTracker, getAnonymousId, getSessionId } from "@databuddy/sdk";
|
|
78
|
-
*
|
|
79
|
-
* const tracker = getTracker();
|
|
80
|
-
* if (tracker) {
|
|
81
|
-
* // Access tracker methods
|
|
82
|
-
* tracker.track("event", { prop: "value" });
|
|
83
|
-
*
|
|
84
|
-
* // Get IDs using dedicated functions
|
|
85
|
-
* const anonId = getAnonymousId();
|
|
86
|
-
* const sessionId = getSessionId();
|
|
87
|
-
* }
|
|
88
|
-
* ```
|
|
89
|
-
*/
|
|
90
|
-
declare function getTracker(): DatabuddyTracker | null;
|
|
91
|
-
/**
|
|
92
|
-
* Tracks a custom event with optional properties.
|
|
93
|
-
* Events are batched and sent efficiently to minimize network overhead.
|
|
94
|
-
* Safe to call on server (no-op) or before tracker loads.
|
|
95
|
-
*
|
|
96
|
-
* @param name - Event name (e.g., "button_click", "purchase", "signup")
|
|
97
|
-
* @param properties - Key-value pairs of event data
|
|
98
|
-
*
|
|
99
|
-
* @example
|
|
100
|
-
* ```ts
|
|
101
|
-
* import { track } from "@databuddy/sdk";
|
|
102
|
-
*
|
|
103
|
-
* // Simple event
|
|
104
|
-
* track("signup_started");
|
|
105
|
-
*
|
|
106
|
-
* // Event with properties
|
|
107
|
-
* track("item_purchased", {
|
|
108
|
-
* itemId: "sku-123",
|
|
109
|
-
* price: 29.99,
|
|
110
|
-
* currency: "USD"
|
|
111
|
-
* });
|
|
112
|
-
*
|
|
113
|
-
* // In a React component
|
|
114
|
-
* function CheckoutButton() {
|
|
115
|
-
* return (
|
|
116
|
-
* <button onClick={() => track("checkout_clicked", { cartSize: 3 })}>
|
|
117
|
-
* Checkout
|
|
118
|
-
* </button>
|
|
119
|
-
* );
|
|
120
|
-
* }
|
|
121
|
-
* ```
|
|
122
|
-
*/
|
|
123
|
-
declare function track(name: string, properties?: Record<string, unknown>): void;
|
|
124
|
-
/** @deprecated Use `track()` instead. Will be removed in v3.0. */
|
|
125
|
-
declare function trackCustomEvent(name: string, properties?: Record<string, unknown>): void;
|
|
126
|
-
/**
|
|
127
|
-
* Clears the current user session and generates new anonymous/session IDs.
|
|
128
|
-
* Use after logout to ensure the next user gets a fresh identity.
|
|
129
|
-
*
|
|
130
|
-
* @example
|
|
131
|
-
* ```ts
|
|
132
|
-
* import { clear } from "@databuddy/sdk";
|
|
133
|
-
*
|
|
134
|
-
* async function handleLogout() {
|
|
135
|
-
* await signOut();
|
|
136
|
-
* clear(); // Reset tracking identity
|
|
137
|
-
* router.push("/login");
|
|
138
|
-
* }
|
|
139
|
-
* ```
|
|
140
|
-
*/
|
|
141
|
-
declare function clear(): void;
|
|
142
|
-
/**
|
|
143
|
-
* Forces all queued events to be sent immediately.
|
|
144
|
-
* Useful before navigation or when you need to ensure events are captured.
|
|
145
|
-
*
|
|
146
|
-
* @example
|
|
147
|
-
* ```ts
|
|
148
|
-
* import { track, flush } from "@databuddy/sdk";
|
|
149
|
-
*
|
|
150
|
-
* function handleExternalLink(url: string) {
|
|
151
|
-
* track("external_link_clicked", { url });
|
|
152
|
-
* flush(); // Ensure event is sent before leaving
|
|
153
|
-
* window.location.href = url;
|
|
154
|
-
* }
|
|
155
|
-
* ```
|
|
156
|
-
*/
|
|
157
|
-
declare function flush(): void;
|
|
158
|
-
/**
|
|
159
|
-
* Tracks an error event. Convenience wrapper around `track("error", ...)`.
|
|
160
|
-
*
|
|
161
|
-
* @param message - Error message
|
|
162
|
-
* @param properties - Additional error context (filename, line number, stack trace)
|
|
163
|
-
*
|
|
164
|
-
* @example
|
|
165
|
-
* ```ts
|
|
166
|
-
* import { trackError } from "@databuddy/sdk";
|
|
167
|
-
*
|
|
168
|
-
* try {
|
|
169
|
-
* await riskyOperation();
|
|
170
|
-
* } catch (error) {
|
|
171
|
-
* trackError(error.message, {
|
|
172
|
-
* stack: error.stack,
|
|
173
|
-
* error_type: error.name,
|
|
174
|
-
* context: "checkout_flow"
|
|
175
|
-
* });
|
|
176
|
-
* }
|
|
177
|
-
* ```
|
|
178
|
-
*/
|
|
179
|
-
declare function trackError(message: string, properties?: {
|
|
180
|
-
filename?: string;
|
|
181
|
-
lineno?: number;
|
|
182
|
-
colno?: number;
|
|
183
|
-
stack?: string;
|
|
184
|
-
error_type?: string;
|
|
185
|
-
[key: string]: string | number | boolean | null | undefined;
|
|
186
|
-
}): void;
|
|
187
|
-
/**
|
|
188
|
-
* Gets the anonymous user ID. Persists across sessions via localStorage.
|
|
189
|
-
* Useful for server-side identification or cross-domain tracking.
|
|
190
|
-
*
|
|
191
|
-
* @param urlParams - Optional URLSearchParams to check for `anonId` param (highest priority)
|
|
192
|
-
* @returns Anonymous ID or `null` if unavailable
|
|
193
|
-
*
|
|
194
|
-
* Priority: URL params → tracker instance → localStorage
|
|
195
|
-
*
|
|
196
|
-
* @example
|
|
197
|
-
* ```ts
|
|
198
|
-
* import { getAnonymousId } from "@databuddy/sdk";
|
|
199
|
-
*
|
|
200
|
-
* // Get from tracker
|
|
201
|
-
* const anonId = getAnonymousId();
|
|
202
|
-
*
|
|
203
|
-
* // Check URL params first (for cross-domain tracking)
|
|
204
|
-
* const params = new URLSearchParams(window.location.search);
|
|
205
|
-
* const anonId = getAnonymousId(params);
|
|
206
|
-
*
|
|
207
|
-
* // Pass to server
|
|
208
|
-
* await fetch("/api/identify", {
|
|
209
|
-
* body: JSON.stringify({ anonId })
|
|
210
|
-
* });
|
|
211
|
-
* ```
|
|
212
|
-
*/
|
|
213
|
-
declare function getAnonymousId(urlParams?: URLSearchParams): string | null;
|
|
214
|
-
/**
|
|
215
|
-
* Gets the current session ID. Resets after 30 min of inactivity.
|
|
216
|
-
* Useful for correlating events within a single browsing session.
|
|
217
|
-
*
|
|
218
|
-
* @param urlParams - Optional URLSearchParams to check for `sessionId` param (highest priority)
|
|
219
|
-
* @returns Session ID or `null` if unavailable
|
|
220
|
-
*
|
|
221
|
-
* Priority: URL params → tracker instance → sessionStorage
|
|
222
|
-
*
|
|
223
|
-
* @example
|
|
224
|
-
* ```ts
|
|
225
|
-
* import { getSessionId } from "@databuddy/sdk";
|
|
226
|
-
*
|
|
227
|
-
* const sessionId = getSessionId();
|
|
228
|
-
* console.log("Current session:", sessionId);
|
|
229
|
-
* ```
|
|
230
|
-
*/
|
|
231
|
-
declare function getSessionId(urlParams?: URLSearchParams): string | null;
|
|
232
|
-
/**
|
|
233
|
-
* Gets both anonymous ID and session ID in a single call.
|
|
234
|
-
*
|
|
235
|
-
* @param urlParams - Optional URLSearchParams to check for tracking params
|
|
236
|
-
* @returns Object with `anonId` and `sessionId` (either may be null)
|
|
237
|
-
*
|
|
238
|
-
* @example
|
|
239
|
-
* ```ts
|
|
240
|
-
* import { getTrackingIds } from "@databuddy/sdk";
|
|
241
|
-
*
|
|
242
|
-
* const { anonId, sessionId } = getTrackingIds();
|
|
243
|
-
*
|
|
244
|
-
* // Send to your backend
|
|
245
|
-
* await api.identify({ anonId, sessionId, userId: user.id });
|
|
246
|
-
* ```
|
|
247
|
-
*/
|
|
248
|
-
declare function getTrackingIds(urlParams?: URLSearchParams): {
|
|
249
|
-
anonId: string | null;
|
|
250
|
-
sessionId: string | null;
|
|
251
|
-
};
|
|
252
|
-
/**
|
|
253
|
-
* Returns tracking IDs as a URL query string for cross-domain tracking.
|
|
254
|
-
* Append to URLs when linking to other domains you own.
|
|
255
|
-
*
|
|
256
|
-
* @param urlParams - Optional URLSearchParams to preserve existing params
|
|
257
|
-
* @returns Query string like `"anonId=xxx&sessionId=yyy"` or empty string
|
|
258
|
-
*
|
|
259
|
-
* @example
|
|
260
|
-
* ```ts
|
|
261
|
-
* import { getTrackingParams } from "@databuddy/sdk";
|
|
262
|
-
*
|
|
263
|
-
* // Link to subdomain with tracking continuity
|
|
264
|
-
* const params = getTrackingParams();
|
|
265
|
-
* const url = `https://app.example.com/dashboard${params ? `?${params}` : ""}`;
|
|
266
|
-
*
|
|
267
|
-
* // In a component
|
|
268
|
-
* <a href={`https://shop.example.com?${getTrackingParams()}`}>
|
|
269
|
-
* Visit Shop
|
|
270
|
-
* </a>
|
|
271
|
-
* ```
|
|
272
|
-
*/
|
|
273
|
-
declare function getTrackingParams(urlParams?: URLSearchParams): string;
|
|
274
|
-
|
|
275
|
-
export { BrowserFlagStorage, CoreFlagsManager, DatabuddyConfig, DatabuddyTracker, FlagResult, FlagState, FlagsConfig, FlagsManager, FlagsManagerOptions, StorageInterface, 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 };
|