Skip to content

Commit

Permalink
Merge pull request #9820 from alphagov/3317-apply-alert-tracking-to-f…
Browse files Browse the repository at this point in the history
…lash-alerts

Apply GA4 tracking to flash alerts
  • Loading branch information
gtvj authored Feb 3, 2025
2 parents 1421635 + 69bf344 commit 93973fd
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 1 deletion.
11 changes: 11 additions & 0 deletions app/components/admin/flash_alert_component.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,15 @@ class Admin::FlashAlertComponent < Admin::FlashMessageComponent
def component_name
"error_alert"
end

def data_attributes
{
module: "ga4-auto-tracker",
"ga4-auto": {
event_name: "flash_message",
text: message,
action: "error",
}.to_json,
}
end
end
5 changes: 4 additions & 1 deletion app/components/admin/flash_message_component.html.erb
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
<%=
content_tag(:div) do
render "govuk_publishing_components/components/#{component_name}", { message: }
render "govuk_publishing_components/components/#{component_name}", {
message: message,
data_attributes: data_attributes,
}
end
%>
2 changes: 2 additions & 0 deletions app/components/admin/flash_message_component.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,6 @@ def message
@message
end
end

def data_attributes; end
end

0 comments on commit 93973fd

Please sign in to comment.