Skip to content

Commit

Permalink
Merge pull request #3784 from alphagov/ga4-homepage-indexes
Browse files Browse the repository at this point in the history
GA4 homepage indexes
  • Loading branch information
andysellick authored Oct 2, 2023
2 parents 6521193 + 04d90fd commit dbfd4ca
Show file tree
Hide file tree
Showing 9 changed files with 165 additions and 175 deletions.
10 changes: 0 additions & 10 deletions app/views/homepage/_body.html.erb

This file was deleted.

68 changes: 68 additions & 0 deletions app/views/homepage/_departments_and_organisations.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
<div class="govuk-grid-column-full govuk-grid-column-one-third-from-desktop">
<section class="homepage-section homepage-section__departments-organisations">
<div class="homepage-section__heading">
<%= render "govuk_publishing_components/components/heading", {
font_size: "m",
text: t("homepage.index.departments_and_organisations"),
data_attributes: {
ga4_scroll_marker: true,
},
} %>
</div>

<%
# The "big number" component links below are hardcoded separately (i.e. not in a loop in this instance) and therefore their 'index' properties are also hardcoded.
# If a new "big number" component is added or removed, this will need to be reflected in the 'index_link' and 'index_total' properties to ensure that they remain accurate for tracking/analytics purposes.
%>
<div class="homepage-section__depts" data-module="gem-track-click ga4-link-tracker">
<%= render "govuk_publishing_components/components/big_number", {
number: t("homepage.index.ministerial_departments_count"),
label: t("homepage.index.ministerial_departments"),
href: "/government/organisations#ministerial_departments",
margin_bottom: 6,
data_attributes: {
"track-category": "homepageClicked",
"track-action": "departmentsLink",
"track-label": "/government/organisations#ministerial_departments",
"track-dimension": "#{t("homepage.index.ministerial_departments_count")} #{t("homepage.index.ministerial_departments")}",
"track-dimension-index": 29,
"track-value": 1,
"ga4_link": {
"event_name": "navigation",
"type": "homepage",
"index_section": locals[:index_section],
"index_link": 1,
"index_section_count": locals[:index_section_count],
"index_total": 2,
"section": t("homepage.index.departments_and_organisations", locale: :en),
"text": "#{t("homepage.index.ministerial_departments_count")} #{t("homepage.index.ministerial_departments", locale: :en)}"
}
},
} %>
<%= render "govuk_publishing_components/components/big_number", {
number: t("homepage.index.other_agencies_count"),
label: t("homepage.index.other_agencies"),
href: "/government/organisations#agencies_and_other_public_bodies",
margin_bottom: 6,
data_attributes: {
"track-category": "homepageClicked",
"track-action": "departmentsLink",
"track-label": "/government/organisations#agencies_and_other_public_bodies",
"track-dimension": "#{t("homepage.index.other_agencies_count")} #{t("homepage.index.other_agencies")}",
"track-dimension-index": 29,
"track-value": 1,
"ga4_link": {
"event_name": "navigation",
"type": "homepage",
"index_section": locals[:index_section],
"index_link": 2,
"index_section_count": locals[:index_section_count],
"index_total": 2,
"section": t("homepage.index.departments_and_organisations", locale: :en),
"text": "#{t("homepage.index.other_agencies_count")} #{t("homepage.index.other_agencies", locale: :en)}"
}
},
} %>
</div>
</section>
</div>
128 changes: 27 additions & 101 deletions app/views/homepage/_government_activity.html.erb
Original file line number Diff line number Diff line change
@@ -1,112 +1,38 @@
<div class="govuk-grid-row">
<div class="govuk-grid-column-full govuk-grid-column-two-thirds-from-desktop" data-module="gem-track-click ga4-link-tracker">
<section class="homepage-section homepage-section__government-activity">
<div class="homepage-section__heading">
<div class="homepage-section__heading-wrapper">
<%= render "govuk_publishing_components/components/heading", {
font_size: "m",
text: t("homepage.index.government_activity"),
data_attributes: {
ga4_scroll_marker: true,
},
} %>
</div>

<%= render "govuk_publishing_components/components/lead_paragraph", {
text: t("homepage.index.government_activity_description"),
margin_bottom: 0
} %>
</div>

<ul class="homepage-services-and-info__list">
<% t("homepage.government_activity").each_with_index do | item, index | %>
<%= render partial: "homepage/chevron_card", locals: {
description: item[:description],
link: item[:link],
title: item[:title],
track_action: "governmentactivityLink",
index_values: {
index_section: 3,
index_link: index + 1,
index_section_count: 6,
},
index_total: t("homepage.government_activity").length,
section: t("homepage.index.government_activity", locale: :en)
} %>
<% end %>
</ul>
</section>
</div>

<div class="govuk-grid-column-full govuk-grid-column-one-third-from-desktop">
<section class="homepage-section homepage-section__departments-organisations">
<div class="homepage-section__heading">
<div class="govuk-grid-column-full govuk-grid-column-two-thirds-from-desktop" data-module="gem-track-click ga4-link-tracker">
<section class="homepage-section homepage-section__government-activity">
<div class="homepage-section__heading">
<div class="homepage-section__heading-wrapper">
<%= render "govuk_publishing_components/components/heading", {
font_size: "m",
text: t("homepage.index.departments_and_organisations"),
text: t("homepage.index.government_activity"),
data_attributes: {
ga4_scroll_marker: true,
},
} %>
</div>

<%#
The "big number" component links below are hardcoded separately (i.e. not in a loop in this instance) and therefore their 'index' properties are also hardcoded. If a new "big number" component is added or removed, this will need to be reflected in the 'index_link' and 'index_total' properties to ensure that they remain accurate for tracking/analytics purposes.
%>
<div class="homepage-section__depts" data-module="gem-track-click ga4-link-tracker">
<%= render "govuk_publishing_components/components/big_number", {
number: t("homepage.index.ministerial_departments_count"),
label: t("homepage.index.ministerial_departments"),
href: "/government/organisations#ministerial_departments",
margin_bottom: 6,
data_attributes: {
"track-category": "homepageClicked",
"track-action": "departmentsLink",
"track-label": "/government/organisations#ministerial_departments",
"track-dimension": "#{t("homepage.index.ministerial_departments_count")} #{t("homepage.index.ministerial_departments")}",
"track-dimension-index": 29,
"track-value": 1,
"ga4_link": {
"event_name": "navigation",
"type": "homepage",
"index": {
"index_section": 4,
"index_link": 1,
"index_section_count": 6,
},
"index_total": 2,
"section": t("homepage.index.departments_and_organisations", locale: :en),
"text": "#{t("homepage.index.ministerial_departments_count")} #{t("homepage.index.ministerial_departments", locale: :en)}"
}
},
} %>
<%= render "govuk_publishing_components/components/big_number", {
number: t("homepage.index.other_agencies_count"),
label: t("homepage.index.other_agencies"),
href: "/government/organisations#agencies_and_other_public_bodies",
margin_bottom: 6,
data_attributes: {
"track-category": "homepageClicked",
"track-action": "departmentsLink",
"track-label": "/government/organisations#agencies_and_other_public_bodies",
"track-dimension": "#{t("homepage.index.other_agencies_count")} #{t("homepage.index.other_agencies")}",
"track-dimension-index": 29,
"track-value": 1,
"ga4_link": {
"event_name": "navigation",
"type": "homepage",
"index": {
"index_section": 4,
"index_link": 2,
"index_section_count": 6,
},
"index_total": 2,
"section": t("homepage.index.departments_and_organisations", locale: :en),
"text": "#{t("homepage.index.other_agencies_count")} #{t("homepage.index.other_agencies", locale: :en)}"
}
<%= render "govuk_publishing_components/components/lead_paragraph", {
text: t("homepage.index.government_activity_description"),
margin_bottom: 0
} %>
</div>

<ul class="homepage-services-and-info__list">
<% t("homepage.government_activity").each_with_index do | item, index | %>
<%= render partial: "homepage/chevron_card", locals: {
description: item[:description],
link: item[:link],
title: item[:title],
track_action: "governmentactivityLink",
index_values: {
index_section: locals[:index_section],
index_link: index + 1,
index_section_count: locals[:index_section_count],
},
index_total: t("homepage.government_activity").length,
section: t("homepage.index.government_activity", locale: :en)
} %>
</div>
</section>
</div>
<% end %>
</ul>
</section>
</div>
2 changes: 0 additions & 2 deletions app/views/homepage/_head.html.erb

This file was deleted.

8 changes: 3 additions & 5 deletions app/views/homepage/_links_and_search.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,9 @@
ga4_link: {
'event_name': 'navigation',
'type': 'homepage',
'index': {
'index_section': 1,
'index_link': index + 1,
'index_section_count': 6,
},
'index_section': locals[:index_section],
'index_link': index + 1,
'index_section_count': locals[:index_section_count],
'index_total': t("homepage.index.popular_links").length,
'section': "#{t("homepage.index.popular_links_heading", locale: :en)}"
}
Expand Down
8 changes: 3 additions & 5 deletions app/views/homepage/_more_on_govuk.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,9 @@
"ga4_link": {
'event_name': 'navigation',
'type': 'homepage',
"index": {
"index_section": 6,
"index_link": index + 1,
"index_section_count": 6,
},
"index_section": locals[:index_section],
"index_link": index + 1,
"index_section_count": locals[:index_section_count],
"index_total": t("homepage.index.more_links").length,
"section": t("homepage.index.more", locale: :en)
}
Expand Down
86 changes: 42 additions & 44 deletions app/views/homepage/_promotion-slots.html.erb
Original file line number Diff line number Diff line change
@@ -1,50 +1,48 @@
<%#
Before updating a promotion slot please read the documentation.
See: https://docs.publishing.service.gov.uk/repos/frontend/update-homepage-promotion-slots.html
<%
# Before updating a promotion slot please read the documentation.
# See: https://docs.publishing.service.gov.uk/repos/frontend/update-homepage-promotion-slots.html
%>

<section class="homepage-section homepage-section--promotion-slots">
<%= render "govuk_publishing_components/components/heading", {
text: t("homepage.index.featured"),
font_size: "m",
margin_bottom: 6,
data_attributes: {
ga4_scroll_marker: true,
<%= render "govuk_publishing_components/components/heading", {
text: t("homepage.index.featured"),
font_size: "m",
margin_bottom: 6,
data_attributes: {
ga4_scroll_marker: true,
},
} %>

<% t("homepage.index.promotion_slots").each_with_index do | item, index | %>
<%= render "govuk_publishing_components/components/image_card", {
href: item[:href],
href_data_attributes: {
track_category: "homepageClicked",
track_action: "promoLink",
track_label: item[:href],
track_value: "1",
track_dimension_index: "29",
track_dimension: item[:title],
ga4_link: {
event_name: 'navigation',
type: 'homepage',
index_section: locals[:index_section],
index_link: index + 1,
index_section_count: locals[:index_section_count],
index_total: t("homepage.index.promotion_slots").length,
section: t("homepage.index.featured", locale: :en)
}
},
image_src: image_path(item[:image_src]),
image_alt: "",
image_loading: "lazy",
heading_level: 3,
heading_text: item[:title],
two_thirds: true,
description: item[:text],
font_size: "s",
sizes: "(max-width: 640px) 100vw, (max-width: 1020px) 33vw, 300px",
srcset: item.fetch(:srcset, {}).stringify_keys.transform_keys { |k| image_path(k) }.presence
} %>

<% t("homepage.index.promotion_slots").each_with_index do | item, index | %>
<%= render "govuk_publishing_components/components/image_card", {
href: item[:href],
href_data_attributes: {
track_category: "homepageClicked",
track_action: "promoLink",
track_label: item[:href],
track_value: "1",
track_dimension_index: "29",
track_dimension: item[:title],
ga4_link: {
event_name: 'navigation',
type: 'homepage',
index: {
index_section: 5,
index_link: index + 1,
index_section_count: 6,
},
index_total: t("homepage.index.promotion_slots").length,
section: t("homepage.index.featured", locale: :en)
}
},
image_src: image_path(item[:image_src]),
image_alt: "",
image_loading: "lazy",
heading_level: 3,
heading_text: item[:title],
two_thirds: true,
description: item[:text],
font_size: "s",
sizes: "(max-width: 640px) 100vw, (max-width: 1020px) 33vw, 300px",
srcset: item.fetch(:srcset, {}).stringify_keys.transform_keys { |k| image_path(k) }.presence
} %>
<% end %>
<% end %>
</section>
6 changes: 3 additions & 3 deletions app/views/homepage/_services_and_information.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
},
} %>
</div>

<ul class="homepage-services-and-info__list" data-module="gem-track-click ga4-link-tracker">
<% t("homepage.categories").each_with_index do | item, index | %>
<%= render partial: "homepage/chevron_card", locals: {
Expand All @@ -21,9 +21,9 @@
title: item[:title],
track_action: "topicsLink",
index_values: {
index_section: 2,
index_section: locals[:index_section],
index_link: index + 1,
index_section_count: 6,
index_section_count: locals[:index_section_count],
},
index_total: t("homepage.categories").length,
section: t("homepage.index.services_and_information", locale: :en)
Expand Down
Loading

0 comments on commit dbfd4ca

Please sign in to comment.