"use client";
import { useEffect, useState } from "react";
import Script from "next/script";
import { useTranslations } from "next-intl";
import { Button, Typography } from "@/components/ui";
import { ROUTES } from "@/shared/constants/client-routes";
import styles from "./Metrics.module.scss";
interface MetricsProps {
fbPixels: string[];
productPrice: string;
currency: string;
}
export default function Metrics({
fbPixels,
productPrice,
currency,
}: MetricsProps) {
const t = useTranslations("Payment.Success");
const [isButtonVisible, setIsButtonVisible] = useState(false);
const handleNext = () => {
window.location.href = ROUTES.additionalPurchases();
};
// Yandex Metrica
useEffect(() => {
const timeout = setTimeout(() => {
if (
typeof window.ym === "function" &&
typeof window.klaviyo === "object" &&
typeof window.gtag === "function"
) {
try {
window.gtag("event", "PaymentSuccess");
window.klaviyo.push(["track", "PaymentSuccess"]);
window.ym(95799066, "init", {
clickmap: true,
trackLinks: true,
accurateTrackBounce: true,
webvisor: true,
});
window.ym(95799066, "reachGoal", "PaymentSuccess", {}, () => {
// deleteYm()
});
} catch (e) {
// eslint-disable-next-line no-console
console.error("YM error:", e);
} finally {
clearTimeout(timeout);
setIsButtonVisible(true);
}
}
}, 200);
return () => clearTimeout(timeout);
}, []);
return (
<>
{/* Klaviyo */}
{/* */}
{/* Yandex Metrica */}
{/* Google Analytics */}
{/* Facebook Pixel */}
{fbPixels.map(pixel => (
))}
{isButtonVisible && (
)}
>
);
}