govuk_publishing_components 32.1.0 → 35.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +1 -0
- data/app/assets/config/govuk_publishing_components_manifest.js +75 -1
- data/app/assets/images/govuk_publishing_components/icon-search.svg +3 -0
- data/app/assets/images/govuk_publishing_components/youtube-play-icon.png +0 -0
- data/app/assets/images/govuk_publishing_components/youtube-play-icon.svg +4 -0
- data/app/assets/javascripts/component_guide/accessibility-test.js +0 -1
- data/app/assets/javascripts/govuk_publishing_components/analytics/auto-scroll-tracker.js +2 -1
- data/app/assets/javascripts/govuk_publishing_components/analytics/linked-domains.js +135 -0
- data/app/assets/javascripts/govuk_publishing_components/analytics-ga4/ga4-auto-tracker.js +49 -0
- data/app/assets/javascripts/govuk_publishing_components/analytics-ga4/ga4-core.js +341 -27
- data/app/assets/javascripts/govuk_publishing_components/analytics-ga4/ga4-ecommerce-tracker.js +17 -92
- data/app/assets/javascripts/govuk_publishing_components/analytics-ga4/ga4-event-tracker.js +11 -23
- data/app/assets/javascripts/govuk_publishing_components/analytics-ga4/ga4-form-tracker.js +121 -0
- data/app/assets/javascripts/govuk_publishing_components/analytics-ga4/ga4-link-tracker.js +86 -305
- data/app/assets/javascripts/govuk_publishing_components/analytics-ga4/ga4-page-views.js +13 -6
- data/app/assets/javascripts/govuk_publishing_components/analytics-ga4/ga4-schemas.js +31 -1
- data/app/assets/javascripts/govuk_publishing_components/analytics-ga4/ga4-smart-answer-results-tracker.js +57 -0
- data/app/assets/javascripts/govuk_publishing_components/analytics-ga4/ga4-specialist-link-tracker.js +131 -0
- data/app/assets/javascripts/govuk_publishing_components/analytics-ga4/init-ga4.js +9 -4
- data/app/assets/javascripts/govuk_publishing_components/analytics-ga4/pii-remover.js +4 -2
- data/app/assets/javascripts/govuk_publishing_components/analytics-ga4.js +4 -0
- data/app/assets/javascripts/govuk_publishing_components/components/accordion.js +12 -1
- data/app/assets/javascripts/govuk_publishing_components/components/cookie-banner.js +2 -2
- data/app/assets/javascripts/govuk_publishing_components/components/image-card.js +19 -0
- data/app/assets/javascripts/govuk_publishing_components/components/layout-super-navigation-header.js +2 -81
- data/app/assets/javascripts/govuk_publishing_components/components/single-page-notification-button.js +24 -8
- data/app/assets/javascripts/govuk_publishing_components/components/step-by-step-nav.js +23 -1
- data/app/assets/javascripts/govuk_publishing_components/dependencies.js +13 -0
- data/app/assets/javascripts/govuk_publishing_components/lib/govspeak/youtube-link-enhancement.js +3 -2
- data/app/assets/javascripts/govuk_publishing_components/lib/trigger-event.js +1 -0
- data/app/assets/javascripts/govuk_publishing_components/load-analytics.js +116 -0
- data/app/assets/javascripts/govuk_publishing_components/modules.js +7 -2
- data/app/assets/javascripts/govuk_publishing_components/vendor/lux/lux-reporter.js +140 -191
- data/app/assets/stylesheets/govuk_publishing_components/_individual_component_support.scss +10 -0
- data/app/assets/stylesheets/govuk_publishing_components/components/_accordion.scss +29 -0
- data/app/assets/stylesheets/govuk_publishing_components/components/_action-link.scss +2 -0
- data/app/assets/stylesheets/govuk_publishing_components/components/_attachment.scss +2 -0
- data/app/assets/stylesheets/govuk_publishing_components/components/_back-link.scss +1 -0
- data/app/assets/stylesheets/govuk_publishing_components/components/_big-number.scss +4 -5
- data/app/assets/stylesheets/govuk_publishing_components/components/_breadcrumbs.scss +1 -0
- data/app/assets/stylesheets/govuk_publishing_components/components/_button.scss +12 -0
- data/app/assets/stylesheets/govuk_publishing_components/components/_cards.scss +20 -0
- data/app/assets/stylesheets/govuk_publishing_components/components/_character-count.scss +1 -0
- data/app/assets/stylesheets/govuk_publishing_components/components/_checkboxes.scss +1 -0
- data/app/assets/stylesheets/govuk_publishing_components/components/_contents-list.scss +21 -0
- data/app/assets/stylesheets/govuk_publishing_components/components/_contextual-guidance.scss +2 -0
- data/app/assets/stylesheets/govuk_publishing_components/components/_contextual-sidebar.scss +2 -0
- data/app/assets/stylesheets/govuk_publishing_components/components/_cookie-banner.scss +7 -0
- data/app/assets/stylesheets/govuk_publishing_components/components/_date-input.scss +1 -0
- data/app/assets/stylesheets/govuk_publishing_components/components/_details.scss +1 -0
- data/app/assets/stylesheets/govuk_publishing_components/components/_devolved-nations.scss +2 -0
- data/app/assets/stylesheets/govuk_publishing_components/components/_document-list.scss +8 -0
- data/app/assets/stylesheets/govuk_publishing_components/components/_emergency-banner.scss +8 -0
- data/app/assets/stylesheets/govuk_publishing_components/components/_error-alert.scss +2 -0
- data/app/assets/stylesheets/govuk_publishing_components/components/_error-message.scss +1 -0
- data/app/assets/stylesheets/govuk_publishing_components/components/_error-summary.scss +1 -0
- data/app/assets/stylesheets/govuk_publishing_components/components/_feedback.scss +17 -19
- data/app/assets/stylesheets/govuk_publishing_components/components/_fieldset.scss +1 -0
- data/app/assets/stylesheets/govuk_publishing_components/components/_file-upload.scss +1 -0
- data/app/assets/stylesheets/govuk_publishing_components/components/_govspeak-html-publication.scss +10 -0
- data/app/assets/stylesheets/govuk_publishing_components/components/_govspeak.scss +85 -0
- data/app/assets/stylesheets/govuk_publishing_components/components/_heading.scss +2 -0
- data/app/assets/stylesheets/govuk_publishing_components/components/_hint.scss +1 -0
- data/app/assets/stylesheets/govuk_publishing_components/components/_image-card.scss +85 -6
- data/app/assets/stylesheets/govuk_publishing_components/components/_input.scss +6 -6
- data/app/assets/stylesheets/govuk_publishing_components/components/_inset-text.scss +1 -0
- data/app/assets/stylesheets/govuk_publishing_components/components/_intervention.scss +2 -0
- data/app/assets/stylesheets/govuk_publishing_components/components/_inverse-header.scss +2 -0
- data/app/assets/stylesheets/govuk_publishing_components/components/_label.scss +1 -0
- data/app/assets/stylesheets/govuk_publishing_components/components/_layout-footer.scss +1 -0
- data/app/assets/stylesheets/govuk_publishing_components/components/_layout-for-public.scss +2 -0
- data/app/assets/stylesheets/govuk_publishing_components/components/_layout-super-navigation-header.scss +253 -483
- data/app/assets/stylesheets/govuk_publishing_components/components/_lead-paragraph.scss +2 -0
- data/app/assets/stylesheets/govuk_publishing_components/components/_metadata.scss +2 -0
- data/app/assets/stylesheets/govuk_publishing_components/components/_modal-dialogue.scss +2 -0
- data/app/assets/stylesheets/govuk_publishing_components/components/_notice.scss +1 -0
- data/app/assets/stylesheets/govuk_publishing_components/components/_organisation-logo.scss +2 -0
- data/app/assets/stylesheets/govuk_publishing_components/components/_panel.scss +1 -0
- data/app/assets/stylesheets/govuk_publishing_components/components/_phase-banner.scss +1 -0
- data/app/assets/stylesheets/govuk_publishing_components/components/_previous-and-next-navigation.scss +1 -0
- data/app/assets/stylesheets/govuk_publishing_components/components/_print-link.scss +2 -0
- data/app/assets/stylesheets/govuk_publishing_components/components/_radio.scss +1 -0
- data/app/assets/stylesheets/govuk_publishing_components/components/_related-navigation.scss +2 -0
- data/app/assets/stylesheets/govuk_publishing_components/components/_reorderable-list.scss +2 -0
- data/app/assets/stylesheets/govuk_publishing_components/components/_search.scss +2 -7
- data/app/assets/stylesheets/govuk_publishing_components/components/_select.scss +1 -0
- data/app/assets/stylesheets/govuk_publishing_components/components/_share-links.scss +2 -0
- data/app/assets/stylesheets/govuk_publishing_components/components/_show-password.scss +2 -0
- data/app/assets/stylesheets/govuk_publishing_components/components/_signup-link.scss +2 -0
- data/app/assets/stylesheets/govuk_publishing_components/components/_single-page-notification-button.scss +2 -0
- data/app/assets/stylesheets/govuk_publishing_components/components/_skip-link.scss +1 -0
- data/app/assets/stylesheets/govuk_publishing_components/components/_step-by-step-nav-header.scss +17 -0
- data/app/assets/stylesheets/govuk_publishing_components/components/_step-by-step-nav-related.scss +2 -0
- data/app/assets/stylesheets/govuk_publishing_components/components/_step-by-step-nav.scss +8 -0
- data/app/assets/stylesheets/govuk_publishing_components/components/_subscription-links.scss +2 -1
- data/app/assets/stylesheets/govuk_publishing_components/components/_success-alert.scss +1 -0
- data/app/assets/stylesheets/govuk_publishing_components/components/_summary-list.scss +1 -0
- data/app/assets/stylesheets/govuk_publishing_components/components/_table.scss +1 -0
- data/app/assets/stylesheets/govuk_publishing_components/components/_tabs.scss +1 -0
- data/app/assets/stylesheets/govuk_publishing_components/components/_textarea.scss +17 -0
- data/app/assets/stylesheets/govuk_publishing_components/components/_title.scss +12 -0
- data/app/assets/stylesheets/govuk_publishing_components/components/_translation-nav.scss +2 -0
- data/app/assets/stylesheets/govuk_publishing_components/components/_warning-text.scss +1 -0
- data/app/assets/stylesheets/govuk_publishing_components/components/govspeak/_steps.scss +26 -9
- data/app/assets/stylesheets/govuk_publishing_components/components/govspeak/_tables.scss +12 -0
- data/app/assets/stylesheets/govuk_publishing_components/components/helpers/_brand-colours.scss +2 -2
- data/app/assets/stylesheets/govuk_publishing_components/components/helpers/_contents-list-helper.scss +0 -1
- data/app/controllers/govuk_publishing_components/application_controller.rb +0 -13
- data/app/controllers/govuk_publishing_components/audit_controller.rb +1 -1
- data/app/controllers/govuk_publishing_components/component_guide_controller.rb +6 -9
- data/app/models/govuk_publishing_components/audit_applications.rb +10 -19
- data/app/models/govuk_publishing_components/audit_comparer.rb +29 -24
- data/app/models/govuk_publishing_components/audit_components.rb +157 -82
- data/app/models/govuk_publishing_components/component_doc.rb +14 -0
- data/app/models/govuk_publishing_components/component_wrapper_helper_options.rb +15 -0
- data/app/views/govuk_publishing_components/audit/_applications.html.erb +3 -3
- data/app/views/govuk_publishing_components/audit/_component_contents.html.erb +47 -39
- data/app/views/govuk_publishing_components/audit/_components.html.erb +47 -2
- data/app/views/govuk_publishing_components/component_guide/_application_stylesheet.html.erb +0 -3
- data/app/views/govuk_publishing_components/component_guide/index.html.erb +0 -7
- data/app/views/govuk_publishing_components/component_guide/show.html.erb +21 -6
- data/app/views/govuk_publishing_components/components/_accordion.html.erb +30 -36
- data/app/views/govuk_publishing_components/components/_action_link.html.erb +7 -2
- data/app/views/govuk_publishing_components/components/_attachment.html.erb +2 -0
- data/app/views/govuk_publishing_components/components/_attachment_link.html.erb +2 -0
- data/app/views/govuk_publishing_components/components/_back_link.html.erb +2 -0
- data/app/views/govuk_publishing_components/components/_big_number.html.erb +3 -1
- data/app/views/govuk_publishing_components/components/_breadcrumbs.html.erb +8 -2
- data/app/views/govuk_publishing_components/components/_button.html.erb +2 -0
- data/app/views/govuk_publishing_components/components/_cards.html.erb +6 -4
- data/app/views/govuk_publishing_components/components/_character_count.html.erb +2 -0
- data/app/views/govuk_publishing_components/components/_checkboxes.html.erb +6 -2
- data/app/views/govuk_publishing_components/components/_contents_list.html.erb +11 -15
- data/app/views/govuk_publishing_components/components/_contextual_breadcrumbs.html.erb +7 -4
- data/app/views/govuk_publishing_components/components/_contextual_footer.html.erb +2 -0
- data/app/views/govuk_publishing_components/components/_contextual_guidance.html.erb +2 -0
- data/app/views/govuk_publishing_components/components/_contextual_sidebar.html.erb +13 -6
- data/app/views/govuk_publishing_components/components/_cookie_banner.html.erb +12 -6
- data/app/views/govuk_publishing_components/components/_date_input.html.erb +2 -0
- data/app/views/govuk_publishing_components/components/_details.html.erb +5 -1
- data/app/views/govuk_publishing_components/components/_devolved_nations.html.erb +2 -0
- data/app/views/govuk_publishing_components/components/_document_list.html.erb +3 -0
- data/app/views/govuk_publishing_components/components/_emergency_banner.html.erb +2 -0
- data/app/views/govuk_publishing_components/components/_error_alert.html.erb +2 -0
- data/app/views/govuk_publishing_components/components/_error_message.html.erb +4 -1
- data/app/views/govuk_publishing_components/components/_error_summary.html.erb +29 -26
- data/app/views/govuk_publishing_components/components/_feedback.html.erb +2 -0
- data/app/views/govuk_publishing_components/components/_fieldset.html.erb +2 -0
- data/app/views/govuk_publishing_components/components/_file_upload.html.erb +2 -0
- data/app/views/govuk_publishing_components/components/_google_tag_manager_script.html.erb +2 -2
- data/app/views/govuk_publishing_components/components/_govspeak.html.erb +1 -0
- data/app/views/govuk_publishing_components/components/_govspeak_html_publication.html.erb +2 -0
- data/app/views/govuk_publishing_components/components/_heading.html.erb +2 -0
- data/app/views/govuk_publishing_components/components/_hint.html.erb +4 -1
- data/app/views/govuk_publishing_components/components/_image_card.html.erb +17 -12
- data/app/views/govuk_publishing_components/components/_input.html.erb +10 -2
- data/app/views/govuk_publishing_components/components/_inset_text.html.erb +2 -0
- data/app/views/govuk_publishing_components/components/_intervention.html.erb +2 -0
- data/app/views/govuk_publishing_components/components/_inverse_header.html.erb +2 -0
- data/app/views/govuk_publishing_components/components/_label.html.erb +7 -3
- data/app/views/govuk_publishing_components/components/_layout_footer.html.erb +2 -0
- data/app/views/govuk_publishing_components/components/_layout_for_admin.html.erb +8 -5
- data/app/views/govuk_publishing_components/components/_layout_for_public.html.erb +8 -3
- data/app/views/govuk_publishing_components/components/_layout_header.html.erb +2 -0
- data/app/views/govuk_publishing_components/components/_layout_super_navigation_header.html.erb +238 -267
- data/app/views/govuk_publishing_components/components/_lead_paragraph.html.erb +2 -0
- data/app/views/govuk_publishing_components/components/_metadata.html.erb +2 -0
- data/app/views/govuk_publishing_components/components/_modal_dialogue.html.erb +2 -0
- data/app/views/govuk_publishing_components/components/_notice.html.erb +2 -0
- data/app/views/govuk_publishing_components/components/_organisation_logo.html.erb +2 -0
- data/app/views/govuk_publishing_components/components/_panel.html.erb +2 -0
- data/app/views/govuk_publishing_components/components/_phase_banner.html.erb +3 -1
- data/app/views/govuk_publishing_components/components/_previous_and_next_navigation.html.erb +6 -1
- data/app/views/govuk_publishing_components/components/_print_link.html.erb +2 -0
- data/app/views/govuk_publishing_components/components/_radio.html.erb +2 -0
- data/app/views/govuk_publishing_components/components/_related_navigation.html.erb +16 -6
- data/app/views/govuk_publishing_components/components/_reorderable_list.html.erb +2 -0
- data/app/views/govuk_publishing_components/components/_search.html.erb +2 -0
- data/app/views/govuk_publishing_components/components/_select.html.erb +2 -0
- data/app/views/govuk_publishing_components/components/_share_links.html.erb +13 -13
- data/app/views/govuk_publishing_components/components/_show_password.html.erb +2 -0
- data/app/views/govuk_publishing_components/components/_signup_link.html.erb +2 -0
- data/app/views/govuk_publishing_components/components/_single_page_notification_button.html.erb +8 -2
- data/app/views/govuk_publishing_components/components/_skip_link.html.erb +2 -0
- data/app/views/govuk_publishing_components/components/_step_by_step_nav.html.erb +8 -1
- data/app/views/govuk_publishing_components/components/_step_by_step_nav_header.html.erb +12 -2
- data/app/views/govuk_publishing_components/components/_step_by_step_nav_related.html.erb +21 -8
- data/app/views/govuk_publishing_components/components/_subscription_links.html.erb +3 -1
- data/app/views/govuk_publishing_components/components/_success_alert.html.erb +2 -0
- data/app/views/govuk_publishing_components/components/_summary_list.html.erb +2 -0
- data/app/views/govuk_publishing_components/components/_table.html.erb +3 -1
- data/app/views/govuk_publishing_components/components/_tabs.html.erb +22 -2
- data/app/views/govuk_publishing_components/components/_textarea.html.erb +12 -2
- data/app/views/govuk_publishing_components/components/_title.html.erb +2 -0
- data/app/views/govuk_publishing_components/components/_translation_nav.html.erb +2 -0
- data/app/views/govuk_publishing_components/components/_warning_text.html.erb +2 -0
- data/app/views/govuk_publishing_components/components/contextual_sidebar/_ukraine_cta.html.erb +16 -6
- data/app/views/govuk_publishing_components/components/docs/accordion.yml +16 -3
- data/app/views/govuk_publishing_components/components/docs/action_link.yml +1 -0
- data/app/views/govuk_publishing_components/components/docs/breadcrumbs.yml +2 -1
- data/app/views/govuk_publishing_components/components/docs/button.yml +10 -0
- data/app/views/govuk_publishing_components/components/docs/cards.yml +1 -0
- data/app/views/govuk_publishing_components/components/docs/checkboxes.yml +1 -0
- data/app/views/govuk_publishing_components/components/docs/contents_list.yml +1 -12
- data/app/views/govuk_publishing_components/components/docs/contextual_breadcrumbs.yml +13 -0
- data/app/views/govuk_publishing_components/components/docs/contextual_footer.yml +43 -0
- data/app/views/govuk_publishing_components/components/docs/contextual_sidebar.yml +65 -0
- data/app/views/govuk_publishing_components/components/docs/details.yml +17 -0
- data/app/views/govuk_publishing_components/components/docs/document_list.yml +18 -1
- data/app/views/govuk_publishing_components/components/docs/emergency_banner.yml +3 -1
- data/app/views/govuk_publishing_components/components/docs/error_message.yml +13 -0
- data/app/views/govuk_publishing_components/components/docs/govspeak.yml +22 -1
- data/app/views/govuk_publishing_components/components/docs/hint.yml +6 -0
- data/app/views/govuk_publishing_components/components/docs/image_card.yml +24 -1
- data/app/views/govuk_publishing_components/components/docs/input.yml +32 -0
- data/app/views/govuk_publishing_components/components/docs/intervention.yml +2 -1
- data/app/views/govuk_publishing_components/components/docs/label.yml +17 -0
- data/app/views/govuk_publishing_components/components/docs/layout_header.yml +1 -0
- data/app/views/govuk_publishing_components/components/docs/previous_and_next_navigation.yml +2 -0
- data/app/views/govuk_publishing_components/components/docs/related_navigation.yml +47 -0
- data/app/views/govuk_publishing_components/components/docs/share_links.yml +59 -30
- data/app/views/govuk_publishing_components/components/docs/single_page_notification_button.yml +16 -1
- data/app/views/govuk_publishing_components/components/docs/step_by_step_nav.yml +54 -0
- data/app/views/govuk_publishing_components/components/docs/step_by_step_nav_header.yml +6 -0
- data/app/views/govuk_publishing_components/components/docs/step_by_step_nav_related.yml +10 -0
- data/app/views/govuk_publishing_components/components/docs/tabs.yml +15 -0
- data/app/views/govuk_publishing_components/components/docs/textarea.yml +31 -0
- data/app/views/govuk_publishing_components/components/docs/translation_nav.yml +2 -0
- data/app/views/govuk_publishing_components/components/feedback/_problem_form.html.erb +3 -3
- data/app/views/govuk_publishing_components/components/feedback/_survey_signup_form.html.erb +1 -1
- data/app/views/govuk_publishing_components/components/feedback/_yes_no_banner.html.erb +4 -5
- data/app/views/govuk_publishing_components/components/metadata/_sentence.html.erb +4 -2
- data/app/views/govuk_publishing_components/components/related_navigation/_section.html.erb +36 -16
- data/app/views/layouts/govuk_publishing_components/application.html.erb +3 -4
- data/config/locales/ar.yml +14 -14
- data/config/locales/az.yml +15 -14
- data/config/locales/be.yml +14 -14
- data/config/locales/bg.yml +14 -14
- data/config/locales/bn.yml +14 -14
- data/config/locales/cs.yml +14 -14
- data/config/locales/cy.yml +14 -14
- data/config/locales/da.yml +14 -14
- data/config/locales/de.yml +14 -14
- data/config/locales/dr.yml +14 -14
- data/config/locales/el.yml +14 -14
- data/config/locales/en.yml +21 -28
- data/config/locales/es-419.yml +14 -14
- data/config/locales/es.yml +14 -14
- data/config/locales/et.yml +14 -14
- data/config/locales/fa.yml +15 -14
- data/config/locales/fi.yml +14 -14
- data/config/locales/fr.yml +14 -14
- data/config/locales/gd.yml +14 -14
- data/config/locales/gu.yml +14 -14
- data/config/locales/he.yml +14 -14
- data/config/locales/hi.yml +14 -14
- data/config/locales/hr.yml +14 -14
- data/config/locales/hu.yml +14 -14
- data/config/locales/hy.yml +14 -14
- data/config/locales/id.yml +14 -14
- data/config/locales/is.yml +14 -14
- data/config/locales/it.yml +14 -14
- data/config/locales/ja.yml +14 -14
- data/config/locales/ka.yml +14 -14
- data/config/locales/kk.yml +14 -14
- data/config/locales/ko.yml +14 -14
- data/config/locales/lt.yml +14 -14
- data/config/locales/lv.yml +14 -14
- data/config/locales/ms.yml +14 -14
- data/config/locales/mt.yml +14 -14
- data/config/locales/nl.yml +14 -14
- data/config/locales/no.yml +14 -14
- data/config/locales/pa-pk.yml +14 -14
- data/config/locales/pa.yml +14 -14
- data/config/locales/pl.yml +14 -14
- data/config/locales/ps.yml +14 -14
- data/config/locales/pt.yml +14 -14
- data/config/locales/ro.yml +14 -14
- data/config/locales/ru.yml +14 -14
- data/config/locales/si.yml +14 -14
- data/config/locales/sk.yml +14 -14
- data/config/locales/sl.yml +14 -14
- data/config/locales/so.yml +14 -14
- data/config/locales/sq.yml +14 -14
- data/config/locales/sr.yml +14 -14
- data/config/locales/sv.yml +14 -14
- data/config/locales/sw.yml +14 -14
- data/config/locales/ta.yml +14 -14
- data/config/locales/th.yml +14 -14
- data/config/locales/tk.yml +14 -14
- data/config/locales/tr.yml +14 -14
- data/config/locales/uk.yml +14 -14
- data/config/locales/ur.yml +14 -14
- data/config/locales/uz.yml +14 -14
- data/config/locales/vi.yml +14 -14
- data/config/locales/zh-hk.yml +14 -14
- data/config/locales/zh-tw.yml +14 -14
- data/config/locales/zh.yml +14 -14
- data/lib/govuk_publishing_components/app_helpers/asset_helper.rb +86 -0
- data/lib/govuk_publishing_components/config.rb +3 -3
- data/lib/govuk_publishing_components/presenters/accordion_helper.rb +38 -0
- data/lib/govuk_publishing_components/presenters/breadcrumb_selector.rb +3 -2
- data/lib/govuk_publishing_components/presenters/{breadcrumbs.rb → breadcrumbs_helper.rb} +8 -0
- data/lib/govuk_publishing_components/presenters/button_helper.rb +9 -2
- data/lib/govuk_publishing_components/presenters/component_wrapper_helper.rb +95 -0
- data/lib/govuk_publishing_components/presenters/image_card_helper.rb +65 -2
- data/lib/govuk_publishing_components/presenters/page_with_step_by_step_navigation.rb +3 -2
- data/lib/govuk_publishing_components/presenters/related_navigation_helper.rb +16 -7
- data/lib/govuk_publishing_components/presenters/single_page_notification_button_helper.rb +43 -2
- data/lib/govuk_publishing_components/presenters/step_by_step_nav_helper.rb +16 -0
- data/lib/govuk_publishing_components/railtie.rb +7 -0
- data/lib/govuk_publishing_components/version.rb +1 -1
- data/lib/govuk_publishing_components.rb +6 -1
- data/node_modules/axe-core/README.md +1 -1
- data/node_modules/axe-core/axe.d.ts +76 -24
- data/node_modules/axe-core/axe.js +9200 -9059
- data/node_modules/axe-core/axe.min.js +3 -3
- data/node_modules/axe-core/package.json +29 -29
- data/node_modules/axe-core/sri-history.json +20 -0
- data/node_modules/govuk-frontend/README.md +1 -2
- data/node_modules/govuk-frontend/govuk/all.js +4035 -2673
- data/node_modules/govuk-frontend/govuk/all.js.map +1 -0
- data/node_modules/govuk-frontend/govuk/common/closest-attribute-value.js +71 -0
- data/node_modules/govuk-frontend/govuk/common/closest-attribute-value.js.map +1 -0
- data/node_modules/govuk-frontend/govuk/common/index.js +180 -0
- data/node_modules/govuk-frontend/govuk/common/index.js.map +1 -0
- data/node_modules/govuk-frontend/govuk/common/normalise-dataset.js +376 -0
- data/node_modules/govuk-frontend/govuk/common/normalise-dataset.js.map +1 -0
- data/node_modules/govuk-frontend/govuk/common.js +173 -30
- data/node_modules/govuk-frontend/govuk/common.js.map +1 -0
- data/node_modules/govuk-frontend/govuk/components/_all.scss +1 -1
- data/node_modules/govuk-frontend/govuk/components/accordion/_index.scss +23 -4
- data/node_modules/govuk-frontend/govuk/components/accordion/accordion.js +2116 -983
- data/node_modules/govuk-frontend/govuk/components/accordion/accordion.js.map +1 -0
- data/node_modules/govuk-frontend/govuk/components/accordion/fixtures.json +54 -22
- data/node_modules/govuk-frontend/govuk/components/accordion/macro-options.json +36 -0
- data/node_modules/govuk-frontend/govuk/components/accordion/template.njk +8 -2
- data/node_modules/govuk-frontend/govuk/components/back-link/_index.scss +19 -19
- data/node_modules/govuk-frontend/govuk/components/back-link/fixtures.json +12 -12
- data/node_modules/govuk-frontend/govuk/components/breadcrumbs/_index.scss +21 -10
- data/node_modules/govuk-frontend/govuk/components/breadcrumbs/fixtures.json +22 -22
- data/node_modules/govuk-frontend/govuk/components/button/_index.scss +23 -5
- data/node_modules/govuk-frontend/govuk/components/button/button.js +958 -690
- data/node_modules/govuk-frontend/govuk/components/button/button.js.map +1 -0
- data/node_modules/govuk-frontend/govuk/components/button/fixtures.json +85 -66
- data/node_modules/govuk-frontend/govuk/components/button/template.njk +1 -1
- data/node_modules/govuk-frontend/govuk/components/character-count/_index.scss +9 -0
- data/node_modules/govuk-frontend/govuk/components/character-count/character-count.js +2083 -1161
- data/node_modules/govuk-frontend/govuk/components/character-count/character-count.js.map +1 -0
- data/node_modules/govuk-frontend/govuk/components/character-count/fixtures.json +112 -36
- data/node_modules/govuk-frontend/govuk/components/character-count/macro-options.json +42 -0
- data/node_modules/govuk-frontend/govuk/components/character-count/template.njk +27 -3
- data/node_modules/govuk-frontend/govuk/components/checkboxes/checkboxes.js +1155 -1119
- data/node_modules/govuk-frontend/govuk/components/checkboxes/checkboxes.js.map +1 -0
- data/node_modules/govuk-frontend/govuk/components/checkboxes/fixtures.json +96 -93
- data/node_modules/govuk-frontend/govuk/components/cookie-banner/fixtures.json +46 -46
- data/node_modules/govuk-frontend/govuk/components/cookie-banner/template.njk +1 -1
- data/node_modules/govuk-frontend/govuk/components/date-input/fixtures.json +50 -50
- data/node_modules/govuk-frontend/govuk/components/details/details.js +797 -766
- data/node_modules/govuk-frontend/govuk/components/details/details.js.map +1 -0
- data/node_modules/govuk-frontend/govuk/components/details/fixtures.json +20 -20
- data/node_modules/govuk-frontend/govuk/components/error-message/fixtures.json +20 -20
- data/node_modules/govuk-frontend/govuk/components/error-summary/error-summary.js +1089 -814
- data/node_modules/govuk-frontend/govuk/components/error-summary/error-summary.js.map +1 -0
- data/node_modules/govuk-frontend/govuk/components/error-summary/fixtures.json +44 -35
- data/node_modules/govuk-frontend/govuk/components/error-summary/template.njk +25 -21
- data/node_modules/govuk-frontend/govuk/components/fieldset/fixtures.json +51 -39
- data/node_modules/govuk-frontend/govuk/components/file-upload/fixtures.json +26 -26
- data/node_modules/govuk-frontend/govuk/components/footer/_index.scss +1 -1
- data/node_modules/govuk-frontend/govuk/components/footer/fixtures.json +46 -46
- data/node_modules/govuk-frontend/govuk/components/footer/macro-options.json +2 -2
- data/node_modules/govuk-frontend/govuk/components/header/_index.scss +6 -0
- data/node_modules/govuk-frontend/govuk/components/header/fixtures.json +93 -38
- data/node_modules/govuk-frontend/govuk/components/header/header.js +646 -992
- data/node_modules/govuk-frontend/govuk/components/header/header.js.map +1 -0
- data/node_modules/govuk-frontend/govuk/components/header/macro-options.json +8 -2
- data/node_modules/govuk-frontend/govuk/components/header/template.njk +4 -2
- data/node_modules/govuk-frontend/govuk/components/hint/fixtures.json +12 -12
- data/node_modules/govuk-frontend/govuk/components/input/fixtures.json +80 -80
- data/node_modules/govuk-frontend/govuk/components/inset-text/fixtures.json +12 -12
- data/node_modules/govuk-frontend/govuk/components/label/fixtures.json +34 -34
- data/node_modules/govuk-frontend/govuk/components/notification-banner/fixtures.json +56 -46
- data/node_modules/govuk-frontend/govuk/components/notification-banner/notification-banner.js +790 -532
- data/node_modules/govuk-frontend/govuk/components/notification-banner/notification-banner.js.map +1 -0
- data/node_modules/govuk-frontend/govuk/components/notification-banner/template.njk +1 -1
- data/node_modules/govuk-frontend/govuk/components/pagination/_index.scss +10 -7
- data/node_modules/govuk-frontend/govuk/components/pagination/fixtures.json +94 -26
- data/node_modules/govuk-frontend/govuk/components/pagination/template.njk +1 -1
- data/node_modules/govuk-frontend/govuk/components/panel/fixtures.json +18 -18
- data/node_modules/govuk-frontend/govuk/components/phase-banner/fixtures.json +14 -14
- data/node_modules/govuk-frontend/govuk/components/phase-banner/macro-options.json +1 -1
- data/node_modules/govuk-frontend/govuk/components/radios/fixtures.json +94 -91
- data/node_modules/govuk-frontend/govuk/components/radios/radios.js +1110 -1079
- data/node_modules/govuk-frontend/govuk/components/radios/radios.js.map +1 -0
- data/node_modules/govuk-frontend/govuk/components/select/fixtures.json +32 -32
- data/node_modules/govuk-frontend/govuk/components/skip-link/fixtures.json +22 -20
- data/node_modules/govuk-frontend/govuk/components/skip-link/skip-link.js +1017 -1008
- data/node_modules/govuk-frontend/govuk/components/skip-link/skip-link.js.map +1 -0
- data/node_modules/govuk-frontend/govuk/components/summary-list/_index.scss +107 -0
- data/node_modules/govuk-frontend/govuk/components/summary-list/fixtures.json +345 -50
- data/node_modules/govuk-frontend/govuk/components/summary-list/macro-options.json +110 -0
- data/node_modules/govuk-frontend/govuk/components/summary-list/template.njk +72 -28
- data/node_modules/govuk-frontend/govuk/components/table/_index.scss +1 -1
- data/node_modules/govuk-frontend/govuk/components/table/fixtures.json +40 -40
- data/node_modules/govuk-frontend/govuk/components/tabs/fixtures.json +29 -29
- data/node_modules/govuk-frontend/govuk/components/tabs/tabs.js +1389 -1233
- data/node_modules/govuk-frontend/govuk/components/tabs/tabs.js.map +1 -0
- data/node_modules/govuk-frontend/govuk/components/tag/fixtures.json +28 -28
- data/node_modules/govuk-frontend/govuk/components/textarea/fixtures.json +34 -34
- data/node_modules/govuk-frontend/govuk/components/warning-text/fixtures.json +14 -14
- data/node_modules/govuk-frontend/govuk/core/_section-break.scss +1 -1
- data/node_modules/govuk-frontend/govuk/helpers/_colour.scss +2 -2
- data/node_modules/govuk-frontend/govuk/helpers/_focused.scss +5 -0
- data/node_modules/govuk-frontend/govuk/helpers/_links.scss +6 -6
- data/node_modules/govuk-frontend/govuk/i18n.js +389 -0
- data/node_modules/govuk-frontend/govuk/i18n.js.map +1 -0
- data/node_modules/govuk-frontend/govuk/macros/i18n.njk +15 -0
- data/node_modules/govuk-frontend/govuk/settings/_all.scss +1 -0
- data/node_modules/govuk-frontend/govuk/settings/_colours-palette.scss +12 -0
- data/node_modules/govuk-frontend/govuk/settings/_compatibility.scss +26 -0
- data/node_modules/govuk-frontend/govuk/settings/_measurements.scss +5 -5
- data/node_modules/govuk-frontend/govuk/settings/_typography-font.scss +23 -0
- data/node_modules/govuk-frontend/govuk/settings/_typography-responsive.scss +12 -0
- data/node_modules/govuk-frontend/govuk/settings/_warnings.scss +53 -0
- data/node_modules/govuk-frontend/govuk/tools/_compatibility.scss +20 -6
- data/node_modules/govuk-frontend/govuk/vendor/polyfills/DOMTokenList.js +242 -241
- data/node_modules/govuk-frontend/govuk/vendor/polyfills/DOMTokenList.js.map +1 -0
- data/node_modules/govuk-frontend/govuk/vendor/polyfills/Date/now.js +22 -0
- data/node_modules/govuk-frontend/govuk/vendor/polyfills/Date/now.js.map +1 -0
- data/node_modules/govuk-frontend/govuk/vendor/polyfills/Document.js +17 -16
- data/node_modules/govuk-frontend/govuk/vendor/polyfills/Document.js.map +1 -0
- data/node_modules/govuk-frontend/govuk/vendor/polyfills/Element/prototype/classList.js +547 -546
- data/node_modules/govuk-frontend/govuk/vendor/polyfills/Element/prototype/classList.js.map +1 -0
- data/node_modules/govuk-frontend/govuk/vendor/polyfills/Element/prototype/closest.js +37 -36
- data/node_modules/govuk-frontend/govuk/vendor/polyfills/Element/prototype/closest.js.map +1 -0
- data/node_modules/govuk-frontend/govuk/vendor/polyfills/Element/prototype/dataset.js +301 -0
- data/node_modules/govuk-frontend/govuk/vendor/polyfills/Element/prototype/dataset.js.map +1 -0
- data/node_modules/govuk-frontend/govuk/vendor/polyfills/Element/prototype/matches.js +21 -20
- data/node_modules/govuk-frontend/govuk/vendor/polyfills/Element/prototype/matches.js.map +1 -0
- data/node_modules/govuk-frontend/govuk/vendor/polyfills/Element/prototype/nextElementSibling.js +198 -197
- data/node_modules/govuk-frontend/govuk/vendor/polyfills/Element/prototype/nextElementSibling.js.map +1 -0
- data/node_modules/govuk-frontend/govuk/vendor/polyfills/Element/prototype/previousElementSibling.js +198 -197
- data/node_modules/govuk-frontend/govuk/vendor/polyfills/Element/prototype/previousElementSibling.js.map +1 -0
- data/node_modules/govuk-frontend/govuk/vendor/polyfills/Element.js +106 -105
- data/node_modules/govuk-frontend/govuk/vendor/polyfills/Element.js.map +1 -0
- data/node_modules/govuk-frontend/govuk/vendor/polyfills/Event.js +400 -399
- data/node_modules/govuk-frontend/govuk/vendor/polyfills/Event.js.map +1 -0
- data/node_modules/govuk-frontend/govuk/vendor/polyfills/Function/prototype/bind.js +239 -238
- data/node_modules/govuk-frontend/govuk/vendor/polyfills/Function/prototype/bind.js.map +1 -0
- data/node_modules/govuk-frontend/govuk/vendor/polyfills/Object/defineProperty.js +72 -71
- data/node_modules/govuk-frontend/govuk/vendor/polyfills/Object/defineProperty.js.map +1 -0
- data/node_modules/govuk-frontend/govuk/vendor/polyfills/String/prototype/trim.js +22 -0
- data/node_modules/govuk-frontend/govuk/vendor/polyfills/String/prototype/trim.js.map +1 -0
- data/node_modules/govuk-frontend/govuk/vendor/polyfills/Window.js +17 -16
- data/node_modules/govuk-frontend/govuk/vendor/polyfills/Window.js.map +1 -0
- data/node_modules/govuk-frontend/govuk-esm/all.mjs +52 -29
- data/node_modules/govuk-frontend/govuk-esm/common/closest-attribute-value.mjs +15 -0
- data/node_modules/govuk-frontend/govuk-esm/common/index.mjs +166 -0
- data/node_modules/govuk-frontend/govuk-esm/common/normalise-dataset.mjs +60 -0
- data/node_modules/govuk-frontend/govuk-esm/common.mjs +6 -28
- data/node_modules/govuk-frontend/govuk-esm/components/accordion/accordion.mjs +238 -85
- data/node_modules/govuk-frontend/govuk-esm/components/button/button.mjs +73 -34
- data/node_modules/govuk-frontend/govuk-esm/components/character-count/character-count.mjs +329 -124
- data/node_modules/govuk-frontend/govuk-esm/components/checkboxes/checkboxes.mjs +32 -20
- data/node_modules/govuk-frontend/govuk-esm/components/details/details.mjs +41 -20
- data/node_modules/govuk-frontend/govuk-esm/components/error-summary/error-summary.mjs +60 -14
- data/node_modules/govuk-frontend/govuk-esm/components/header/header.mjs +9 -2
- data/node_modules/govuk-frontend/govuk-esm/components/notification-banner/notification-banner.mjs +33 -4
- data/node_modules/govuk-frontend/govuk-esm/components/radios/radios.mjs +18 -11
- data/node_modules/govuk-frontend/govuk-esm/components/skip-link/skip-link.mjs +15 -7
- data/node_modules/govuk-frontend/govuk-esm/components/tabs/tabs.mjs +171 -38
- data/node_modules/govuk-frontend/govuk-esm/i18n.mjs +378 -0
- data/node_modules/govuk-frontend/govuk-esm/vendor/polyfills/Date/now.mjs +13 -0
- data/node_modules/govuk-frontend/govuk-esm/vendor/polyfills/Element/prototype/dataset.mjs +68 -0
- data/node_modules/govuk-frontend/govuk-esm/vendor/polyfills/String/prototype/trim.mjs +13 -0
- data/node_modules/govuk-frontend/govuk-prototype-kit/init.js +7 -0
- data/node_modules/govuk-frontend/govuk-prototype-kit/init.scss +12 -0
- data/node_modules/govuk-frontend/govuk-prototype-kit.config.json +138 -7
- data/node_modules/govuk-frontend/package.json +1 -1
- metadata +70 -19
- data/app/assets/stylesheets/component_guide/print.scss +0 -1
- data/app/assets/stylesheets/govuk_publishing_components/_all_components_print.scss +0 -18
- data/app/assets/stylesheets/govuk_publishing_components/components/print/_accordion.scss +0 -28
- data/app/assets/stylesheets/govuk_publishing_components/components/print/_button.scss +0 -8
- data/app/assets/stylesheets/govuk_publishing_components/components/print/_cards.scss +0 -4
- data/app/assets/stylesheets/govuk_publishing_components/components/print/_contents-list.scss +0 -19
- data/app/assets/stylesheets/govuk_publishing_components/components/print/_emergency-banner.scss +0 -3
- data/app/assets/stylesheets/govuk_publishing_components/components/print/_govspeak-html-publication.scss +0 -5
- data/app/assets/stylesheets/govuk_publishing_components/components/print/_govspeak.scss +0 -80
- data/app/assets/stylesheets/govuk_publishing_components/components/print/_layout-super-navigation-header.scss +0 -3
- data/app/assets/stylesheets/govuk_publishing_components/components/print/_organisation-logo.scss +0 -7
- data/app/assets/stylesheets/govuk_publishing_components/components/print/_step-by-step-nav-header.scss +0 -7
- data/app/assets/stylesheets/govuk_publishing_components/components/print/_step-by-step-nav.scss +0 -116
- data/app/assets/stylesheets/govuk_publishing_components/components/print/_textarea.scss +0 -13
- data/app/assets/stylesheets/govuk_publishing_components/components/print/_title.scss +0 -7
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
window.GOVUK = window.GOVUK || {}
|
|
2
|
+
window.GOVUK.Modules = window.GOVUK.Modules || {};
|
|
3
|
+
|
|
4
|
+
(function (Modules) {
|
|
5
|
+
'use strict'
|
|
6
|
+
|
|
7
|
+
function Ga4FormTracker (module) {
|
|
8
|
+
this.module = module
|
|
9
|
+
this.trackingTrigger = 'data-ga4-form' // elements with this attribute get tracked
|
|
10
|
+
this.includeTextInputValues = this.module.hasAttribute('data-ga4-form-include-text')
|
|
11
|
+
this.redacted = false
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
Ga4FormTracker.prototype.init = function () {
|
|
15
|
+
var consentCookie = window.GOVUK.getConsentCookie()
|
|
16
|
+
|
|
17
|
+
if (consentCookie && consentCookie.settings) {
|
|
18
|
+
this.startModule()
|
|
19
|
+
} else {
|
|
20
|
+
this.startModule = this.startModule.bind(this)
|
|
21
|
+
window.addEventListener('cookie-consent', this.startModule)
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
// triggered by cookie-consent event, which happens when users consent to cookies
|
|
26
|
+
Ga4FormTracker.prototype.startModule = function () {
|
|
27
|
+
if (window.dataLayer) {
|
|
28
|
+
this.module.addEventListener('submit', this.trackFormSubmit.bind(this))
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
Ga4FormTracker.prototype.trackFormSubmit = function (event) {
|
|
33
|
+
var target = window.GOVUK.analyticsGa4.core.trackFunctions.findTrackingAttributes(event.target, this.trackingTrigger)
|
|
34
|
+
if (target) {
|
|
35
|
+
try {
|
|
36
|
+
var data = target.getAttribute(this.trackingTrigger)
|
|
37
|
+
data = JSON.parse(data)
|
|
38
|
+
} catch (e) {
|
|
39
|
+
// if there's a problem with the config, don't start the tracker
|
|
40
|
+
console.warn('GA4 configuration error: ' + e.message, window.location)
|
|
41
|
+
return
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
var formInputs = this.getFormInputs()
|
|
45
|
+
var formData = this.getInputValues(formInputs)
|
|
46
|
+
data.text = this.combineGivenAnswers(formData) || 'No answer given'
|
|
47
|
+
|
|
48
|
+
var schemas = new window.GOVUK.analyticsGa4.Schemas()
|
|
49
|
+
var schema = schemas.mergeProperties(data, 'event_data')
|
|
50
|
+
window.GOVUK.analyticsGa4.core.sendData(schema)
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
Ga4FormTracker.prototype.getFormInputs = function () {
|
|
55
|
+
var inputs = []
|
|
56
|
+
var labels = this.module.querySelectorAll('label')
|
|
57
|
+
|
|
58
|
+
for (var i = 0; i < labels.length; i++) {
|
|
59
|
+
var label = labels[i]
|
|
60
|
+
var labelFor = label.getAttribute('for')
|
|
61
|
+
var input = false
|
|
62
|
+
if (labelFor) {
|
|
63
|
+
input = this.module.querySelector('[id=' + labelFor + ']')
|
|
64
|
+
} else {
|
|
65
|
+
input = label.querySelector('input')
|
|
66
|
+
}
|
|
67
|
+
inputs.push({
|
|
68
|
+
input: input,
|
|
69
|
+
label: label
|
|
70
|
+
})
|
|
71
|
+
}
|
|
72
|
+
return inputs
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
Ga4FormTracker.prototype.getInputValues = function (inputs) {
|
|
76
|
+
for (var i = inputs.length - 1; i >= 0; i--) {
|
|
77
|
+
var input = inputs[i]
|
|
78
|
+
var elem = input.input
|
|
79
|
+
var labelText = input.label.innerText || input.label.textContent
|
|
80
|
+
var inputType = elem.getAttribute('type')
|
|
81
|
+
var inputNodename = elem.nodeName
|
|
82
|
+
|
|
83
|
+
if (inputType === 'checkbox' && elem.checked) {
|
|
84
|
+
input.answer = labelText
|
|
85
|
+
} else if (inputNodename === 'SELECT' && elem.options[elem.selectedIndex].value) {
|
|
86
|
+
input.answer = elem.options[elem.selectedIndex].text
|
|
87
|
+
} else if ((inputType === 'text' || inputType === 'search') && elem.value) {
|
|
88
|
+
if (this.includeTextInputValues) {
|
|
89
|
+
var PIIRemover = new window.GOVUK.analyticsGa4.PIIRemover()
|
|
90
|
+
input.answer = PIIRemover.stripPIIWithOverride(elem.value, true, true)
|
|
91
|
+
} else {
|
|
92
|
+
this.redacted = true
|
|
93
|
+
}
|
|
94
|
+
} else if (inputType === 'radio' && elem.checked) {
|
|
95
|
+
input.answer = labelText
|
|
96
|
+
} else {
|
|
97
|
+
// remove the input from those gathered as it has no value
|
|
98
|
+
inputs.splice(i, 1)
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
return inputs
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
Ga4FormTracker.prototype.combineGivenAnswers = function (data) {
|
|
105
|
+
var answers = []
|
|
106
|
+
for (var i = 0; i < data.length; i++) {
|
|
107
|
+
var answer = data[i].answer
|
|
108
|
+
if (answer) {
|
|
109
|
+
answers.push(answer)
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
if (this.redacted) {
|
|
113
|
+
answers.push('[REDACTED]')
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
answers = answers.join(',')
|
|
117
|
+
return answers
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
Modules.Ga4FormTracker = Ga4FormTracker
|
|
121
|
+
})(window.GOVUK.Modules)
|
|
@@ -1,331 +1,112 @@
|
|
|
1
|
-
|
|
1
|
+
//= require ../vendor/polyfills/closest.js
|
|
2
2
|
window.GOVUK = window.GOVUK || {}
|
|
3
|
-
window.GOVUK.
|
|
4
|
-
window.GOVUK.analyticsGa4.analyticsModules = window.GOVUK.analyticsGa4.analyticsModules || {};
|
|
3
|
+
window.GOVUK.Modules = window.GOVUK.Modules || {};
|
|
5
4
|
|
|
6
|
-
(function (
|
|
5
|
+
(function (Modules) {
|
|
7
6
|
'use strict'
|
|
8
7
|
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
this.appendDomainsWithoutWWW(this.internalDomains)
|
|
16
|
-
this.internalDownloadPaths = config.internalDownloadPaths || ['/government/uploads/']
|
|
17
|
-
this.dedicatedDownloadDomains = config.dedicatedDownloadDomains || ['assets.publishing.service.gov.uk']
|
|
18
|
-
this.appendDomainsWithoutWWW(this.dedicatedDownloadDomains)
|
|
19
|
-
this.handleClick = this.handleClick.bind(this)
|
|
20
|
-
this.handleMousedown = this.handleMousedown.bind(this)
|
|
8
|
+
function Ga4LinkTracker (module) {
|
|
9
|
+
this.module = module
|
|
10
|
+
this.trackingTrigger = 'data-ga4-link' // elements with this attribute get tracked
|
|
11
|
+
this.trackLinksOnly = this.module.hasAttribute('data-ga4-track-links-only')
|
|
12
|
+
this.limitToElementClass = this.module.getAttribute('data-ga4-limit-to-element-class')
|
|
13
|
+
}
|
|
21
14
|
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
document.querySelector('body').addEventListener('contextmenu', this.handleClick)
|
|
25
|
-
document.querySelector('body').addEventListener('mousedown', this.handleMousedown)
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
},
|
|
15
|
+
Ga4LinkTracker.prototype.init = function () {
|
|
16
|
+
var consentCookie = window.GOVUK.getConsentCookie()
|
|
29
17
|
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
18
|
+
if (consentCookie && consentCookie.settings) {
|
|
19
|
+
this.startModule()
|
|
20
|
+
} else {
|
|
21
|
+
this.startModule = this.startModule.bind(this)
|
|
22
|
+
window.addEventListener('cookie-consent', this.startModule)
|
|
23
|
+
}
|
|
24
|
+
}
|
|
35
25
|
|
|
36
|
-
|
|
37
|
-
|
|
26
|
+
// triggered by cookie-consent event, which happens when users consent to cookies
|
|
27
|
+
Ga4LinkTracker.prototype.startModule = function () {
|
|
28
|
+
if (window.dataLayer) {
|
|
29
|
+
this.handleClick = this.handleClick.bind(this)
|
|
30
|
+
this.handleMousedown = this.handleMousedown.bind(this)
|
|
38
31
|
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
32
|
+
this.module.addEventListener('click', this.handleClick)
|
|
33
|
+
this.module.addEventListener('contextmenu', this.handleClick)
|
|
34
|
+
this.module.addEventListener('mousedown', this.handleMousedown)
|
|
42
35
|
|
|
43
|
-
if (
|
|
44
|
-
|
|
36
|
+
if (this.module.hasAttribute('data-ga4-set-indexes')) {
|
|
37
|
+
window.GOVUK.analyticsGa4.core.trackFunctions.setIndexes(this.module)
|
|
45
38
|
}
|
|
39
|
+
}
|
|
40
|
+
}
|
|
46
41
|
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
if (
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
/* Since external links can't be determined in the template, we use populated-via-js as a signal
|
|
58
|
-
for our JavaScript to determine this value. */
|
|
59
|
-
if (clickData.external === 'populated-via-js' && clickData.url) {
|
|
60
|
-
clickData.external = this.isExternalLink(clickData.url) ? 'true' : 'false'
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
if (clickData.method === 'populated-via-js') {
|
|
64
|
-
clickData.method = this.getClickType(event)
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
if (clickData.index) {
|
|
68
|
-
clickData.index = parseInt(clickData.index)
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
if (clickData.index_total) {
|
|
72
|
-
clickData.index_total = parseInt(clickData.index_total)
|
|
73
|
-
}
|
|
74
|
-
} else if (this.isMailToLink(href)) {
|
|
75
|
-
clickData.event_name = 'navigation'
|
|
76
|
-
clickData.type = 'email'
|
|
77
|
-
clickData.external = 'true'
|
|
78
|
-
clickData.url = href
|
|
79
|
-
clickData.text = this.removeLinesAndExtraSpaces(element.textContent)
|
|
80
|
-
clickData.method = this.getClickType(event)
|
|
81
|
-
} else if (this.isDownloadLink(href)) {
|
|
82
|
-
clickData.event_name = 'file_download'
|
|
83
|
-
clickData.type = this.isPreviewLink(href) ? 'preview' : 'generic download'
|
|
84
|
-
clickData.external = this.isExternalLink(href) ? 'true' : 'false'
|
|
85
|
-
clickData.url = href
|
|
86
|
-
clickData.text = this.removeLinesAndExtraSpaces(element.textContent)
|
|
87
|
-
clickData.method = this.getClickType(event)
|
|
88
|
-
} else if (this.isExternalLink(href)) {
|
|
89
|
-
clickData.event_name = 'navigation'
|
|
90
|
-
clickData.type = 'generic link'
|
|
91
|
-
clickData.external = 'true'
|
|
92
|
-
clickData.url = href
|
|
93
|
-
clickData.text = this.removeLinesAndExtraSpaces(element.textContent)
|
|
94
|
-
clickData.method = this.getClickType(event)
|
|
42
|
+
Ga4LinkTracker.prototype.handleClick = function (event) {
|
|
43
|
+
var target = event.target
|
|
44
|
+
if (!this.trackLinksOnly) {
|
|
45
|
+
this.trackClick(event)
|
|
46
|
+
} else if (this.trackLinksOnly && target.closest('a')) {
|
|
47
|
+
if (!this.limitToElementClass) {
|
|
48
|
+
this.trackClick(event)
|
|
49
|
+
} else if (target.closest('.' + this.limitToElementClass)) {
|
|
50
|
+
this.trackClick(event)
|
|
95
51
|
}
|
|
52
|
+
}
|
|
53
|
+
}
|
|
96
54
|
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
var schema = new window.GOVUK.analyticsGa4.Schemas().eventSchema()
|
|
105
|
-
schema.event = 'event_data'
|
|
106
|
-
|
|
107
|
-
// get attributes from the clickData object to send to GA
|
|
108
|
-
// only allow it if it already exists in the schema
|
|
109
|
-
for (var property in clickData) {
|
|
110
|
-
if (property in schema.event_data) {
|
|
111
|
-
schema.event_data[property] = clickData[property]
|
|
112
|
-
}
|
|
113
|
-
}
|
|
55
|
+
Ga4LinkTracker.prototype.handleMousedown = function (event) {
|
|
56
|
+
// 1 = middle mouse button
|
|
57
|
+
if (event.button === 1) {
|
|
58
|
+
this.handleClick(event)
|
|
59
|
+
}
|
|
60
|
+
}
|
|
114
61
|
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
62
|
+
Ga4LinkTracker.prototype.trackClick = function (event) {
|
|
63
|
+
var element = event.target
|
|
64
|
+
var PIIRemover = new window.GOVUK.analyticsGa4.PIIRemover()
|
|
118
65
|
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
} else {
|
|
124
|
-
// This regex matches a protocol and domain name at the start of a string such as https://www.gov.uk, http://gov.uk, //gov.uk
|
|
125
|
-
path = href.replace(/^(http:||https:)?(\/\/)([^\/]*)/, '') // eslint-disable-line no-useless-escape
|
|
126
|
-
}
|
|
66
|
+
// don't track this link if it's already being tracked by the ecommerce tracker
|
|
67
|
+
if (element.closest('[data-ga4-ecommerce-path]')) {
|
|
68
|
+
return
|
|
69
|
+
}
|
|
127
70
|
|
|
128
|
-
|
|
71
|
+
var target = window.GOVUK.analyticsGa4.core.trackFunctions.findTrackingAttributes(event.target, this.trackingTrigger)
|
|
72
|
+
if (target) {
|
|
73
|
+
try {
|
|
74
|
+
var data = target.getAttribute(this.trackingTrigger)
|
|
75
|
+
data = JSON.parse(data)
|
|
76
|
+
} catch (e) {
|
|
77
|
+
// if there's a problem with the config, don't start the tracker
|
|
78
|
+
console.error('GA4 configuration error: ' + e.message, window.location)
|
|
129
79
|
return
|
|
130
80
|
}
|
|
131
81
|
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
}
|
|
143
|
-
return obj
|
|
144
|
-
},
|
|
145
|
-
|
|
146
|
-
populateLinkDomain: function (href) {
|
|
147
|
-
// We always want mailto links to have an undefined link_domain
|
|
148
|
-
if (this.isMailToLink(href)) {
|
|
149
|
-
return undefined
|
|
150
|
-
}
|
|
82
|
+
var text = data.text || event.target.textContent
|
|
83
|
+
data.text = window.GOVUK.analyticsGa4.core.trackFunctions.removeLinesAndExtraSpaces(text)
|
|
84
|
+
var url = data.url || this.findLink(event.target).getAttribute('href')
|
|
85
|
+
data.url = window.GOVUK.analyticsGa4.core.trackFunctions.removeCrossDomainParams(PIIRemover.stripPII(url))
|
|
86
|
+
data.link_domain = window.GOVUK.analyticsGa4.core.trackFunctions.populateLinkDomain(data.url)
|
|
87
|
+
data.link_path_parts = window.GOVUK.analyticsGa4.core.trackFunctions.populateLinkPathParts(data.url)
|
|
88
|
+
data.method = window.GOVUK.analyticsGa4.core.trackFunctions.getClickType(event)
|
|
89
|
+
data.external = window.GOVUK.analyticsGa4.core.trackFunctions.isExternalLink(data.url) ? 'true' : 'false'
|
|
90
|
+
data.index = event.target.getAttribute('data-ga4-index') ? parseInt(event.target.getAttribute('data-ga4-index')) : data.index || undefined
|
|
91
|
+
data.index = window.GOVUK.analyticsGa4.core.trackFunctions.createIndexObject(data.index)
|
|
151
92
|
|
|
152
|
-
if (
|
|
153
|
-
|
|
154
|
-
} else {
|
|
155
|
-
// This regex matches a protocol and domain name at the start of a string such as https://www.gov.uk, http://gov.uk, //gov.uk
|
|
156
|
-
var domainRegex = /^(http:||https:)?(\/\/)([^\/]*)/ // eslint-disable-line no-useless-escape
|
|
157
|
-
var domain = domainRegex.exec(href)[0]
|
|
158
|
-
return domain
|
|
93
|
+
if (data.type === 'smart answer' && data.action === 'change response') {
|
|
94
|
+
data.section = PIIRemover.stripPIIWithOverride(data.section, true, true)
|
|
159
95
|
}
|
|
160
|
-
},
|
|
161
|
-
|
|
162
|
-
appendDomainsWithoutWWW: function (domainsArrays) {
|
|
163
|
-
// Add domains with www. removed, in case site hrefs are marked up without www. included.
|
|
164
|
-
for (var i = 0; i < domainsArrays.length; i++) {
|
|
165
|
-
var domain = domainsArrays[i]
|
|
166
|
-
if (this.stringStartsWith(domain, 'www.')) {
|
|
167
|
-
var domainWithoutWww = domain.replace('www.', '')
|
|
168
|
-
domainsArrays.push(domainWithoutWww)
|
|
169
|
-
}
|
|
170
|
-
}
|
|
171
|
-
},
|
|
172
|
-
|
|
173
|
-
removeLinesAndExtraSpaces: function (text) {
|
|
174
|
-
text = text.trim()
|
|
175
|
-
text = text.replace(/(\r\n|\n|\r)/gm, ' ') // Replace line breaks with 1 space
|
|
176
|
-
text = text.replace(/\s+/g, ' ') // Replace instances of 2+ spaces with 1 space
|
|
177
|
-
return text
|
|
178
|
-
},
|
|
179
96
|
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
} else if (event.metaKey) {
|
|
186
|
-
return 'command/win click'
|
|
187
|
-
} else if (event.shiftKey) {
|
|
188
|
-
return 'shift click'
|
|
189
|
-
} else {
|
|
190
|
-
return 'primary click'
|
|
191
|
-
}
|
|
192
|
-
case 'mousedown':
|
|
193
|
-
return 'middle click'
|
|
194
|
-
case 'contextmenu':
|
|
195
|
-
return 'secondary click'
|
|
196
|
-
}
|
|
197
|
-
},
|
|
198
|
-
|
|
199
|
-
handleMousedown: function (event) {
|
|
200
|
-
// 1 = middle mouse button
|
|
201
|
-
if (event.button === 1) {
|
|
202
|
-
this.handleClick(event)
|
|
203
|
-
}
|
|
204
|
-
},
|
|
205
|
-
|
|
206
|
-
isMailToLink: function (href) {
|
|
207
|
-
return href.substring(0, 7) === 'mailto:'
|
|
208
|
-
},
|
|
209
|
-
|
|
210
|
-
isDownloadLink: function (href) {
|
|
211
|
-
if (this.isInternalLink(href) && this.hrefPointsToDownloadPath(href)) {
|
|
212
|
-
return true
|
|
213
|
-
}
|
|
214
|
-
|
|
215
|
-
var result = false
|
|
216
|
-
for (var i = 0; i < this.dedicatedDownloadDomains.length; i++) {
|
|
217
|
-
var downloadDomain = this.dedicatedDownloadDomains[i]
|
|
218
|
-
if (this.hrefPointsToDomain(href, downloadDomain)) {
|
|
219
|
-
result = true
|
|
220
|
-
}
|
|
221
|
-
}
|
|
222
|
-
return result
|
|
223
|
-
},
|
|
224
|
-
|
|
225
|
-
isInternalLink: function (href) {
|
|
226
|
-
if (this.hrefIsRelative(href) || this.hrefIsAnchor(href)) {
|
|
227
|
-
return true
|
|
228
|
-
}
|
|
229
|
-
var result = false
|
|
230
|
-
for (var i = 0; i < this.internalDomains.length; i++) {
|
|
231
|
-
var internalDomain = this.internalDomains[i]
|
|
232
|
-
if (this.hrefPointsToDomain(href, internalDomain)) {
|
|
233
|
-
result = true
|
|
234
|
-
}
|
|
235
|
-
}
|
|
236
|
-
return result
|
|
237
|
-
},
|
|
238
|
-
|
|
239
|
-
isExternalLink: function (href) {
|
|
240
|
-
return !this.isInternalLink(href)
|
|
241
|
-
},
|
|
242
|
-
|
|
243
|
-
isPreviewLink: function (href) {
|
|
244
|
-
/* Regex looks for:
|
|
245
|
-
1. The file extension period (the character '.')
|
|
246
|
-
2. any alphanumeric characters (so we can match any file type such as jpg, pdf, mp4.)
|
|
247
|
-
3. the presence of '/preview'.
|
|
248
|
-
For example, .csv/preview or .mp4/preview will be matched.
|
|
249
|
-
Regex is used over JS string methods as this should work with anchor links, query string parameters and files that may have 'preview' in their name.
|
|
250
|
-
*/
|
|
251
|
-
var previewRegex = /\.\w+\/preview/i
|
|
252
|
-
return previewRegex.test(href)
|
|
253
|
-
},
|
|
254
|
-
|
|
255
|
-
hrefPointsToDomain: function (href, domain) {
|
|
256
|
-
/* Add a trailing slash to prevent an edge case such
|
|
257
|
-
as the href www.gov.uk.domain.co.uk being detected as an internal link,
|
|
258
|
-
if we were checking for 'www.gov.uk' instead of 'www.gov.uk/' */
|
|
259
|
-
if (domain.substring(domain.length) !== '/') {
|
|
260
|
-
domain = domain + '/'
|
|
261
|
-
}
|
|
262
|
-
|
|
263
|
-
/* If the href doesn't end in a slash, we add one.
|
|
264
|
-
This fixes an edge case where the <a href> is exactly `https://www.gov.uk`
|
|
265
|
-
but these checks would only look for `https://www.gov.uk/` */
|
|
266
|
-
if (href.substring(href.length) !== '/') {
|
|
267
|
-
href = href + '/'
|
|
268
|
-
}
|
|
269
|
-
var httpDomain = 'http://' + domain
|
|
270
|
-
var httpsDomain = 'https://' + domain
|
|
271
|
-
var schemaRelativeDomain = '//' + domain
|
|
272
|
-
return this.stringStartsWith(href, domain) ||
|
|
273
|
-
this.stringStartsWith(href, httpDomain) ||
|
|
274
|
-
this.stringStartsWith(href, httpsDomain) ||
|
|
275
|
-
this.stringStartsWith(href, schemaRelativeDomain)
|
|
276
|
-
},
|
|
277
|
-
|
|
278
|
-
hrefPointsToDownloadPath: function (href) {
|
|
279
|
-
var result = false
|
|
280
|
-
for (var i = 0; i < this.internalDownloadPaths.length; i++) {
|
|
281
|
-
var internalDownloadPath = this.internalDownloadPaths[i]
|
|
282
|
-
if (href.indexOf(internalDownloadPath) !== -1) {
|
|
283
|
-
result = true
|
|
284
|
-
}
|
|
285
|
-
}
|
|
286
|
-
return result
|
|
287
|
-
},
|
|
288
|
-
|
|
289
|
-
stringStartsWith: function (string, stringToFind) {
|
|
290
|
-
return string.substring(0, stringToFind.length) === stringToFind
|
|
291
|
-
},
|
|
292
|
-
|
|
293
|
-
stringEndsWith: function (string, stringToFind) {
|
|
294
|
-
return string.substring(string.length - stringToFind.length, string.length) === stringToFind
|
|
295
|
-
},
|
|
296
|
-
|
|
297
|
-
hrefIsRelative: function (href) {
|
|
298
|
-
// Checks that a link is relative, but is not a protocol relative url
|
|
299
|
-
return href[0] === '/' && href[1] !== '/'
|
|
300
|
-
},
|
|
301
|
-
|
|
302
|
-
hrefIsAnchor: function (href) {
|
|
303
|
-
return href[0] === '#'
|
|
304
|
-
},
|
|
305
|
-
|
|
306
|
-
getHostname: function () {
|
|
307
|
-
return window.location.hostname
|
|
308
|
-
},
|
|
309
|
-
|
|
310
|
-
getProtocol: function () {
|
|
311
|
-
return window.location.protocol
|
|
312
|
-
},
|
|
313
|
-
|
|
314
|
-
removeCrossDomainParams: function (href) {
|
|
315
|
-
if (href.indexOf('_ga') !== -1 || href.indexOf('_gl') !== -1) {
|
|
316
|
-
// _ga & _gl are values needed for cross domain tracking, but we don't want them included in our click tracking.
|
|
317
|
-
href = href.replaceAll(/_g[al]=([^&]*)/g, '')
|
|
97
|
+
var schemas = new window.GOVUK.analyticsGa4.Schemas()
|
|
98
|
+
var schema = schemas.mergeProperties(data, 'event_data')
|
|
99
|
+
window.GOVUK.analyticsGa4.core.sendData(schema)
|
|
100
|
+
}
|
|
101
|
+
}
|
|
318
102
|
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
}
|
|
325
|
-
}
|
|
326
|
-
return href
|
|
103
|
+
Ga4LinkTracker.prototype.findLink = function (target) {
|
|
104
|
+
if (target.tagName === 'A') {
|
|
105
|
+
return target
|
|
106
|
+
} else {
|
|
107
|
+
return target.closest('a')
|
|
327
108
|
}
|
|
328
109
|
}
|
|
329
110
|
|
|
330
|
-
|
|
331
|
-
})(window.GOVUK.
|
|
111
|
+
Modules.Ga4LinkTracker = Ga4LinkTracker
|
|
112
|
+
})(window.GOVUK.Modules)
|
|
@@ -27,12 +27,12 @@ window.GOVUK.analyticsGa4.analyticsModules = window.GOVUK.analyticsGa4.analytics
|
|
|
27
27
|
schema_name: this.getMetaContent('schema-name'),
|
|
28
28
|
content_id: this.getMetaContent('content-id'),
|
|
29
29
|
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
30
|
+
browse_topic: this.getMetaContent('section'),
|
|
31
|
+
taxonomy_level1: this.getMetaContent('themes'),
|
|
32
|
+
taxonomy_main: this.getMetaContent('taxon-slug'),
|
|
33
|
+
taxonomy_main_id: this.getMetaContent('taxon-id'),
|
|
34
|
+
taxonomy_all: this.splitLongMetaContent('taxon-slugs'),
|
|
35
|
+
taxonomy_all_ids: this.splitLongMetaContent('taxon-ids'),
|
|
36
36
|
|
|
37
37
|
language: this.getLanguage(),
|
|
38
38
|
history: this.getHistory(),
|
|
@@ -106,6 +106,13 @@ window.GOVUK.analyticsGa4.analyticsModules = window.GOVUK.analyticsGa4.analytics
|
|
|
106
106
|
return (withdrawn === 'withdrawn') ? 'true' : 'false'
|
|
107
107
|
},
|
|
108
108
|
|
|
109
|
+
splitLongMetaContent: function (metatag) {
|
|
110
|
+
var tag = this.getMetaContent(metatag)
|
|
111
|
+
if (tag) {
|
|
112
|
+
return window.GOVUK.analyticsGa4.core.trackFunctions.splitStringIntoParts(tag)
|
|
113
|
+
}
|
|
114
|
+
},
|
|
115
|
+
|
|
109
116
|
// return only the date from given timestamps of the form
|
|
110
117
|
// 2022-03-28T19:11:00.000+00:00
|
|
111
118
|
stripTimeFrom: function (value) {
|
|
@@ -23,11 +23,41 @@
|
|
|
23
23
|
external: this.undefined,
|
|
24
24
|
method: this.undefined,
|
|
25
25
|
link_domain: this.undefined,
|
|
26
|
-
link_path_parts: this.undefined
|
|
26
|
+
link_path_parts: this.undefined,
|
|
27
|
+
tool_name: this.undefined
|
|
27
28
|
}
|
|
28
29
|
}
|
|
29
30
|
}
|
|
30
31
|
|
|
32
|
+
Schemas.prototype.ecommerceSchema = function () {
|
|
33
|
+
return {
|
|
34
|
+
event: this.undefined,
|
|
35
|
+
search_results: {
|
|
36
|
+
event_name: this.undefined,
|
|
37
|
+
term: this.undefined,
|
|
38
|
+
sort: this.undefined,
|
|
39
|
+
results: this.undefined,
|
|
40
|
+
ecommerce: {
|
|
41
|
+
items: []
|
|
42
|
+
}
|
|
43
|
+
},
|
|
44
|
+
event_data: this.undefined
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
// get attributes from the data attribute to send to GA
|
|
49
|
+
// only allow it if it already exists in the schema
|
|
50
|
+
Schemas.prototype.mergeProperties = function (data, eventAttribute) {
|
|
51
|
+
var schema = this.eventSchema()
|
|
52
|
+
schema.event = eventAttribute
|
|
53
|
+
for (var property in data) {
|
|
54
|
+
if (property in schema.event_data) {
|
|
55
|
+
schema.event_data[property] = data[property]
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
return schema
|
|
59
|
+
}
|
|
60
|
+
|
|
31
61
|
GOVUK.analyticsGa4 = GOVUK.analyticsGa4 || {}
|
|
32
62
|
GOVUK.analyticsGa4.Schemas = Schemas
|
|
33
63
|
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
window.GOVUK = window.GOVUK || {}
|
|
2
|
+
window.GOVUK.Modules = window.GOVUK.Modules || {}
|
|
3
|
+
window.GOVUK.analyticsGa4 = window.GOVUK.analyticsGa4 || {};
|
|
4
|
+
|
|
5
|
+
(function (Modules) {
|
|
6
|
+
'use strict'
|
|
7
|
+
|
|
8
|
+
function Ga4SmartAnswerResultsTracker (module) {
|
|
9
|
+
this.module = module
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
Ga4SmartAnswerResultsTracker.prototype.init = function () {
|
|
13
|
+
var consentCookie = window.GOVUK.getConsentCookie()
|
|
14
|
+
|
|
15
|
+
if (consentCookie && consentCookie.settings) {
|
|
16
|
+
this.startModule()
|
|
17
|
+
} else {
|
|
18
|
+
this.startModule = this.startModule.bind(this)
|
|
19
|
+
window.addEventListener('cookie-consent', this.startModule)
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
// triggered by cookie-consent event, which happens when users consent to cookies
|
|
24
|
+
Ga4SmartAnswerResultsTracker.prototype.startModule = function () {
|
|
25
|
+
// only run this code if the dataLayer exists and an element with a data-ga4-ecommerce-path
|
|
26
|
+
// attribute exists as this indicates that ecommerce tracking is required
|
|
27
|
+
if (window.dataLayer && this.module.querySelector('[data-ga4-ecommerce-path]')) {
|
|
28
|
+
this.trackResults()
|
|
29
|
+
this.module.addEventListener('click', this.handleClick.bind(this))
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
Ga4SmartAnswerResultsTracker.prototype.trackResults = function () {
|
|
34
|
+
var ecommerceSchema = window.GOVUK.analyticsGa4.core.ecommerceHelperFunctions.populateEcommerceSchema({
|
|
35
|
+
element: this.module,
|
|
36
|
+
resultsId: 'ga4-ecommerce-result-count'
|
|
37
|
+
})
|
|
38
|
+
|
|
39
|
+
window.GOVUK.analyticsGa4.core.ecommerceHelperFunctions.clearEcommerceObject()
|
|
40
|
+
window.GOVUK.analyticsGa4.core.sendData(ecommerceSchema)
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
Ga4SmartAnswerResultsTracker.prototype.handleClick = function (event) {
|
|
44
|
+
if (event.target.getAttribute('data-ga4-ecommerce-path')) {
|
|
45
|
+
var ecommerceSchema = window.GOVUK.analyticsGa4.core.ecommerceHelperFunctions.populateEcommerceSchema({
|
|
46
|
+
element: this.module,
|
|
47
|
+
resultsId: 'ga4-ecommerce-result-count',
|
|
48
|
+
event: event
|
|
49
|
+
})
|
|
50
|
+
|
|
51
|
+
window.GOVUK.analyticsGa4.core.ecommerceHelperFunctions.clearEcommerceObject()
|
|
52
|
+
window.GOVUK.analyticsGa4.core.sendData(ecommerceSchema)
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
Modules.Ga4SmartAnswerResultsTracker = Ga4SmartAnswerResultsTracker
|
|
57
|
+
})(window.GOVUK.Modules)
|