@databuddy/sdk 2.3.27 → 2.3.28

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.
@@ -1,4 +1,4 @@
1
- export { c as createScript, i as isScriptInjected } from '../shared/@databuddy/sdk.ClnhxS25.mjs';
1
+ export { c as createScript, i as isScriptInjected } from '../shared/@databuddy/sdk.urY7MmVr.mjs';
2
2
 
3
3
  function detectClientId(providedClientId) {
4
4
  if (providedClientId) {
@@ -234,6 +234,10 @@ declare class Databuddy {
234
234
  * ```
235
235
  */
236
236
  track(event: CustomEventInput): Promise<EventResponse>;
237
+ /**
238
+ * Convert BatchEventInput to CustomEventSpan format expected by /events endpoint
239
+ */
240
+ private toCustomEventSpan;
237
241
  private send;
238
242
  private scheduleFlush;
239
243
  /**
@@ -234,6 +234,10 @@ declare class Databuddy {
234
234
  * ```
235
235
  */
236
236
  track(event: CustomEventInput): Promise<EventResponse>;
237
+ /**
238
+ * Convert BatchEventInput to CustomEventSpan format expected by /events endpoint
239
+ */
240
+ private toCustomEventSpan;
237
241
  private send;
238
242
  private scheduleFlush;
239
243
  /**
@@ -419,20 +419,35 @@ class Databuddy {
419
419
  }
420
420
  return { success: true };
421
421
  }
422
+ /**
423
+ * Convert BatchEventInput to CustomEventSpan format expected by /events endpoint
424
+ */
425
+ toCustomEventSpan(event) {
426
+ const timestamp = event.timestamp ? Math.floor(event.timestamp) : Date.now();
427
+ return {
428
+ timestamp,
429
+ path: "",
430
+ eventName: event.name,
431
+ anonymousId: event.anonymousId ?? null,
432
+ sessionId: event.sessionId ?? null,
433
+ properties: event.properties ?? null
434
+ };
435
+ }
422
436
  async send(event) {
423
437
  try {
424
- const url = `${this.apiUrl}/?client_id=${encodeURIComponent(this.clientId)}`;
438
+ const url = `${this.apiUrl}/events?client_id=${encodeURIComponent(this.clientId)}`;
439
+ const customEventSpan = this.toCustomEventSpan(event);
425
440
  this.logger.info("\u{1F4E4} SENDING SINGLE EVENT:", {
426
- name: event.name,
427
- properties: JSON.stringify(event.properties, null, 2),
428
- propertiesCount: Object.keys(event.properties || {}).length
441
+ eventName: customEventSpan.eventName,
442
+ properties: JSON.stringify(customEventSpan.properties, null, 2),
443
+ propertiesCount: Object.keys(customEventSpan.properties || {}).length
429
444
  });
430
445
  const response = await fetch(url, {
431
446
  method: "POST",
432
447
  headers: {
433
448
  "Content-Type": "application/json"
434
449
  },
435
- body: JSON.stringify(event)
450
+ body: JSON.stringify([customEventSpan])
436
451
  });
437
452
  if (!response.ok) {
438
453
  const errorText = await response.text().catch(() => "Unknown error");
@@ -578,17 +593,20 @@ class Databuddy {
578
593
  };
579
594
  }
580
595
  try {
581
- const url = `${this.apiUrl}/batch?client_id=${encodeURIComponent(this.clientId)}`;
596
+ const url = `${this.apiUrl}/events?client_id=${encodeURIComponent(this.clientId)}`;
597
+ const customEventSpans = processedEvents.map(
598
+ (event) => this.toCustomEventSpan(event)
599
+ );
582
600
  this.logger.info("\u{1F4E6} SENDING BATCH EVENTS:", {
583
- count: processedEvents.length,
584
- firstEventName: processedEvents[0]?.name,
601
+ count: customEventSpans.length,
602
+ firstEventName: customEventSpans[0]?.eventName,
585
603
  firstEventProperties: JSON.stringify(
586
- processedEvents[0]?.properties,
604
+ customEventSpans[0]?.properties,
587
605
  null,
588
606
  2
589
607
  ),
590
608
  firstEventPropertiesCount: Object.keys(
591
- processedEvents[0]?.properties || {}
609
+ customEventSpans[0]?.properties || {}
592
610
  ).length
593
611
  });
594
612
  const response = await fetch(url, {
@@ -596,7 +614,7 @@ class Databuddy {
596
614
  headers: {
597
615
  "Content-Type": "application/json"
598
616
  },
599
- body: JSON.stringify(processedEvents)
617
+ body: JSON.stringify(customEventSpans)
600
618
  });
601
619
  if (!response.ok) {
602
620
  const errorText = await response.text().catch(() => "Unknown error");
@@ -2,7 +2,7 @@
2
2
 
3
3
  import { detectClientId } from '../core/index.mjs';
4
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.ClnhxS25.mjs';
5
+ import { i as isScriptInjected, c as createScript } from '../shared/@databuddy/sdk.urY7MmVr.mjs';
6
6
  import React, { useRef, useMemo, useEffect, useSyncExternalStore, createContext, useContext } from 'react';
7
7
  import { B as BrowserFlagStorage, C as CoreFlagsManager } from '../shared/@databuddy/sdk.DE24-JrU.mjs';
8
8
  import { l as logger } from '../shared/@databuddy/sdk.CALvx07o.mjs';
@@ -1,4 +1,4 @@
1
- const version = "2.3.26";
1
+ const version = "2.3.28";
2
2
 
3
3
  const INJECTED_SCRIPT_ATTRIBUTE = "data-databuddy-injected";
4
4
  function isScriptInjected() {
@@ -1,5 +1,5 @@
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.ClnhxS25.mjs';
2
+ import { i as isScriptInjected, c as createScript } from '../shared/@databuddy/sdk.urY7MmVr.mjs';
3
3
  import { B as BrowserFlagStorage, C as CoreFlagsManager } from '../shared/@databuddy/sdk.DE24-JrU.mjs';
4
4
  import '../shared/@databuddy/sdk.CALvx07o.mjs';
5
5
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@databuddy/sdk",
3
- "version": "2.3.27",
3
+ "version": "2.3.28",
4
4
  "description": "Official Databuddy Analytics SDK",
5
5
  "main": "./dist/core/index.mjs",
6
6
  "types": "./dist/core/index.d.ts",