import type { FC } from 'react' import { headers } from 'next/headers' import Script from 'next/script' import * as React from 'react' import { IS_CE_EDITION, IS_PROD } from '@/config' export enum GaType { admin = 'admin', webapp = 'webapp', } const gaIdMaps = { [GaType.admin]: 'G-DM9497FN4V', [GaType.webapp]: 'G-2MFWXK7WYT', } export type IGAProps = { gaType: GaType } const extractNonceFromCSP = (cspHeader: string | null): string | undefined => { if (!cspHeader) return undefined const nonceMatch = cspHeader.match(/'nonce-([^']+)'/) return nonceMatch ? nonceMatch[1] : undefined } const GA: FC = async ({ gaType, }) => { if (IS_CE_EDITION) return null const cspHeader = IS_PROD ? (await headers()).get('content-security-policy') : null const nonce = extractNonceFromCSP(cspHeader) return ( <> {/* Initialize dataLayer first */}