Skip to content

Commit

Permalink
Merge pull request #3134 from alphagov/add-email-tracking
Browse files Browse the repository at this point in the history
Add GA4 tracking for email subscriptions
  • Loading branch information
andysellick authored Aug 21, 2023
2 parents 794d4c4 + ef52da7 commit 3b795bc
Showing 1 changed file with 41 additions and 10 deletions.
51 changes: 41 additions & 10 deletions app/views/email_alert_subscriptions/new.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -9,22 +9,53 @@
<% end %>

<div class="govuk-width-container">
<%= form_tag email_alert_subscriptions_path(subscriber_list_params: subscriber_list_params), class: 'signup-choices' do %>
<%
ga4_data = {
event_name: "form_response",
type: "email subscription",
section: t("email_alert_subscriptions.new.question", locale: :en),
action: "continue",
tool_name: "Get emails from GOV.UK",
}.to_json
%>
<%= form_tag(
email_alert_subscriptions_path(subscriber_list_params: subscriber_list_params),
class: 'signup-choices',
data: {
module: "ga4-form-tracker",
ga4_form: ga4_data,
}) do %>
<% if @signup_presenter.can_modify_choices? %>
<%= render partial: 'govuk_publishing_components/components/title', locals: {
title: @signup_presenter.name,
} %>
<% if @error_message.present? %>
<%= render "govuk_publishing_components/components/error_summary", {
title: "There is a problem",
items: [
{
text: @error_message,
href: "#signup-choices-options",
}
]
} %>
<%
ga4_data = {
event_name: "form_error",
type: "email subscription",
text: @error_message,
section: t("email_alert_subscriptions.new.question", locale: :en),
action: "error",
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/error_summary", {
title: "There is a problem",
items: [
{
text: @error_message,
href: "#signup-choices-options",
}
]
} %>
<% end %>
<% end %>
<%= render "govuk_publishing_components/components/checkboxes", {
Expand Down

0 comments on commit 3b795bc

Please sign in to comment.