<% if local_assigns[:items] && !items.blank? %>
  <aside class='govuk-taxonomy-sidebar' data-module='track-click' role='complementary'>
    <% items.each_with_index do |item, item_index| %>

      <div class='sidebar-taxon'>
        <h2>
          <%= link_to item[:title], item[:url], class: 'taxon-link' %>
        </h2>

        <p class='taxon-description'>
          <%= item[:description] %>
        </p>

        <% item[:related_content] ||= [] %>
        <% if item[:related_content].any? %>
          <nav role='navigation'>
            <ul class='related-content'>
              <% item[:related_content].each_with_index do |related_item, related_content_index| %>
                <li>
                  <%=
                    link_to(
                      related_item[:title],
                      related_item[:link],
                      data: {
                          track_category: 'relatedLinkClicked',
                          track_action: "#{item_index + 1}.#{related_content_index + 1}",
                          track_label: related_item[:link],
                          track_dimension: related_item[:title],
                          track_dimension_index: 29,
                      },
                      class: 'related-link',
                    )
                  %>
                </li>
              <% end %>
            </ul>
          </nav>
        <% end %>
      </div>

    <% end %>
  </aside>
<% end %>

<% if local_assigns[:items] && !items.blank? %>
  <aside class='govuk-taxonomy-sidebar' data-module='track-click' role='complementary'>
    <% items.each_with_index do |item, item_index| %>

      <div class='sidebar-taxon'>
        <h2>
          <%=
            link_to(
              item[:title],
              item[:url],
              class: 'taxon-link',
              data: {
                track_category: 'relatedLinkClicked',
                track_action: "#{item_index + 1}",
                track_label: item[:url],
                track_dimension: item[:title],
                track_dimension_index: 29,
              },
            )
          %>
        </h2>

        <p class='taxon-description'>
          <%= item[:description] %>
        </p>

        <% item[:related_content] ||= [] %>
        <% if item[:related_content].any? %>
          <nav role='navigation'>
            <ul class='related-content'>
              <% item[:related_content].each_with_index do |related_item, related_content_index| %>
                <li>
                  <%=
                    link_to(
                      related_item[:title],
                      related_item[:link],
                      data: {
                          track_category: 'relatedLinkClicked',
                          track_action: "#{item_index + 1}.#{related_content_index + 1}",
                          track_label: related_item[:link],
                          track_dimension: related_item[:title],
                          track_dimension_index: 29,
                      },
                      class: 'related-link',
                    )
                  %>
                </li>
              <% end %>
            </ul>
          </nav>
        <% end %>
      </div>

    <% end %>
  </aside>
<% end %>

Add click-tracking to the taxon title heading in the taxonomy sidebar
Add click-tracking to the taxon title heading in the taxonomy sidebar
