Skip to content

Commit

Permalink
Merge pull request #2900 from alphagov/track-subscriptions
Browse files Browse the repository at this point in the history
Add tracking for email subscriptions completion
  • Loading branch information
andysellick authored Aug 21, 2023
2 parents 14b5ae9 + 20a7d6c commit 1030b26
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 13 deletions.
8 changes: 4 additions & 4 deletions app/helpers/content_items_helper.rb
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
module ContentItemsHelper
def email_subscription_success_banner_heading(account_flash)
def email_subscription_success_banner_heading(account_flash, locale = nil)
if account_flash.include?("email-subscription-success")
sanitize(t("email.subscribe_title"))
sanitize(t("email.subscribe_title", locale:))
elsif account_flash.include?("email-unsubscribe-success")
sanitize(t("email.unsubscribe_title"))
sanitize(t("email.unsubscribe_title", locale:))
elsif account_flash.include?("email-subscription-already-subscribed")
sanitize(t("email.already_subscribed_title"))
sanitize(t("email.already_subscribed_title", locale:))
end
end

Expand Down
2 changes: 1 addition & 1 deletion app/views/content_items/call_for_evidence.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
) %>
<% end %>
<%= render 'shared/email_subscribe_unsubscribe_flash' %>
<%= render 'shared/email_subscribe_unsubscribe_flash', { title: @content_item.title_and_context[:title] } %>

<div class="govuk-grid-row">
<div class="govuk-grid-column-two-thirds">
Expand Down
2 changes: 1 addition & 1 deletion app/views/content_items/consultation.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
) %>
<% end %>
<%= render 'shared/email_subscribe_unsubscribe_flash' %>
<%= render 'shared/email_subscribe_unsubscribe_flash', { title: @content_item.title_and_context[:title] } %>

<div class="govuk-grid-row">
<div class="govuk-grid-column-two-thirds">
Expand Down
2 changes: 1 addition & 1 deletion app/views/content_items/detailed_guide.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
<% end %>
<% end %>
<%= render 'shared/email_subscribe_unsubscribe_flash' %>
<%= render 'shared/email_subscribe_unsubscribe_flash', { title: @content_item.title_and_context[:title] } %>

<div class="govuk-grid-row">
<div class="govuk-grid-column-two-thirds">
Expand Down
2 changes: 1 addition & 1 deletion app/views/content_items/publication.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
<% end %>
<% end %>
<%= render 'shared/email_subscribe_unsubscribe_flash' %>
<%= render 'shared/email_subscribe_unsubscribe_flash', { title: @content_item.title } %>

<div class="govuk-grid-row">
<div class="govuk-grid-column-two-thirds">
Expand Down
26 changes: 21 additions & 5 deletions app/views/shared/_email_subscribe_unsubscribe_flash.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,27 @@
<% if show_email_subscription_success_banner?(@account_flash) %>
<div class="govuk-grid-row govuk-!-margin-top-3">
<div class="govuk-grid-column-two-thirds">
<%= render "govuk_publishing_components/components/success_alert", {
message: email_subscription_success_banner_heading(@account_flash),
description: banner_description,
margin_bottom: 0,
} %>
<%
ga4_data = {
event_name: "form_complete",
type: "email subscription",
text: email_subscription_success_banner_heading(@account_flash, :en),
section: local_assigns[:title],
action: "complete",
tool_name: "Get emails from GOV.UK"
}.to_json
%>
<%= content_tag(:div,
data: {
module: "ga4-auto-tracker",
ga4_auto: ga4_data
}) do %>
<%= render "govuk_publishing_components/components/success_alert", {
message: email_subscription_success_banner_heading(@account_flash),
description: banner_description,
margin_bottom: 0,
} %>
<% end %>
</div>
</div>
<% end %>

0 comments on commit 1030b26

Please sign in to comment.