"use client"; import { useState, useEffect, useRef } from "react"; import Link from "next/link"; import Button from "@/components/ui/Button"; export default function ExitIntentPopup() { const [show, setShow] = useState(false); const [dismissed, setDismissed] = useState(false); const lastScrollY = useRef(0); const maxScrollY = useRef(0); useEffect(() => { if (dismissed) return; // Check if already shown this session if (typeof window !== "undefined" && sessionStorage.getItem("hooklab_exit_popup")) { setDismissed(true); return; } const triggerPopup = () => { if (!show && !dismissed) { setShow(true); sessionStorage.setItem("hooklab_exit_popup", "1"); } }; // Desktop: mouse leaves viewport at top const handleMouseLeave = (e: MouseEvent) => { if (e.clientY <= 5) { triggerPopup(); } }; // Mobile: user scrolls back up fast after scrolling at least 60% of the page const handleScroll = () => { const currentY = window.scrollY; const pageHeight = document.documentElement.scrollHeight - window.innerHeight; const scrollPercent = pageHeight > 0 ? currentY / pageHeight : 0; if (currentY > maxScrollY.current) { maxScrollY.current = currentY; } // Trigger if user scrolled past 60% of page and then scrolls up by 300px+ const scrolledUpAmount = maxScrollY.current - currentY; const maxScrollPercent = pageHeight > 0 ? maxScrollY.current / pageHeight : 0; if (maxScrollPercent > 0.6 && scrolledUpAmount > 300 && scrollPercent < 0.4) { triggerPopup(); } lastScrollY.current = currentY; }; // Desktop: mouseleave document.addEventListener("mouseleave", handleMouseLeave); // Mobile: scroll-based trigger window.addEventListener("scroll", handleScroll, { passive: true }); return () => { document.removeEventListener("mouseleave", handleMouseLeave); window.removeEventListener("scroll", handleScroll); }; }, [show, dismissed]); const handleClose = () => { setShow(false); setDismissed(true); }; if (!show) return null; return (
TikTok Shop vient d'arriver en France. Le marché n'est pas encore saturé et les premiers créateurs captent l'essentiel des commissions.
{/* Stats */}50,5M€
Marché FR en 2 mois
10-30%
Commission par vente