@@ -20,7 +20,7 @@ export default function RootLayout({ {children} - + ); } @@ -39,8 +39,6 @@ export default function PortfolioBlock({ contacts, portfolioItems }: IProps) { } }; - console.log(portfolioItems); - return (
{isModalFeedbackOpened && } @@ -1,7 +1,8 @@ "use client"; -import Router from "next/router"; -import React, { useCallback, useEffect } from "react"; +import { usePathname, useRouter } from "next/navigation"; +// import Router from "next/router"; +import React, { useCallback, useEffect, useState } from "react"; import ym, { YMInitializer } from "react-yandex-metrika"; type Props = { @@ -11,24 +12,28 @@ type Props = { const YM_COUNTER_ID = 98551939; const YandexMetrikaContainer = ({ enabled }: Props) => { + const pathname = usePathname() + const [isFirstRender, setIsFirstRender] = useState(true) + const hit = useCallback( (url: string) => { if (enabled) { ym("hit", url); } else { - console.log(`%c[YandexMetrika](HIT)`, `color: orange`, url); + // 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 (!isFirstRender) { + hit(pathname); + } else { + setIsFirstRender(false); + } + }, [pathname, isFirstRender]); + if (!enabled) return null; return (