-
Notifications
You must be signed in to change notification settings - Fork 20
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add GA4 tracking for content navigation #3420
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
All looks good, some minor comments/suggestions, can you also merge some of the commits together? e.g. yml + test + change in one commit, per component.
app/views/govuk_publishing_components/components/_contents_list.html.erb
Outdated
Show resolved
Hide resolved
app/views/govuk_publishing_components/components/_contents_list.html.erb
Outdated
Show resolved
Hide resolved
app/views/govuk_publishing_components/components/_previous_and_next_navigation.html.erb
Show resolved
Hide resolved
app/views/govuk_publishing_components/components/_previous_and_next_navigation.html.erb
Outdated
Show resolved
Hide resolved
app/views/govuk_publishing_components/components/_previous_and_next_navigation.html.erb
Outdated
Show resolved
Hide resolved
app/views/govuk_publishing_components/components/_previous_and_next_navigation.html.erb
Outdated
Show resolved
Hide resolved
app/views/govuk_publishing_components/components/_previous_and_next_navigation.html.erb
Show resolved
Hide resolved
Thanks @andysellick I've made the changes - will squash everything once approved 👍 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just a couple of small comments but happy to approve and let you sort them out and squash commits etc. 👍
local_assigns[:aria] ||= {} | ||
component_helper = GovukPublishingComponents::Presenters::ComponentWrapperHelper.new(local_assigns) | ||
component_helper.add_class("gem-c-contents-list #{brand_helper.brand_class}") | ||
component_helper.add_data_attribute({ module: "gem-track-click" }) | ||
component_helper.add_data_attribute({ module: "ga4-link-tracker" }) if ga4_tracking | ||
component_helper.add_data_attribute({ga4_link: ga4_data, ga4_track_links_only: ""}) if ga4_tracking |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nitpick: can you add spaces to match the previous lines? i.e.
component_helper.add_data_attribute({ ga4_link: ga4_data, ga4_track_links_only: "" }) if ga4_tracking
ga4_link_data = nil | ||
if ga4_tracking | ||
ga4_link_data = {"index": {"index_link": position}, "index_total": contents.length}.to_json | ||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should be able to shorten this? Also (nitpick) please add spaces to improve readability, as shown.
ga4_link_data = { "index": { "index_link": position }, "index_total": contents.length }.to_json if ga4_tracking
I didn't use data-ga4-set-indexes as the page you're on is part of the list, but it isn't a link. So it needs to be included in the indexes, but it's not a HTML link. data-ga4-set-indexes only sets indexes by presence of HTML links. Therefore the index_total and indexes would always be off. Therefore we manually set the indexes in the template so that the item that isn't a link in the list is included.
200397b
to
9c8a584
Compare
Thanks @andysellick, squashed and fixed those two issues. Would you be able to approve the Percy change? Thanks! |
Would you be able to approve this PR if all is OK? Thanks 👍
What
Adds the
ga4_tracking
option to three components. When this is set to true, it will add the relevant GA4 attributes.Why
https://trello.com/c/C9M2EJQu/553-content-navigation-chapter-headings-next-previous-view-a-printable-version-navigation-and-show-hide-updates-interaction
I have a branch in
government-frontend
that will use these attributes.Visual Changes
None.