Skip to content
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

Merged
merged 4 commits into from
Jun 6, 2023
Merged

Conversation

AshGDS
Copy link
Contributor

@AshGDS AshGDS commented May 30, 2023

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.

@govuk-ci govuk-ci temporarily deployed to components-gem-pr-3420 May 30, 2023 15:19 Inactive
@AshGDS AshGDS self-assigned this May 30, 2023
@AshGDS AshGDS requested review from andysellick and JamesCGDS May 30, 2023 15:25
@govuk-ci govuk-ci temporarily deployed to components-gem-pr-3420 May 30, 2023 15:26 Inactive
Copy link
Contributor

@andysellick andysellick left a 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.

@govuk-ci govuk-ci temporarily deployed to components-gem-pr-3420 June 5, 2023 10:55 Inactive
@AshGDS
Copy link
Contributor Author

AshGDS commented Jun 5, 2023

Thanks @andysellick I've made the changes - will squash everything once approved 👍

Copy link
Contributor

@andysellick andysellick left a 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
Copy link
Contributor

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
Copy link
Contributor

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

AshGDS added 4 commits June 6, 2023 10:37
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.
@AshGDS AshGDS force-pushed the ga4-content-navigation branch from 200397b to 9c8a584 Compare June 6, 2023 09:37
@govuk-ci govuk-ci temporarily deployed to components-gem-pr-3420 June 6, 2023 09:38 Inactive
@AshGDS
Copy link
Contributor Author

AshGDS commented Jun 6, 2023

Thanks @andysellick, squashed and fixed those two issues. Would you be able to approve the Percy change? Thanks!

@AshGDS AshGDS merged commit a5a805d into main Jun 6, 2023
@AshGDS AshGDS deleted the ga4-content-navigation branch June 6, 2023 12:32
@JamesCGDS JamesCGDS mentioned this pull request Jun 8, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants