feat: captura o email assim que digitado, antes do checkout

Dispara trackLead pro /api/checkout/track-lead do app principal no
momento que o usuário informa o email (landing + funil), não só
quando chega a tentar pagar. Fire-and-forget, não trava a navegação.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
Marcio Bevervanso 2026-07-09 16:52:28 -03:00
parent da4f3195b7
commit f2e74cfc24
3 changed files with 19 additions and 0 deletions

View file

@ -2,6 +2,7 @@ import { useState, type FormEvent } from 'react';
import { Check, ShieldCheck, Gift, ArrowRight, Loader2 } from 'lucide-react'; import { Check, ShieldCheck, Gift, ArrowRight, Loader2 } from 'lucide-react';
import { cn } from '../lib/utils'; import { cn } from '../lib/utils';
import { useT, getLang } from '../i18n'; import { useT, getLang } from '../i18n';
import { trackLead } from '../utils/trackLead';
export default function Offer() { export default function Offer() {
const t = useT(); const t = useT();
@ -29,6 +30,7 @@ export default function Offer() {
setError(''); setError('');
const isBR = getLang() === 'pt'; const isBR = getLang() === 'pt';
trackLead(email, isBR ? 'landing' : 'landing-international', 'Starter');
if (!isBR) { if (!isBR) {
// Internacional: Starter USD $6.99 → Stripe direto // Internacional: Starter USD $6.99 → Stripe direto

View file

@ -1,5 +1,6 @@
import { useState, useEffect, useRef, type FormEvent } from 'react'; import { useState, useEffect, useRef, type FormEvent } from 'react';
import { Loader2, Send } from 'lucide-react'; import { Loader2, Send } from 'lucide-react';
import { trackLead } from '../utils/trackLead';
type MessageType = 'text' | 'audio' | 'image' | 'video' | 'embed'; type MessageType = 'text' | 'audio' | 'image' | 'video' | 'embed';
@ -274,6 +275,8 @@ export default function WhatsAppFunnel() {
(window as any).fbq('track', 'InitiateCheckout'); (window as any).fbq('track', 'InitiateCheckout');
} }
trackLead(emailInput, 'funil', 'Starter');
setTimeout(() => { setTimeout(() => {
window.location.href = `https://festamagicaia.com.br/checkout?plan=starter&source=funil&email=${encodeURIComponent(emailInput)}`; window.location.href = `https://festamagicaia.com.br/checkout?plan=starter&source=funil&email=${encodeURIComponent(emailInput)}`;
}, 800); }, 800);

14
src/utils/trackLead.ts Normal file
View file

@ -0,0 +1,14 @@
// Dispara best-effort, sem travar a navegação — se falhar, ninguém percebe.
// keepalive garante que a requisição sobrevive ao redirect que vem logo em seguida.
export function trackLead(email: string, source: string, planName?: string) {
try {
fetch('https://www.festamagicaia.com.br/api/checkout/track-lead', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ email, source, planName }),
keepalive: true,
}).catch(() => {});
} catch {
// no-op
}
}