@@ -1,12 +1,15 @@ import type { Metadata } from "next"; import "./globals.css"; import { nunitoSans } from '@/src/assets/fonts/fonts'; +import YandexMetrikaContainer from "../shared/utils/YandexMetrikaContainer"; export const metadata: Metadata = { title: "X-ESSENCE - шоурум-ателье", description: "Индивидуальный пошив одежды любой сложности, от деловой одежды до роскошных вечерних костюмов,пошив малых партий для брендов и мероприятий, подгонка по фигуре и кастомизация", }; +const analyticsEnabled = !!(process.env.NODE_ENV === "production"); + export default function RootLayout({ children, }: Readonly<{ @@ -15,8 +18,9 @@ export default function RootLayout({ return ( - {children} + {children} + ); } @@ -0,0 +1,51 @@ +"use client"; + +import Router from "next/router"; +import React, { useCallback, useEffect } from "react"; +import ym, { YMInitializer } from "react-yandex-metrika"; + +type Props = { + enabled: boolean; +}; + +const YM_COUNTER_ID = 98551939; + +const YandexMetrikaContainer = ({ enabled }: Props) => { + const hit = useCallback( + (url: string) => { + if (enabled) { + ym("hit", url); + } else { + console.log(`%c[YandexMetrika](HIT)`, `color: orange`, url); + } + }, + [enabled], + ); + + useEffect(() => { + console.log(111); + + hit(window.location.pathname + window.location.search); + Router.events.on("routeChangeComplete", (url: string) => hit(url)); + }, [hit]); + + if (!enabled) return null; + + return ( + <> + + + ); +}; + +export default YandexMetrikaContainer; @@ -23,6 +23,7 @@ "react-loading-skeleton": "^3.5.0", "react-modal": "^3.16.1", "react-transition-group": "^4.4.5", + "react-yandex-metrika": "^2.6.0", "sharp": "^0.33.5", "swiper": "^11.1.14", "yup": "^1.4.0" @@ -5148,6 +5149,15 @@ "react-dom": ">=16.6.0" } }, + "node_modules/react-yandex-metrika": { + "version": "2.6.0", + "resolved": "https://registry.npmjs.org/react-yandex-metrika/-/react-yandex-metrika-2.6.0.tgz", + "integrity": "sha512-8K4wExsNZtY3DTxh1G8a+zWH9Pg8fw23MJcoJ4I/562qrHRnh7L5nteq3lnNL58dnNQbuuHIRoGgMjIo+r1GjA==", + "peerDependencies": { + "prop-types": "*", + "react": "*" + } + }, "node_modules/read-cache": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/read-cache/-/read-cache-1.0.0.tgz", @@ -24,6 +24,7 @@ "react-loading-skeleton": "^3.5.0", "react-modal": "^3.16.1", "react-transition-group": "^4.4.5", + "react-yandex-metrika": "^2.6.0", "sharp": "^0.33.5", "swiper": "^11.1.14", "yup": "^1.4.0"