'use client' import { components } from 'api-types' import { useRouter } from 'next/compat/router' import { usePathname } from 'next/navigation' import Script from 'next/script' import { useCallback, useEffect, useRef } from 'react' import { useLatest } from 'react-use' import { useUser } from './auth' import { hasConsented, useConsentState } from './consent-state' import { IS_PLATFORM } from './constants' import { useFeatureFlags } from './feature-flags' import { post } from './fetchWrappers' import type { FirstReferrerData, MwDiagData } from './first-referrer-cookie' import { isExternalReferrer, isOAuthRedirectReferrer, parseFirstReferrerCookie, parseMwDiagCookie, } from './first-referrer-cookie' import { ensurePlatformSuffix, isBrowser } from './helpers' import { useFirstTouchStore, useParams } from './hooks' import { posthogClient, type ClientTelemetryEvent } from './posthog-client' import { TelemetryEvent } from './telemetry-constants' import { clearFirstTouchData, getFirstTouchData, type SharedTelemetryData, } from './telemetry-first-touch-store' import { getSharedTelemetryData, getTelemetryCookieOptions } from './telemetry-utils' export { posthogClient, type ClientTelemetryEvent } export const TelemetryTagManager = () => { const { hasAccepted } = useConsentState() const isGTMEnabled = Boolean( IS_PLATFORM && process.env.NEXT_PUBLIC_GOOGLE_TAG_MANAGER_ID && hasAccepted ) if (!isGTMEnabled) return null return (