fix: add tracking service
This commit is contained in:
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