'use client';

import { usePathname } from 'next/navigation';
import { useEffect } from 'react';
import ym, { YMInitializer } from 'react-yandex-metrika';
import { YM_COUNTER_ID } from '@core/constants/tracking-service';

export default function YandexMetrika() {
  const pathname = usePathname();

  // Отправляем событие "hit" при изменении маршрута
  useEffect(() => {
    if (pathname) {
      ym('hit', pathname);
    }
  }, [pathname]);

  return (
    <YMInitializer
      accounts={[YM_COUNTER_ID]}
      options={{
        defer: true,
        webvisor: true,
        clickmap: true,
        trackLinks: true,
        accurateTrackBounce: true,
      }}
      version='2'
    />
  );
}
