Track search events in Google Analytics
What does this MR do and why?
This MR:
- Adds a
data-result-type
attribute to result links so that we can distinguish between clicks on the dropdown results vs the results page - Adds a push event when visitors select a filter on the results page
This MR enables tracking for search-related events for https://gitlab.com/gitlab-com/marketing/marketing-strategy-performance/-/issues/1273
Screenshots, screen recordings, or links to review app
Review app: https://gps-ga-instrumentation.docs.gitlab-review.app/
Result link data attributes:
Dropdown results | Results page |
---|---|
dataLayer:
before this MR | after |
---|---|
How to set up and validate locally
This one is best tested on the review app, using browser dev tools:
- Run a search from the homepage or an interior content page, and inspect links in the dropdown. They should include this attribute:
- Run a search from the
/search
page and inspect result links there. They should include this attribute: - On the results page (
/search
), typewindow.dataLayer
into the dev tools console and hit enter. It should return undefined. - Click a filter option, then type
window.dataLayer
into the dev tools console and hit enter again. It should show a new item in the dataLayer array containing the selected filter option. - Uncheck a filter option, then check
window.dataLayer
again. When unchecking an option, a new event should not be added.
Merge request acceptance checklist
This checklist encourages us to confirm any changes have been analyzed to reduce risks in quality, performance, reliability, security, and maintainability.
-
I have evaluated the MR acceptance checklist for this merge request.
Edited by Sarah German