Skip to content

Commit

Permalink
Pass signup links index in data_attributes
Browse files Browse the repository at this point in the history
  • Loading branch information
JamesCGDS committed Aug 25, 2023
1 parent 3153387 commit c89ce8a
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 12 deletions.
52 changes: 46 additions & 6 deletions app/presenters/signup_links_presenter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,57 @@ def initialize(content_item, facets, keywords)
end

def signup_links
{
feed_link:,
# if there are 4 links, we start from 2
# if there are 2 links, we start from 1
[
get_signup_link(0),
get_signup_link(count_signup_links / 2),
]
end

private

attr_reader :content_item, :facets, :keywords

def get_signup_link(pos)
total_links = count_signup_links

data_attributes = {
hide_heading: true,
small_form: true,
feed_link:,
feed_link_data_attributes: {},
email_signup_link: email_signup_link.presence,
email_signup_link_data_attributes: {},
}.compact
end

private
if email_signup_link && feed_link
email_index_link = pos + 1
feed_index_link = pos + 2
elsif email_signup_link
email_index_link = pos + 1
elsif feed_link
feed_index_link = pos + 1
end

attr_reader :content_item, :facets, :keywords
data_attributes[:email_signup_link_data_attributes][:ga4_index] = {
index_link: email_index_link,
index_total: total_links

Check failure on line 44 in app/presenters/signup_links_presenter.rb

View workflow job for this annotation

GitHub Actions / Lint Ruby / Run RuboCop

Style/TrailingCommaInHashLiteral: Put a comma after the last item of a multiline hash.
}
data_attributes[:feed_link_data_attributes][:ga4_index] = {
index_link: feed_index_link,
index_total: total_links

Check failure on line 48 in app/presenters/signup_links_presenter.rb

View workflow job for this annotation

GitHub Actions / Lint Ruby / Run RuboCop

Style/TrailingCommaInHashLiteral: Put a comma after the last item of a multiline hash.
}

data_attributes
end

def count_signup_links
total = 0
total += 1 if feed_link
total += 1 if email_signup_link
total * 2
end

def email_signup_link
signup_link = content_item.signup_link
Expand All @@ -43,4 +83,4 @@ def query_string(params)
query_string = params.compact.to_query
query_string.blank? ? query_string : "?#{query_string}"
end
end
end

Check failure on line 86 in app/presenters/signup_links_presenter.rb

View workflow job for this annotation

GitHub Actions / Lint Ruby / Run RuboCop

Layout/TrailingEmptyLines: Final newline missing. (https://rubystyle.guide#newline-eof)
10 changes: 4 additions & 6 deletions app/views/finders/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
<% content_for :title, content_item.title %>
<% end %>
<% content_for :head do %>
<% if signup_links[:feed_link] %>
<%= auto_discovery_link_tag(:atom, signup_links[:feed_link]) %>
<% if signup_links[0][:feed_link] %>
<%= auto_discovery_link_tag(:atom, signup_links[0][:feed_link]) %>
<% end %>
<%= render 'finder_meta', content_item: content_item %>
<% end %>
Expand Down Expand Up @@ -82,9 +82,8 @@
class="govuk-grid-column-one-half govuk-!-text-align-right subscription-links subscription-links--desktop"
data-module="ga4-link-tracker"
data-ga4-track-links-only
data-ga4-set-indexes
data-ga4-link='{ "event_name": "navigation", "type": "subscribe", "section": "Top" }'>
<%= render "govuk_publishing_components/components/subscription_links", signup_links %>
<%= render "govuk_publishing_components/components/subscription_links", signup_links[0] %>
</div>
</div>
<div id="js-facet-tag-wrapper" class="facet-tags__container" aria-live="assertive">
Expand All @@ -111,9 +110,8 @@
id="subscription-links-footer"
data-module="ga4-link-tracker"
data-ga4-track-links-only
data-ga4-set-indexes
data-ga4-link='{ "event_name": "navigation", "type": "subscribe", "section": "Footer" }'>
<%= render "govuk_publishing_components/components/subscription_links", signup_links %>
<%= render "govuk_publishing_components/components/subscription_links", signup_links[1] %>
</div>
</div>
</div>
Expand Down

0 comments on commit c89ce8a

Please sign in to comment.