Add constants and improve event tracking

This commit is contained in:
Víctor Falcón 2025-11-25 12:00:14 +01:00
parent 4c41d76ebe
commit 76e975bd18
3 changed files with 9 additions and 3 deletions

View File

@ -0,0 +1,2 @@
export const LEAD_FUNNEL_EVENT_UUID = '9668a06c-dee9-47a8-9bee-eaaa2a3a5915';

View File

@ -41,7 +41,9 @@ export async function trackEvent(
queryParams.append(key, String(value));
}
});
await fetch(`${url}?${queryParams.toString()}`);
await fetch(`${url}?${queryParams.toString()}`, {
keepalive: true,
});
} else {
await fetch(url, {
method: 'POST',
@ -49,6 +51,7 @@ export async function trackEvent(
'Content-Type': 'application/json',
},
body: JSON.stringify(payload),
keepalive: true,
});
}
}

View File

@ -20,6 +20,7 @@ import {
} from 'lucide-react';
import { useEffect, useRef } from 'react';
import { trackEvent } from '@/lib/track-event';
import { LEAD_FUNNEL_EVENT_UUID } from '@/lib/constants';
export default function Welcome({
canRegister = true,
@ -37,7 +38,7 @@ export default function Welcome({
return;
}
visitTrackedRef.current = true;
trackEvent('9668a06c-dee9-47a8-9bee-eaaa2a3a5915', {
trackEvent(LEAD_FUNNEL_EVENT_UUID, {
step: 'Visit',
});
}, []);
@ -174,7 +175,7 @@ export default function Welcome({
className="flex sm:items-center justify-center flex-col gap-2 sm:flex-row"
onSuccess={async () => {
const emailValue = emailInputRef.current?.value || '';
await trackEvent('9668a06c-dee9-47a8-9bee-eaaa2a3a5915', {
await trackEvent(LEAD_FUNNEL_EVENT_UUID, {
step: 'Lead Created',
email: emailValue,
});