Skip to content

Commit

Permalink
BAU: Reflect changes to global flags
Browse files Browse the repository at this point in the history
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
  • Loading branch information
gtvj committed Oct 29, 2024
1 parent 9461c4b commit 4ee5a4f
Show file tree
Hide file tree
Showing 14 changed files with 34 additions and 34 deletions.
2 changes: 1 addition & 1 deletion ci/terraform/authdev1.tfvars
Original file line number Diff line number Diff line change
Expand Up @@ -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"
2 changes: 1 addition & 1 deletion ci/terraform/authdev2.tfvars
Original file line number Diff line number Diff line change
Expand Up @@ -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"
2 changes: 1 addition & 1 deletion ci/terraform/build.tfvars
Original file line number Diff line number Diff line change
Expand Up @@ -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"
8 changes: 4 additions & 4 deletions ci/terraform/ecs.tf
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion ci/terraform/integration.tfvars
Original file line number Diff line number Diff line change
Expand Up @@ -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"
4 changes: 2 additions & 2 deletions ci/terraform/production.tfvars
Original file line number Diff line number Diff line change
Expand Up @@ -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"
2 changes: 1 addition & 1 deletion ci/terraform/sandpit.tfvars
Original file line number Diff line number Diff line change
Expand Up @@ -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"
4 changes: 2 additions & 2 deletions ci/terraform/staging.tfvars
Original file line number Diff line number Diff line change
Expand Up @@ -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"
8 changes: 4 additions & 4 deletions ci/terraform/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}

Expand Down
6 changes: 3 additions & 3 deletions cloudformation/deploy/template.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 4 additions & 4 deletions scripts/_create_env_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
4 changes: 2 additions & 2 deletions src/components/common/layout/base.njk
Original file line number Diff line number Diff line change
Expand Up @@ -177,8 +177,8 @@
uaContainerId: "{{uaContainerId}}"
}, {
isDataSensitive: false,
disableGa4Tracking: {{isGa4Disabled}},
disableUaTracking: {{isUaDisabled}},
enableGa4Tracking: {{isGa4Enabled}},
enableUaTracking: {{isUaEnabled}},
cookieDomain: "{{analyticsCookieDomain}}"
});
}
Expand Down
8 changes: 4 additions & 4 deletions src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down
8 changes: 4 additions & 4 deletions src/middleware/analytics-middleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

0 comments on commit 4ee5a4f

Please sign in to comment.