Skip to content

Track search events in Google Analytics

Sarah German requested to merge gps-ga-instrumentation into main

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
image image

dataLayer:

before this MR after
image image

How to set up and validate locally

This one is best tested on the review app, using browser dev tools:

  1. Run a search from the homepage or an interior content page, and inspect links in the dropdown. They should include this attribute:
  2. Run a search from the /search page and inspect result links there. They should include this attribute:
  3. On the results page (/search), type window.dataLayer into the dev tools console and hit enter. It should return undefined.
  4. 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.
  5. 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.

Edited by Sarah German

Merge request reports