@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.
@@ -13,7 +13,7 @@
13
13
  * />
14
14
  * ```
15
15
  */
16
- type DatabuddyConfig = {
16
+ interface DatabuddyConfig {
17
17
  /**
18
18
  * Your Databuddy project client ID.
19
19
  * If not provided, will automatically detect from NEXT_PUBLIC_DATABUDDY_CLIENT_ID environment variable.
@@ -149,11 +149,11 @@ type DatabuddyConfig = {
149
149
  skipPatterns?: string[];
150
150
  /** Array of glob patterns to mask sensitive paths (e.g., ['/users/*']) */
151
151
  maskPatterns?: string[];
152
- };
152
+ }
153
153
  /**
154
154
  * Base event properties that can be attached to any event
155
155
  */
156
- type BaseEventProperties = {
156
+ interface BaseEventProperties {
157
157
  /** Page URL */
158
158
  __path?: string;
159
159
  /** Page title */
@@ -180,7 +180,7 @@ type BaseEventProperties = {
180
180
  utm_campaign?: string;
181
181
  utm_term?: string;
182
182
  utm_content?: string;
183
- };
183
+ }
184
184
  /**
185
185
  * Custom event properties that can be attached to any event
186
186
  */
@@ -191,7 +191,7 @@ interface EventProperties extends BaseEventProperties {
191
191
  /**
192
192
  * Pre-defined event types with their specific properties
193
193
  */
194
- type EventTypeMap = {
194
+ interface EventTypeMap {
195
195
  screen_view: {
196
196
  time_on_page?: number;
197
197
  scroll_depth?: number;
@@ -244,7 +244,7 @@ type EventTypeMap = {
244
244
  error_type?: string;
245
245
  };
246
246
  [eventName: string]: EventProperties;
247
- };
247
+ }
248
248
  /**
249
249
  * Available event names
250
250
  */
@@ -266,7 +266,7 @@ type PropertiesForEvent<T extends EventName> = T extends keyof EventTypeMap ? Ev
266
266
  * const options = window.databuddy.options;
267
267
  * ```
268
268
  */
269
- type DatabuddyTracker = {
269
+ interface DatabuddyTracker {
270
270
  /**
271
271
  * Track a custom event.
272
272
  * @param eventName - Name of the event (e.g., "purchase", "signup")
@@ -305,7 +305,7 @@ type DatabuddyTracker = {
305
305
  * Current tracker configuration options.
306
306
  */
307
307
  options: DatabuddyConfig;
308
- };
308
+ }
309
309
  /**
310
310
  * Global window interface extensions
311
311
  */
@@ -348,12 +348,12 @@ declare global {
348
348
  * </a>
349
349
  * ```
350
350
  */
351
- type DataAttributes = {
351
+ interface DataAttributes {
352
352
  /** Event name to track when element is clicked */
353
353
  "data-track": string;
354
354
  /** Additional data attributes (auto-converted from kebab-case to camelCase) */
355
355
  [key: `data-${string}`]: string;
356
- };
356
+ }
357
357
  /**
358
358
  * Utility types for creating typed event tracking functions
359
359
  */
@@ -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
- export type { BaseEventProperties as B, DatabuddyConfig as D, EventProperties as E, PropertiesForEvent as P, ScreenViewFunction as S, TrackFunction as T, DatabuddyTracker as a, EventTypeMap as b, EventName as c, DataAttributes as d, SetGlobalPropertiesFunction as e };
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 };
@@ -13,7 +13,7 @@
13
13
  * />
14
14
  * ```
15
15
  */
16
- type DatabuddyConfig = {
16
+ interface DatabuddyConfig {
17
17
  /**
18
18
  * Your Databuddy project client ID.
19
19
  * If not provided, will automatically detect from NEXT_PUBLIC_DATABUDDY_CLIENT_ID environment variable.
@@ -149,11 +149,11 @@ type DatabuddyConfig = {
149
149
  skipPatterns?: string[];
150
150
  /** Array of glob patterns to mask sensitive paths (e.g., ['/users/*']) */
151
151
  maskPatterns?: string[];
152
- };
152
+ }
153
153
  /**
154
154
  * Base event properties that can be attached to any event
155
155
  */
156
- type BaseEventProperties = {
156
+ interface BaseEventProperties {
157
157
  /** Page URL */
158
158
  __path?: string;
159
159
  /** Page title */
@@ -180,7 +180,7 @@ type BaseEventProperties = {
180
180
  utm_campaign?: string;
181
181
  utm_term?: string;
182
182
  utm_content?: string;
183
- };
183
+ }
184
184
  /**
185
185
  * Custom event properties that can be attached to any event
186
186
  */
@@ -191,7 +191,7 @@ interface EventProperties extends BaseEventProperties {
191
191
  /**
192
192
  * Pre-defined event types with their specific properties
193
193
  */
194
- type EventTypeMap = {
194
+ interface EventTypeMap {
195
195
  screen_view: {
196
196
  time_on_page?: number;
197
197
  scroll_depth?: number;
@@ -244,7 +244,7 @@ type EventTypeMap = {
244
244
  error_type?: string;
245
245
  };
246
246
  [eventName: string]: EventProperties;
247
- };
247
+ }
248
248
  /**
249
249
  * Available event names
250
250
  */
@@ -266,7 +266,7 @@ type PropertiesForEvent<T extends EventName> = T extends keyof EventTypeMap ? Ev
266
266
  * const options = window.databuddy.options;
267
267
  * ```
268
268
  */
269
- type DatabuddyTracker = {
269
+ interface DatabuddyTracker {
270
270
  /**
271
271
  * Track a custom event.
272
272
  * @param eventName - Name of the event (e.g., "purchase", "signup")
@@ -305,7 +305,7 @@ type DatabuddyTracker = {
305
305
  * Current tracker configuration options.
306
306
  */
307
307
  options: DatabuddyConfig;
308
- };
308
+ }
309
309
  /**
310
310
  * Global window interface extensions
311
311
  */
@@ -348,12 +348,12 @@ declare global {
348
348
  * </a>
349
349
  * ```
350
350
  */
351
- type DataAttributes = {
351
+ interface DataAttributes {
352
352
  /** Event name to track when element is clicked */
353
353
  "data-track": string;
354
354
  /** Additional data attributes (auto-converted from kebab-case to camelCase) */
355
355
  [key: `data-${string}`]: string;
356
- };
356
+ }
357
357
  /**
358
358
  * Utility types for creating typed event tracking functions
359
359
  */
@@ -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
- export type { BaseEventProperties as B, DatabuddyConfig as D, EventProperties as E, PropertiesForEvent as P, ScreenViewFunction as S, TrackFunction as T, DatabuddyTracker as a, EventTypeMap as b, EventName as c, DataAttributes as d, SetGlobalPropertiesFunction as e };
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 };
@@ -0,0 +1,35 @@
1
+ const version = "2.3.21";
2
+
3
+ const INJECTED_SCRIPT_ATTRIBUTE = "data-databuddy-injected";
4
+ function isScriptInjected() {
5
+ return !!document.querySelector(`script[${INJECTED_SCRIPT_ATTRIBUTE}]`);
6
+ }
7
+ function createScript({
8
+ scriptUrl,
9
+ sdkVersion,
10
+ clientSecret,
11
+ filter,
12
+ debug,
13
+ ...props
14
+ }) {
15
+ const script = document.createElement("script");
16
+ script.src = scriptUrl || "https://cdn.databuddy.cc/databuddy.js";
17
+ script.async = true;
18
+ script.crossOrigin = "anonymous";
19
+ script.setAttribute(INJECTED_SCRIPT_ATTRIBUTE, "true");
20
+ script.setAttribute("data-sdk-version", sdkVersion || version);
21
+ for (const [key, value] of Object.entries(props)) {
22
+ if (value === void 0 || value === null) {
23
+ continue;
24
+ }
25
+ const dataKey = `data-${key.replace(/([A-Z])/g, "-$1").toLowerCase()}`;
26
+ if (Array.isArray(value) || value && typeof value === "object") {
27
+ script.setAttribute(dataKey, JSON.stringify(value));
28
+ } else {
29
+ script.setAttribute(dataKey, String(value));
30
+ }
31
+ }
32
+ return script;
33
+ }
34
+
35
+ export { createScript as c, isScriptInjected as i };