From 58a81f9f95661dc1513e1e66befba71102a0c79f Mon Sep 17 00:00:00 2001 From: Andrew Hosgood Date: Wed, 14 Feb 2024 14:36:17 +0000 Subject: [PATCH] Add tracking for global header --- src/nationalarchives/analytics.mjs | 2 ++ .../components/global-header/analytics.js | 23 +++++++++++++++++++ 2 files changed, 25 insertions(+) create mode 100644 src/nationalarchives/components/global-header/analytics.js diff --git a/src/nationalarchives/analytics.mjs b/src/nationalarchives/analytics.mjs index a1c69d2f..7beede0a 100644 --- a/src/nationalarchives/analytics.mjs +++ b/src/nationalarchives/analytics.mjs @@ -5,12 +5,14 @@ import { valueGetters, } from "./lib/analytics-helpers.mjs"; import BreadcrumbAnalytics from "./components/breadcrumbs/analytics.js"; +import GlobalHeaderAnalytics from "./components/global-header/analytics.js"; import HeaderAnalytics from "./components/header/analytics.js"; import HeroAnalytics from "./components/hero/analytics.js"; import PictureAnalytics from "./components/picture/analytics.js"; const componentAnalytics = [ ...BreadcrumbAnalytics, + ...GlobalHeaderAnalytics, ...HeaderAnalytics, ...HeroAnalytics, ...PictureAnalytics, diff --git a/src/nationalarchives/components/global-header/analytics.js b/src/nationalarchives/components/global-header/analytics.js new file mode 100644 index 00000000..92a37a92 --- /dev/null +++ b/src/nationalarchives/components/global-header/analytics.js @@ -0,0 +1,23 @@ +export default [ + { + scope: ".tna-global-header", + areaName: "header", + events: [ + { + eventName: "toggle", + targetElement: ".tna-global-header__navigation-button", + on: "click", + data: { + // eslint-disable-next-line no-unused-vars + state: ($el, $scope, event) => { + const expanded = $el.getAttribute("aria-expanded"); + if (expanded === null) { + return null; + } + return expanded.toString() === "true" ? "opened" : "closed"; + }, + }, + }, + ], + }, +];