Skip to content

Commit

Permalink
Merge pull request #3515 from alphagov/ga4-attachment-refactor
Browse files Browse the repository at this point in the history
Move GA4 attachment link tracking to all attachment links
  • Loading branch information
AshGDS authored Aug 14, 2023
2 parents 3659c8c + beeb017 commit 63b839f
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 9 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
* Add navigation-page-type GA4 pageview attribute ([PR #3529](https://github.com/alphagov/govuk_publishing_components/pull/3529))
* Update the documentation for loading component stylesheets individually ([PR #3543](https://github.com/alphagov/govuk_publishing_components/pull/3543))
* Add GA4 video tracking ([PR #3535](https://github.com/alphagov/govuk_publishing_components/pull/3535))
* Move GA4 attachment link tracking to all attachment links ([PR #3515](https://github.com/alphagov/govuk_publishing_components/pull/3515))

## 35.13.1

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,6 @@
"HTML",
class: "gem-c-attachment__attribute",
)
data_attributes[:module] ? data_attributes[:module] << " ga4-link-tracker" : data_attributes[:module] = "ga4-link-tracker"
data_attributes[:ga4_link] = { "event_name": "navigation", "type": "attachment" }.to_json
when "external"
attributes << tag.span(
attachment.url,
Expand All @@ -53,7 +51,7 @@
end

%>
<%= tag.section class: class_names(container_class_names) do %>
<%= tag.section class: class_names(container_class_names), data: { module: "ga4-link-tracker", ga4_track_links_only: "", ga4_link: { 'event_name': 'navigation', 'type': 'attachment' } } do %>
<%= tag.div class: "gem-c-attachment__thumbnail" do %>
<%= link_to attachment.url,
class: "govuk-link",
Expand Down
11 changes: 5 additions & 6 deletions spec/components/attachment_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -269,19 +269,18 @@ def assert_thumbnail(type, src: nil)
assert_select '.gem-c-attachment:not([class*="govuk-!-margin-bottom-"])'
end

it "adds GA4 tracking on HTML attachment links" do
it "includes GA4 tracking on attachment links by default" do
render_component(
attachment: {
title: "Test",
url: "https://assets.publishing.service.gov.uk/government/uploads/system/uploads/attachment_data/file/687542/February_2018_Consular_MI.csv",
url: "https://example.com",
filename: "test",
type: "html",
},
)

assert_select "h2 a[data-module=ga4-link-tracker]"
assert_select ".gem-c-attachment__thumbnail a[data-module=ga4-link-tracker]"
assert_select "h2 a[data-ga4-link='{\"event_name\":\"navigation\",\"type\":\"attachment\"}']"
assert_select ".gem-c-attachment__thumbnail a[data-ga4-link='{\"event_name\":\"navigation\",\"type\":\"attachment\"}']"
assert_select "section[data-module=ga4-link-tracker]"
assert_select "section[data-ga4-link='{\"event_name\":\"navigation\",\"type\":\"attachment\"}']"
assert_select "section[data-ga4-track-links-only]"
end
end

0 comments on commit 63b839f

Please sign in to comment.