@@ -26,6 +26,7 @@ import UserMenu from './UserMenu/UserMenu';
2626import { useSession } from 'next-auth/react' ;
2727// import { useTheme } from '../context/ThemeContext';
2828import { useState } from 'react' ;
29+ import { PROD_DEPLOYMENT_ENVIRONMENT , PROD_METRICS_WEBSITE_ID , QA_DEPLOYMENT_ENVIRONMENT , QA_METRICS_WEBSITE_ID , UMAMI_METRICS_SCRIPT_SOURCE } from '../types/const'
2930
3031interface IAppLayout {
3132 children : React . ReactNode ;
@@ -46,6 +47,35 @@ const AppLayout: React.FunctionComponent<IAppLayout> = ({ children }) => {
4647 const router = useRouter ( ) ;
4748 const pathname = usePathname ( ) ;
4849
50+ React . useEffect ( ( ) => {
51+ if ( typeof window === 'undefined' ) return ;
52+
53+ const hostname = window . location . hostname ;
54+ const isProd = hostname === PROD_DEPLOYMENT_ENVIRONMENT ;
55+ const isQA = hostname === QA_DEPLOYMENT_ENVIRONMENT ;
56+
57+ const scriptSource = isQA || isProd ? UMAMI_METRICS_SCRIPT_SOURCE : '' ;
58+ const websiteId = isProd
59+ ? PROD_METRICS_WEBSITE_ID
60+ : isQA
61+ ? QA_METRICS_WEBSITE_ID
62+ : null ;
63+
64+ if ( scriptSource && websiteId ) {
65+ const script = document . createElement ( 'script' ) ;
66+ script . async = true ;
67+ script . defer = true ;
68+ script . dataset . websiteId = websiteId ;
69+ script . src = scriptSource ;
70+
71+ document . head . appendChild ( script ) ;
72+
73+ return ( ) => {
74+ document . head . removeChild ( script ) ;
75+ } ;
76+ }
77+ } , [ ] ) ;
78+
4979 React . useEffect ( ( ) => {
5080 // Fetch the experimental feature flag
5181 const fetchExperimentalFeature = async ( ) => {
0 commit comments