fix: add tracking service

This commit is contained in:
2025-06-20 12:47:57 +03:00
parent 2d77844758
commit 29a1abea03
7 changed files with 52 additions and 7 deletions

View File

@@ -1,10 +1,11 @@
import type { Metadata } from 'next';
import { ReactNode } from 'react';
import { Open_Sans } from 'next/font/google';
import '@core/styles/reset.scss';
import '@core/styles/globals.scss';
import { Toaster } from 'react-hot-toast';
import { ModalProvider } from '@core/providers/modal-provider';
import { CookieNotice } from '@/widgets';
import { CookieNotice, YandexMetrika } from '@/widgets';
const openSans = Open_Sans({
subsets: ['cyrillic'],
@@ -32,10 +33,11 @@ export const metadata: Metadata = {
export default function RootLayout({
children,
}: Readonly<{ children: React.ReactNode }>) {
}: Readonly<{ children: ReactNode }>) {
return (
<html lang='en'>
<body className={`${openSans.variable}`}>
<YandexMetrika />
<ModalProvider>{children}</ModalProvider>
<Toaster />
<CookieNotice />

View File

@@ -0,0 +1,3 @@
const YM_COUNTER_ID = 102875868; // ID счетчика YM
export { YM_COUNTER_ID };

View File

@@ -6,3 +6,4 @@ export { OfferForm } from './offer-form';
export { OfferRequestForm } from './offer-request';
export { AdvancedPhoneInput } from './advanced-phone-input';
export { CookieNotice } from './cookie-notice';
export { YandexMetrika } from './yandex-metrika';

View File

@@ -0,0 +1 @@
export { default as YandexMetrika } from './ui';

View File

@@ -0,0 +1,31 @@
'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'
/>
);
}