@@ -26,6 +26,13 @@ import UserMenu from './UserMenu/UserMenu';
26
26
import { useSession } from 'next-auth/react' ;
27
27
// import { useTheme } from '../context/ThemeContext';
28
28
import { useState } from 'react' ;
29
+ import {
30
+ PROD_DEPLOYMENT_ENVIRONMENT ,
31
+ PROD_METRICS_WEBSITE_ID ,
32
+ QA_DEPLOYMENT_ENVIRONMENT ,
33
+ QA_METRICS_WEBSITE_ID ,
34
+ UMAMI_METRICS_SCRIPT_SOURCE
35
+ } from '../types/const' ;
29
36
30
37
interface IAppLayout {
31
38
children : React . ReactNode ;
@@ -46,6 +53,31 @@ const AppLayout: React.FunctionComponent<IAppLayout> = ({ children }) => {
46
53
const router = useRouter ( ) ;
47
54
const pathname = usePathname ( ) ;
48
55
56
+ React . useEffect ( ( ) => {
57
+ if ( typeof window === 'undefined' ) return ;
58
+
59
+ const hostname = window . location . hostname ;
60
+ const isProd = hostname === PROD_DEPLOYMENT_ENVIRONMENT ;
61
+ const isQA = hostname === QA_DEPLOYMENT_ENVIRONMENT ;
62
+
63
+ const scriptSource = isQA || isProd ? UMAMI_METRICS_SCRIPT_SOURCE : '' ;
64
+ const websiteId = isProd ? PROD_METRICS_WEBSITE_ID : isQA ? QA_METRICS_WEBSITE_ID : null ;
65
+
66
+ if ( scriptSource && websiteId ) {
67
+ const script = document . createElement ( 'script' ) ;
68
+ script . async = true ;
69
+ script . defer = true ;
70
+ script . dataset . websiteId = websiteId ;
71
+ script . src = scriptSource ;
72
+
73
+ document . head . appendChild ( script ) ;
74
+
75
+ return ( ) => {
76
+ document . head . removeChild ( script ) ;
77
+ } ;
78
+ }
79
+ } , [ ] ) ;
80
+
49
81
React . useEffect ( ( ) => {
50
82
// Fetch the experimental feature flag
51
83
const fetchExperimentalFeature = async ( ) => {
0 commit comments