Skip to content

Commit 9e3f76c

Browse files
committed
fix: basket
1 parent 843104d commit 9e3f76c

File tree

2 files changed

+34
-10
lines changed

2 files changed

+34
-10
lines changed

apps/basket/src/routes/basket.ts

Lines changed: 29 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -160,10 +160,15 @@ async function insertError(
160160
userAgent: string,
161161
ip: string
162162
): Promise<void> {
163-
const eventId = sanitizeString(
163+
let eventId = sanitizeString(
164164
errorData.payload.eventId,
165165
VALIDATION_LIMITS.SHORT_STRING_MAX_LENGTH
166166
);
167+
168+
if (!eventId) {
169+
eventId = randomUUID();
170+
}
171+
167172
if (await checkDuplicate(eventId, 'error')) {
168173
return;
169174
}
@@ -234,11 +239,15 @@ async function insertWebVitals(
234239
userAgent: string,
235240
ip: string
236241
): Promise<void> {
237-
const eventId = sanitizeString(
242+
let eventId = sanitizeString(
238243
vitalsData.payload.eventId,
239244
VALIDATION_LIMITS.SHORT_STRING_MAX_LENGTH
240245
);
241246

247+
if (!eventId) {
248+
eventId = randomUUID();
249+
}
250+
242251
if (await checkDuplicate(eventId, 'web_vitals')) {
243252
return;
244253
}
@@ -298,10 +307,15 @@ async function insertCustomEvent(
298307
userAgent: string,
299308
ip: string
300309
): Promise<void> {
301-
const eventId = sanitizeString(
310+
let eventId = sanitizeString(
302311
customData.eventId,
303312
VALIDATION_LIMITS.SHORT_STRING_MAX_LENGTH
304313
);
314+
q
315+
if (!eventId) {
316+
eventId = randomUUID();
317+
}
318+
305319
if (await checkDuplicate(eventId, 'custom')) {
306320
return;
307321
}
@@ -348,10 +362,15 @@ async function insertOutgoingLink(
348362
userAgent: string,
349363
ip: string
350364
): Promise<void> {
351-
const eventId = sanitizeString(
365+
let eventId = sanitizeString(
352366
linkData.eventId,
353367
VALIDATION_LIMITS.SHORT_STRING_MAX_LENGTH
354368
);
369+
370+
if (!eventId) {
371+
eventId = randomUUID();
372+
}
373+
355374
if (await checkDuplicate(eventId, 'outgoing_link')) {
356375
return;
357376
}
@@ -396,10 +415,15 @@ async function insertTrackEvent(
396415
userAgent: string,
397416
ip: string
398417
): Promise<void> {
399-
const eventId = sanitizeString(
418+
let eventId = sanitizeString(
400419
trackData.eventId,
401420
VALIDATION_LIMITS.SHORT_STRING_MAX_LENGTH
402421
);
422+
423+
if (!eventId) {
424+
eventId = randomUUID();
425+
}
426+
403427
if (await checkDuplicate(eventId, 'track')) {
404428
return;
405429
}
@@ -472,11 +496,7 @@ async function insertTrackEvent(
472496
time_on_page: trackData.time_on_page,
473497
scroll_depth: trackData.scroll_depth,
474498
interaction_count: trackData.interaction_count,
475-
exit_intent: trackData.exit_intent || 0,
476499
page_count: trackData.page_count || 1,
477-
is_bounce: trackData.is_bounce || 0,
478-
has_exit_intent: trackData.has_exit_intent,
479-
page_size: trackData.page_size,
480500

481501
utm_source: trackData.utm_source,
482502
utm_medium: trackData.utm_medium,

apps/docs/content/docs/api.mdx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -316,7 +316,7 @@ Track custom events programmatically using the basket endpoint.
316316

317317
**Required Fields:**
318318
- `type`: Must be "custom"
319-
- `eventId`: Unique identifier for the event (max 512 characters)
319+
- `eventId`: Unique identifier for the event (max 512 characters) - used for deduplication (auto-generated if empty)
320320
- `name`: Event name (1-128 characters)
321321

322322
**Optional Fields:**
@@ -329,6 +329,10 @@ Track custom events programmatically using the basket endpoint.
329329
**Simple tracking**: For basic event tracking, you only need `type`, `eventId`, and `name`. The `anonymousId` and `sessionId` are useful for user journey tracking but not required for simple conversion or action tracking.
330330
</Callout>
331331

332+
<Callout type="info">
333+
**Event ID Generation**: The `eventId` is a custom string you provide for deduplication. It can be any unique identifier (UUID, timestamp-based, etc.). If you send the same `eventId` twice, the second event will be ignored. This prevents duplicate events from network retries or accidental double-sends.
334+
</Callout>
335+
332336
**Response:**
333337

334338
<CodeBlock

0 commit comments

Comments
 (0)