From 00f3a5723abb36fc8d60eef33cd736a69bd223a9 Mon Sep 17 00:00:00 2001 From: Kalvin <82277+kalvinwang@users.noreply.github.com> Date: Thu, 2 Sep 2021 23:30:00 -0400 Subject: [PATCH] Include Google Analytics code --- pages/index.tsx | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/pages/index.tsx b/pages/index.tsx index 48260bb0..a050850a 100644 --- a/pages/index.tsx +++ b/pages/index.tsx @@ -25,6 +25,7 @@ export interface HomeProps { errorCode?: number | null userArrivedFromUioMobile?: boolean urlPrefixes: UrlPrefixes + enableGoogleAnalytics: string } export default function Home({ @@ -34,9 +35,34 @@ export default function Home({ errorCode = null, userArrivedFromUioMobile = false, urlPrefixes, + enableGoogleAnalytics, }: HomeProps): ReactElement { const { t } = useTranslation('common') + // Once CSP is enabled, if you change the GA script code, you need to update the hash in csp.js to allow + // this script to run. Chrome dev tools will have an error with the correct hash value to use. + // https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Security-Policy/script-src#Unsafe_inline_script + const gaScript = ` + window.dataLayer = window.dataLayer || [] + function gtag(){dataLayer.push(arguments)} + gtag('js', new Date()) + // For details see: https://support.google.com/analytics/answer/9310895?hl=en + // https://developers.google.com/analytics/devguides/collection/gtagjs/ip-anonymization + gtag('config', 'UA-3419582-2', { 'anonymize_ip': true }) // www.ca.gov + gtag('config', 'UA-3419582-31', { 'anonymize_ip': true }) // edd.ca.gov` + + const googleAnalytics = ( + <> + {/* Global site tag (gtag.js) - Google Analytics */} +