Skip to content

Commit

Permalink
Merge pull request #2258 from govuk-one-login/BAU/upgrade-frontend-an…
Browse files Browse the repository at this point in the history
…alytics-to-version-3

BAU: Upgrade GOV.UK Frontend Analytics package to v3
  • Loading branch information
gtvj authored Nov 11, 2024
2 parents 5469b0c + 8016c2f commit cd950bf
Show file tree
Hide file tree
Showing 16 changed files with 77 additions and 66 deletions.
2 changes: 1 addition & 1 deletion ci/terraform/authdev1.tfvars
Original file line number Diff line number Diff line change
Expand Up @@ -52,5 +52,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 @@ -57,5 +57,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 @@ -44,5 +44,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 @@ -177,12 +177,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 @@ -40,5 +40,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 @@ -42,8 +42,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 @@ -50,5 +50,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 @@ -42,8 +42,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 @@ -385,15 +385,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 @@ -710,10 +710,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
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@
"@aws-sdk/client-ssm": "^3.366.0",
"@eslint/eslintrc": "^3.1.0",
"@eslint/js": "^9.14.0",
"@govuk-one-login/frontend-analytics": "2.0.1",
"@govuk-one-login/frontend-analytics": "3.0.1",
"@govuk-one-login/frontend-language-toggle": "^1.1.0",
"@govuk-one-login/frontend-passthrough-headers": "^1.1.1",
"@govuk-one-login/frontend-vital-signs": "0.0.4",
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 @@ -127,12 +127,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 @@ -173,12 +173,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();
}
Loading

0 comments on commit cd950bf

Please sign in to comment.