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:53:04 -03:00
parent d8788dab2b
commit 243acb4aab
3 changed files with 19 additions and 0 deletions

View file

@ -2,6 +2,7 @@ import { useState, type FormEvent } from 'react';
import { motion } from 'framer-motion';
import { Check, ShieldCheck, Gift, ArrowRight, ImageIcon, Download, Clock, Headphones, Zap, Loader2 } from 'lucide-react';
import { cn } from '../lib/utils';
import { trackLead } from '../utils/trackLead';
export default function Offer() {
const benefits = [
@ -30,6 +31,7 @@ export default function Offer() {
setIsLoading(true);
setError('');
trackLead(email, 'landing-30', 'Kit Festa');
window.location.href = `https://festamagicaia.com.br/checkout?plan=popular&source=landing-30&email=${encodeURIComponent(email)}`;
};

View file

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