fix: add tracking service
This commit is contained in:
@@ -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 />
|
||||
|
||||
3
src/core/constants/tracking-service.ts
Normal file
3
src/core/constants/tracking-service.ts
Normal file
@@ -0,0 +1,3 @@
|
||||
const YM_COUNTER_ID = 102875868; // ID счетчика YM
|
||||
|
||||
export { YM_COUNTER_ID };
|
||||
@@ -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';
|
||||
|
||||
1
src/widgets/yandex-metrika/index.ts
Normal file
1
src/widgets/yandex-metrika/index.ts
Normal file
@@ -0,0 +1 @@
|
||||
export { default as YandexMetrika } from './ui';
|
||||
31
src/widgets/yandex-metrika/ui.tsx
Normal file
31
src/widgets/yandex-metrika/ui.tsx
Normal 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'
|
||||
/>
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user