From 4ee5a4ff364bf0abebbd872bbb3ea9af056504a5 Mon Sep 17 00:00:00 2001 From: GTVJ Date: Tue, 29 Oct 2024 18:00:59 +0000 Subject: [PATCH] BAU: Reflect changes to global flags The GOV.UK Frontend Analytics v3 flips the disable flags to be enable flags to address some confusion (for example, the isGa4Disabled flag in v2 is now a isGa4Enabled flag). Read more about this change in Confluence[^1] This commit updates the codebase to reflect this switch by replacing functions and variables to be their equivalent when flipped. For example: - the googleAnalytics4Disabled() function which used the GA4_DISABLED environment variable and defaulted to "true" is now a googleAnalytics4Enabled() function that uses GA4_ENABLED and defaults to "false" - where 'ua_disabled = false' was, 'ua_enabled = true' now is [^1]: https://govukverify.atlassian.net/wiki/spaces/DIFC/pages/3801317710/Implementation+Guide#%E2%AC%86%EF%B8%8F-Upgrading-from-v2-to-v3 --- ci/terraform/authdev1.tfvars | 2 +- ci/terraform/authdev2.tfvars | 2 +- ci/terraform/build.tfvars | 2 +- ci/terraform/ecs.tf | 8 ++++---- ci/terraform/integration.tfvars | 2 +- ci/terraform/production.tfvars | 4 ++-- ci/terraform/sandpit.tfvars | 2 +- ci/terraform/staging.tfvars | 4 ++-- ci/terraform/variables.tf | 8 ++++---- cloudformation/deploy/template.yaml | 6 +++--- scripts/_create_env_file.py | 8 ++++---- src/components/common/layout/base.njk | 4 ++-- src/config.ts | 8 ++++---- src/middleware/analytics-middleware.ts | 8 ++++---- 14 files changed, 34 insertions(+), 34 deletions(-) diff --git a/ci/terraform/authdev1.tfvars b/ci/terraform/authdev1.tfvars index 340e91ce4..a6a292cec 100644 --- a/ci/terraform/authdev1.tfvars +++ b/ci/terraform/authdev1.tfvars @@ -53,5 +53,5 @@ orch_stub_to_auth_audience = "https://signin.authdev1.sandpit.account. dynatrace_secret_arn = "arn:aws:secretsmanager:eu-west-2:216552277552:secret:DynatraceNonProductionVariables" -ua_disabled = "false" +ua_enabled = "true" analytics_cookie_domain = ".sandpit.account.gov.uk" diff --git a/ci/terraform/authdev2.tfvars b/ci/terraform/authdev2.tfvars index 7170c79ef..4fb6c11ae 100644 --- a/ci/terraform/authdev2.tfvars +++ b/ci/terraform/authdev2.tfvars @@ -58,5 +58,5 @@ orch_stub_to_auth_audience = "https://signin.authdev2.sandpit.account. dynatrace_secret_arn = "arn:aws:secretsmanager:eu-west-2:216552277552:secret:DynatraceNonProductionVariables" -ua_disabled = "false" +ua_enabled = "true" analytics_cookie_domain = ".sandpit.account.gov.uk" diff --git a/ci/terraform/build.tfvars b/ci/terraform/build.tfvars index 4c30994fe..0f2730dd0 100644 --- a/ci/terraform/build.tfvars +++ b/ci/terraform/build.tfvars @@ -45,5 +45,5 @@ cloudfront_auth_frontend_enabled = true cloudfront_auth_dns_enabled = true cloudfront_WafAcl_Logdestination = "csls_cw_logs_destination_prodpython" -ua_disabled = "false" +ua_enabled = "true" analytics_cookie_domain = ".build.account.gov.uk" diff --git a/ci/terraform/ecs.tf b/ci/terraform/ecs.tf index 53acc4903..b81d1cd5f 100644 --- a/ci/terraform/ecs.tf +++ b/ci/terraform/ecs.tf @@ -185,12 +185,12 @@ locals { value = var.prove_identity_welcome_enabled }, { - name = "GA4_DISABLED" - value = var.ga4_disabled + name = "GA4_ENABLED" + value = var.ga4_enabled }, { - name = "UA_DISABLED" - value = var.ua_disabled + name = "UA_ENABLED" + value = var.ua_enabled }, { name = "UNIVERSAL_ANALYTICS_GTM_CONTAINER_ID" diff --git a/ci/terraform/integration.tfvars b/ci/terraform/integration.tfvars index 8afcb4e19..359050ba1 100644 --- a/ci/terraform/integration.tfvars +++ b/ci/terraform/integration.tfvars @@ -41,5 +41,5 @@ orch_to_auth_signing_public_key = "-----BEGIN PUBLIC KEY-----\nMFkwEwYHKoZIzj0CA orch_to_auth_client_id = "orchestrationAuth" orch_to_auth_audience = "https://signin.integration.account.gov.uk/" -ua_disabled = "false" +ua_enabled = "true" analytics_cookie_domain = ".integration.account.gov.uk" diff --git a/ci/terraform/production.tfvars b/ci/terraform/production.tfvars index f09bc9613..c4fc71f72 100644 --- a/ci/terraform/production.tfvars +++ b/ci/terraform/production.tfvars @@ -43,8 +43,8 @@ orch_to_auth_signing_public_key = "-----BEGIN PUBLIC KEY-----\nMFkwEwYHKoZIzj0CA orch_to_auth_client_id = "orchestrationAuth" orch_to_auth_audience = "https://signin.account.gov.uk/" -ua_disabled = "false" +ua_enabled = "true" universal_analytics_gtm_container_id = "GTM-TT5HDKV" -ga4_disabled = "false" +ga4_enabled = "true" google_analytics_4_gtm_container_id = "GTM-K4PBJH3" analytics_cookie_domain = ".account.gov.uk" diff --git a/ci/terraform/sandpit.tfvars b/ci/terraform/sandpit.tfvars index 38c030fa7..267b6652d 100644 --- a/ci/terraform/sandpit.tfvars +++ b/ci/terraform/sandpit.tfvars @@ -51,5 +51,5 @@ logging_endpoint_arns = [ dynatrace_secret_arn = "arn:aws:secretsmanager:eu-west-2:216552277552:secret:DynatraceNonProductionVariables" -ua_disabled = "false" +ua_enabled = "true" analytics_cookie_domain = ".sandpit.account.gov.uk" diff --git a/ci/terraform/staging.tfvars b/ci/terraform/staging.tfvars index 1cd7a2898..d268c8740 100644 --- a/ci/terraform/staging.tfvars +++ b/ci/terraform/staging.tfvars @@ -43,8 +43,8 @@ orch_to_auth_signing_public_key = "-----BEGIN PUBLIC KEY-----\nMFkwEwYHKoZIzj0CA orch_to_auth_client_id = "orchestrationAuth" orch_to_auth_audience = "https://signin.staging.account.gov.uk/" -ua_disabled = "false" +ua_enabled = "true" universal_analytics_gtm_container_id = "GTM-TK92W68" -ga4_disabled = "false" +ga4_enabled = "true" google_analytics_4_gtm_container_id = "GTM-KD86CMZ" analytics_cookie_domain = ".staging.account.gov.uk" diff --git a/ci/terraform/variables.tf b/ci/terraform/variables.tf index baeaba486..63f3478c9 100644 --- a/ci/terraform/variables.tf +++ b/ci/terraform/variables.tf @@ -396,15 +396,15 @@ variable "language_toggle_enabled" { description = "Enables English / Welsh language toggle in the user interface" } -variable "ga4_disabled" { +variable "ga4_enabled" { type = string - default = "true" + default = "false" description = "Enables Google Analytics 4" } -variable "ua_disabled" { +variable "ua_enabled" { type = string - default = "true" + default = "false" description = "Enables Universal Analytics" } diff --git a/cloudformation/deploy/template.yaml b/cloudformation/deploy/template.yaml index 2ff347c86..d17ddbb7c 100644 --- a/cloudformation/deploy/template.yaml +++ b/cloudformation/deploy/template.yaml @@ -714,10 +714,10 @@ Resources: Value: 1 - Name: PROVE_IDENTITY_WELCOME_ENABLED Value: 0 - - Name: GA4_DISABLED - Value: true - - Name: UA_DISABLED + - Name: GA4_ENABLED Value: false + - Name: UA_ENABLED + Value: true - Name: UNIVERSAL_ANALYTICS_GTM_CONTAINER_ID Value: GTM-TK92W68 - Name: GOOGLE_ANALYTICS_4_GTM_CONTAINER_ID diff --git a/scripts/_create_env_file.py b/scripts/_create_env_file.py index 60d6b4b46..3aef20b91 100755 --- a/scripts/_create_env_file.py +++ b/scripts/_create_env_file.py @@ -128,12 +128,12 @@ class EnvFileSection(TypedDict): { "header": "Analytics", "variables": { - "GA4_DISABLED": { - "value": "false", + "GA4_ENABLED": { + "value": "true", "comment": "GA4 Enablement", }, - "UA_DISABLED": { - "value": "false", + "UA_ENABLED": { + "value": "true", "comment": "Univeral Analytics", }, "UNIVERSAL_ANALYTICS_GTM_CONTAINER_ID": { diff --git a/src/components/common/layout/base.njk b/src/components/common/layout/base.njk index f58d10b11..d6237b69f 100644 --- a/src/components/common/layout/base.njk +++ b/src/components/common/layout/base.njk @@ -177,8 +177,8 @@ uaContainerId: "{{uaContainerId}}" }, { isDataSensitive: false, - disableGa4Tracking: {{isGa4Disabled}}, - disableUaTracking: {{isUaDisabled}}, + enableGa4Tracking: {{isGa4Enabled}}, + enableUaTracking: {{isUaEnabled}}, cookieDomain: "{{analyticsCookieDomain}}" }); } diff --git a/src/config.ts b/src/config.ts index 73bce5b3b..e4bfb8123 100644 --- a/src/config.ts +++ b/src/config.ts @@ -181,12 +181,12 @@ export function getGTMContainerID(): string { return process.env.UNIVERSAL_ANALYTICS_GTM_CONTAINER_ID || ""; } -export function googleAnalytics4Disabled(): string { - return process.env.GA4_DISABLED || "true"; +export function googleAnalytics4Enabled(): string { + return process.env.GA4_ENABLED || "false"; } -export function universalAnalyticsDisabled(): string { - return process.env.UA_DISABLED || "false"; +export function universalAnalyticsEnabled(): string { + return process.env.UA_ENABLED || "false"; } export function proveIdentityWelcomeEnabled(): boolean { return process.env.PROVE_IDENTITY_WELCOME_ENABLED === "1"; diff --git a/src/middleware/analytics-middleware.ts b/src/middleware/analytics-middleware.ts index 9d7ce61ec..ee0783143 100644 --- a/src/middleware/analytics-middleware.ts +++ b/src/middleware/analytics-middleware.ts @@ -3,14 +3,14 @@ import { getAnalyticsCookieDomain, getGA4ContainerId, getGTMContainerID, - googleAnalytics4Disabled, - universalAnalyticsDisabled, + googleAnalytics4Enabled, + universalAnalyticsEnabled, } from "../config"; export function setGTM(req: Request, res: Response, next: NextFunction): void { res.locals.ga4ContainerId = getGA4ContainerId(); res.locals.uaContainerId = getGTMContainerID(); res.locals.analyticsCookieDomain = getAnalyticsCookieDomain(); - res.locals.isGa4Disabled = googleAnalytics4Disabled(); - res.locals.isUaDisabled = universalAnalyticsDisabled(); + res.locals.isGa4Enabled = googleAnalytics4Enabled(); + res.locals.isUaEnabled = universalAnalyticsEnabled(); next(); }