@@ -4,7 +4,7 @@ import { useSession } from 'next-auth/react' import { useAppSelector } from '#/app/store/store' import { getDeviceType } from '#/shared/lib/helpers' -import { initYandexMetrika } from '#/shared/lib/yandex-metrika' +import { initYandexMetrika, stopYandexMetrika } from '#/shared/lib/yandex-metrika' import styles from './cookie-consent.module.scss' @@ -23,11 +23,15 @@ export function CookieConsent() { const desktop = getDeviceType() === 'desktop' React.useEffect(() => { - if (account_type !== 'regular') return + if (meStatus !== 'succeeded') return + if (account_type.startsWith('business')) { + stopYandexMetrika() + return + } const stored = getConsent() setConsent(stored) if (stored === 'all') initYandexMetrika() - }, [account_type]) + }, [account_type, meStatus]) const choose = (value: string) => { localStorage.setItem('cookie-consent', value) @@ -36,7 +40,7 @@ export function CookieConsent() { } if (status !== 'authenticated' || meStatus !== 'succeeded') return null - if (account_type !== 'regular' || consent !== null) return null + if (account_type.startsWith('business') || consent !== null) return null return (
@@ -1,3 +1,10 @@ +export function stopYandexMetrika() { + if (typeof window === 'undefined') return + delete (window as any).__ymInited + delete (window as any).ym + document.querySelectorAll('script[src*="mc.yandex.ru"]').forEach((s) => s.remove()) +} + export function initYandexMetrika() { if (typeof window === 'undefined' || (window as any).__ymInited) return ;(window as any).__ymInited = true