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

ga4 tracking for filter/sorting UI interaction #3485

Merged
merged 11 commits into from
Oct 7, 2024
Merged

Conversation

alexbowen
Copy link
Contributor

@alexbowen alexbowen commented Sep 30, 2024

For new search page implementation, this PR adds ga4 initialisation and attributes to filters and sorting UI to meet requirements listed here:

https://docs.google.com/spreadsheets/d/1dRoxYPatZiNJGYZEc6E_FZ5xeD_aWQdGxQfYK1dUFq0

  • Filter panel is a simple custom accordion and tracking of opening and closing is implemented using the data-ga4-expandable attribute which adds opened/closed to the action property of the event data.
  • Filter sections are standard HTML details elements and tracking of opening and closing is implemented again using the data-ga4-expandable attribute which adds opened/closed to the action property of the event data.
  • Interaction with form elements that apply filtering/sorting adds ga4 events using the existing finder-frontend/app/assets/javascripts/analytics-ga4/ga4-finder-tracker.js script. The new all-content-finder search page uses a form with id to identify it and initialise the tracking scripts if the form is present (and cookie consent has been granted from the user).
  • Filter/sorting remove links and clear all links (filter-summary component) use ga4-event-tracker attribute and standard child attributes to track when they are clicked.

No visual changes.

@govuk-ci govuk-ci temporarily deployed to finder-frontend-pr-3485 September 30, 2024 12:17 Inactive
@alexbowen alexbowen changed the title add ga4 tracking to filter panel ga4 tracking for filter panel and section open/close Sep 30, 2024
@andysellick
Copy link
Contributor

@alexbowen it's possible that some existing functionality using the data-ga4-expandable attribute might help you here, see: https://github.com/alphagov/govuk_publishing_components/blob/main/docs/analytics-ga4/trackers/ga4-event-tracker.md#advanced-use

@alexbowen
Copy link
Contributor Author

alexbowen commented Oct 2, 2024

@alexbowen it's possible that some existing functionality using the data-ga4-expandable attribute might help you here, see: https://github.com/alphagov/govuk_publishing_components/blob/main/docs/analytics-ga4/trackers/ga4-event-tracker.md#advanced-use

@andysellick Yeah i was aware of this. Will have a look again at this now i am more familiar with ga4 stuff. was having trouble getting data-ga4-expandable to work before but am about to revisit.

@govuk-ci govuk-ci temporarily deployed to finder-frontend-pr-3485 October 2, 2024 10:27 Inactive
@govuk-ci govuk-ci temporarily deployed to finder-frontend-pr-3485 October 2, 2024 11:48 Inactive
@govuk-ci govuk-ci temporarily deployed to finder-frontend-pr-3485 October 2, 2024 11:51 Inactive
@govuk-ci govuk-ci temporarily deployed to finder-frontend-pr-3485 October 2, 2024 13:23 Inactive
@govuk-ci govuk-ci temporarily deployed to finder-frontend-pr-3485 October 2, 2024 13:40 Inactive
@govuk-ci govuk-ci temporarily deployed to finder-frontend-pr-3485 October 2, 2024 14:09 Inactive
@govuk-ci govuk-ci temporarily deployed to finder-frontend-pr-3485 October 2, 2024 14:24 Inactive
@govuk-ci govuk-ci temporarily deployed to finder-frontend-pr-3485 October 2, 2024 14:46 Inactive
@govuk-ci govuk-ci temporarily deployed to finder-frontend-pr-3485 October 2, 2024 14:50 Inactive
@alexbowen alexbowen changed the title ga4 tracking for filter panel and section open/close ga4 tracking for filter/sorting UI interaction Oct 2, 2024
@govuk-ci govuk-ci temporarily deployed to finder-frontend-pr-3485 October 2, 2024 20:04 Inactive
@alexbowen alexbowen marked this pull request as ready for review October 3, 2024 10:27
@govuk-ci govuk-ci temporarily deployed to finder-frontend-pr-3485 October 3, 2024 12:03 Inactive
@govuk-ci govuk-ci temporarily deployed to finder-frontend-pr-3485 October 3, 2024 12:10 Inactive
}
}
})
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Note to self (@csutter): Not necessarily one for right now, but perhaps with the above code dealing with the new all content finder too, maybe it's worth creating a GOVUK.AllContentFinder module to not litter the application.js too much.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes i was thinking to put this in a more isolated place than here but was in 2 minds about a few places where exactly. so I have left as is for the purposes of this PR, but agreed its a bit lazy just whacking it here in the long run

section: button_text,
text: button_text,
index_section: 0,
index_section_count: 4
Copy link
Contributor

Choose a reason for hiding this comment

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

This probably shouldn't be hardcoded, but rather passed into this component (as the number of sections might change).

section: "Filter and sort",
action: "search",
index_section: 0,
index_section_count: 4,
Copy link
Contributor

Choose a reason for hiding this comment

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

Ditto as above, should be a parameter to this component.

event_name: "select_content",
type: "finder",
text: button_text,
section: "Filter and sort",
Copy link
Contributor

Choose a reason for hiding this comment

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

This should also be button_text

"data-ga4-event" => {
event_name: "select_content",
type: "finder",
text: "Clear all",
Copy link
Contributor

Choose a reason for hiding this comment

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

This should be the same as the text of this link - maybe that should be configurable too?

event_name: "select_content",
type: "finder",
text: "Clear all",
section: "Filter and sort",
Copy link
Contributor

Choose a reason for hiding this comment

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

This should be button_text as well

event_name: "select_content",
type: "finder",
text: clear_all_text,
section: "Selected filters and sorting",
Copy link
Contributor

Choose a reason for hiding this comment

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

Should this be heading_text?

type: "finder",
section: heading_text,
text: heading_text,
index_section: index_section + 1,
Copy link
Contributor

Choose a reason for hiding this comment

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

We're already adding 1 to this in the views/finders/all_content_finder_facets/_*_facet.html.erb partials, should we be doing this again here?

} do %>
<div class="js-all-content-finder-taxonomy-select" data-ga4-change-category="update-filter select" data-ga4-section="Topic">
Copy link
Contributor

Choose a reason for hiding this comment

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

We need to keep the js-all-content-finder-taxonomy-select on this or it breaks the subtopic updating JS

Copy link
Contributor

Choose a reason for hiding this comment

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

As the filter_section component uses the standard component helper we should just be able to put that in classes on the component itself though.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

there was a reason i did this at some point and i did indeed mean to put that class the the container but must have got distracted! so the class is on the component now as that div seems uneccessary

index_section_count: 0,
}

render_component(heading_text:, data: button_event_attributes.to_json)
Copy link
Contributor

Choose a reason for hiding this comment

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

Not sure I follow where data ends up here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

similar i think a hangover from something early in implementing this, it is included all over tests and have removed all as yes they do absolutely nothing

@govuk-ci govuk-ci temporarily deployed to finder-frontend-pr-3485 October 4, 2024 21:22 Inactive
@csutter csutter merged commit 160b8b9 into main Oct 7, 2024
12 checks passed
@csutter csutter deleted the filters-ga4-tracking branch October 7, 2024 09:49
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.

4 participants