Skip to content

Commit

Permalink
Merge pull request #1597 from alphagov/tracking-fixes
Browse files Browse the repository at this point in the history
GA4 tracking fixes
  • Loading branch information
andysellick authored Aug 22, 2023
2 parents 19fce9f + da41599 commit 382a28b
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 7 deletions.
1 change: 1 addition & 0 deletions app/controllers/subscriptions_management_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ def confirmed_unsubscribe_all
flash[:success] = {
message: t("subscriptions_management.confirmed_unsubscribe_all.success_message"),
description: t("subscriptions_management.confirmed_unsubscribe_all.success_description"),
description_en: t("subscriptions_management.confirmed_unsubscribe_all.success_description", locale: :en),
}
rescue GdsApi::HTTPNotFound
# The user has already unsubscribed.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,21 @@

<p class="govuk-body"><%= t("subscriptions_management.confirm_unsubscribe_all.description") %></p>

<%= form_tag(action: :confirmed_unsubscribe_all) do %>
<%
ga4_data = {
event_name: "form_response",
type: "email subscription",
section: t("subscriptions_management.confirm_unsubscribe_all.heading", locale: :en),
action: "unsubscribe",
tool_name: "Get emails from GOV.UK"
}.to_json
%>
<%= form_tag(
{ action: :confirmed_unsubscribe_all },
data: {
module: "ga4-form-tracker",
ga4_form: ga4_data
}) do %>
<%= hidden_field_tag(:from, @from) %>
<%= render 'govuk_publishing_components/components/button', {
text: 'Unsubscribe',
Expand Down
26 changes: 21 additions & 5 deletions app/views/subscriptions_management/index.html.erb
Original file line number Diff line number Diff line change
@@ -1,18 +1,34 @@
<% content_for :title, t("subscriptions_management.heading") %>
<% if flash[:success] %>
<%= render 'govuk_publishing_components/components/success_alert', {
message: flash[:success]["message"],
description: flash[:success]["description"],
} %>
<%
ga4_data = {
event_name: "form_complete",
type: "email subscription",
text: flash[:success]["description_en"],
section: t("subscriptions_management.heading", locale: :en),
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: flash[:success]["message"],
description: flash[:success]["description"],
} %>
<% end %>
<% end %>
<% if flash[:subscription] %>
<% subscription = @subscriptions[flash[:subscription]['id']] %>
<% if subscription %>
<%
ga4_data = {
event_name: "form_response",
event_name: "form_complete",
type: "email subscription",
text: t("subscriptions_management.index.flashes.subscription", title: subscription["subscriber_list"]["title"], locale: :en),
section: t("subscriptions_management.heading", locale: :en),
Expand Down
17 changes: 16 additions & 1 deletion app/views/subscriptions_management/update_frequency.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,22 @@
margin_bottom: 6,
} %>
<%= form_tag change_frequency_path, method: :post do %>
<%
ga4_data = {
event_name: "form_response",
type: "email subscription",
section: t("subscriptions_management.update_frequency.title", subscription_title: get_subscription_title(@subscriptions[@subscription_id]), locale: :en),
action: "save",
tool_name: "Get emails from GOV.UK"
}
%>
<%= form_tag(
change_frequency_path,
method: :post,
data: {
module: "ga4-form-tracker",
ga4_form: ga4_data
}) do %>
<%= hidden_field_tag :id, @subscription_id %>
<%= render 'govuk_publishing_components/components/radio', {
name: 'new_frequency',
Expand Down

0 comments on commit 382a28b

Please sign in to comment.