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 a reset option into the GA4 scrolltracker #3544

Merged
merged 1 commit into from
Aug 11, 2023
Merged

Conversation

andysellick
Copy link
Contributor

What

  • code adds an event listener for 'dynamic-page-update' event, which resets all of the nodes to alreadySeen = false
  • this event can then be triggered by code elsewhere, in order to 'reset' scroll tracking on any given page
  • initial use is for search pages, where users change their search filters, page dynamically updates and so scroll tracking only works the first time, now if the search code triggers that event, the scroll tracker will reset

Why

Scroll tracking works correctly on search pages until users change their filters. At that point the user is effectively on a new page (content and URL change) and we want the scroll tracking to 'reset' (i.e. if the user has scrolled to the bottom of the page previously, we want to also record that happened after the search filters are changed). Unfortunately because the page was updated dynamically using JS, the scroll tracker still thinks its on the same page, and therefore doesn't register GA4 events when users scroll. This PR fixes that - a related PR will be raised in finder-frontend to add to required event trigger.

Visual Changes

None.

Trello card: https://trello.com/c/fhnLqnKw/669-scroll-tracker-to-refresh-on-dynamic-pages

@govuk-ci govuk-ci temporarily deployed to components-gem-pr-3544 August 10, 2023 10:06 Inactive
@govuk-ci govuk-ci temporarily deployed to components-gem-pr-3544 August 10, 2023 10:07 Inactive
andysellick added a commit to alphagov/finder-frontend that referenced this pull request Aug 10, 2023
- if listening, the scroll tracker will detect this event and reset scroll tracking
- see related PR: alphagov/govuk_publishing_components#3544
- code adds an event listener for 'dynamic-page-update' event, which resets all of the nodes to alreadySeen = false
- this event can then be triggered by code elsewhere, in order to 'reset' scroll tracking on any given page
- initial use is for search pages, where users change their search filters, page dynamically updates and so scroll tracking only works the first time, now if the search code triggers that event, the scroll tracker will reset
@govuk-ci govuk-ci temporarily deployed to components-gem-pr-3544 August 11, 2023 07:36 Inactive
Copy link
Contributor

@JamesCGDS JamesCGDS left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚀

@andysellick andysellick merged commit d6b35e7 into main Aug 11, 2023
6 checks passed
@andysellick andysellick deleted the scrolltracker-reset branch August 11, 2023 10:13
@andysellick andysellick mentioned this pull request Aug 15, 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