Sha256: 29348a13f16a5bee2dabf9e17efa73b75998fefa7ed176f1c831c770b6ca0f42

Contents?: true

Size: 1.73 KB

Versions: 5

Compression:

Stored size: 1.73 KB

Contents

module GovukPublishingComponents
  module Presenters
    class LayoutFooterHelper
      attr_reader :ga4_index_total, :ga4_index_section_count, :ga4_ogl_link_index_section, :ga4_copyright_link_index_section

      def initialize(footer_navigation_section, footer_meta_section)
        @ga4_index_total = 0
        @ga4_index_section_count = 0
        @amount_of_meta_sections = 0

        footer_navigation_section.each do |section|
          @ga4_index_section_count += 1
          if section[:items]
            @ga4_index_total += section[:items].length
          end
        end

        if footer_meta_section.any?
          @amount_of_meta_sections = 1
          @ga4_index_section_count += 1
          @ga4_index_total += footer_meta_section[:items].length
        end

        # For our GOVUK footer links, we need to add 2 to the index_total and index_section_count. This is due to the "Open Government License" and "Crown Copyright" links being defined separately to the rest of our footer links.
        @ga4_index_total += 2
        @ga4_index_section_count += 2

        @ga4_ogl_link_index_section = footer_navigation_section.length + @amount_of_meta_sections + 1
        @ga4_copyright_link_index_section = footer_navigation_section.length + @amount_of_meta_sections + 2
      end

      def generate_ga4_link_attribute(index_link, index_section, section)
        {
          "event_name": "navigation",
          "type": "footer",
          "index": {
            "index_link": (index_link + 1).to_s,
            "index_section": (index_section + 1).to_s,
            "index_section_count": @ga4_index_section_count.to_s,
          },
          "index-total": @ga4_index_total.to_s,
          "section": section,
        }
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
govuk_publishing_components-35.3.1 lib/govuk_publishing_components/presenters/layout_footer_helper.rb
govuk_publishing_components-35.3.0 lib/govuk_publishing_components/presenters/layout_footer_helper.rb
govuk_publishing_components-35.2.0 lib/govuk_publishing_components/presenters/layout_footer_helper.rb
govuk_publishing_components-35.1.1 lib/govuk_publishing_components/presenters/layout_footer_helper.rb
govuk_publishing_components-35.1.0 lib/govuk_publishing_components/presenters/layout_footer_helper.rb