Skip to content

add tracking to search flow#5626

Merged
ilayda-cp merged 11 commits intomainfrom
WD-35298-add-tracking-to-search
Mar 26, 2026
Merged

add tracking to search flow#5626
ilayda-cp merged 11 commits intomainfrom
WD-35298-add-tracking-to-search

Conversation

@ilayda-cp
Copy link
Copy Markdown
Contributor

@ilayda-cp ilayda-cp commented Mar 23, 2026

Done

  • Updated @canonical/analytics-events from 1.0.4 to 1.0.5 to use the new trackEvent function
  • Added search analytics tracking to the homepage and store page to understand user search patterns (whether users can find what they're searching for, what queries return no results, and which results they click on)
  • All search events share a search_id stored in sessionStorage to trace the full user journey from search to result click

How to QA

  1. Open browser devtools Console tab.

  2. Go to https://snapcraft-io-5626.demos.haus/

  3. Console: [analytics] trackPageView: snap_home_page

  4. Type "firefox" in the search box and press Enter

  5. Console: [analytics] snap_home_search_submitted {search_id: "...", query: "firefox"}

  6. Page navigates to /store?q=firefox

  7. After navigation, check console

  8. Console: [analytics] trackPageView: snap_store_page

  9. After results appear on screen

  10. Console: [analytics] snap_store_search_results_loaded {search_id: "...", query: "firefox", total_items: ..., page: "1"}

  11. Verify search_id matches step 5

  12. Click on any snap card

  13. Console: [analytics] snap_store_search_result_clicked {search_id: "...", query: "firefox", position: ...}

  14. Verify search_id matches step 5

  15. Go to /store

  16. Type "vlc" in the search box and press Enter

  17. Console: [analytics] snap_store_search_submitted {search_id: "...", query: "vlc"}

  18. Verify search_id is different from step 5 (new search = new ID)

  19. Console: [analytics] snap_store_search_results_loaded {search_id: "...", query: "vlc", ...}

  20. Verify search_id matches the new one from step 5

  21. On /store, type "xyzqwerty123456" and press Enter

  22. Console: [analytics] snap_store_search_submitted {search_id: "...", query: "xyzqwerty123456"}

  23. Console: [analytics] snap_store_search_no_results {search_id: "...", query: "xyzqwerty123456"}

  24. Verify empty results page is shown

  25. Verify all events within a single search journey share the same search_id

  26. Start a new search

  27. verify a new search_id is generated

Known limitations

  • "Open in new tab" on snap cards won't trigger snap_store_search_result_clicked (only same-tab clicks are tracked)
  • Homepage search submitted event may not reach the analytics endpoint due to page navigation, but search_id persists via sessionStorage and downstream events on /store will still fire
  • console.log lines are for QA only and should be removed before production

Testing

  • This PR has tests
  • No testing required (explain why):

Security

  • Security considerations for review (list them):
    • Examples:
    • Access control: users can only access their own data
    • Input: user input is validated and sanitised
    • Sensitive data: secret or private data is not exposed in any way
    • ...
  • This PR has no security considerations (explain why):

Issue / Card

Fixes #

UX Approval

  • This PR does not require UX approval
  • This PR does require UX approval (add context):

@webteam-app
Copy link
Copy Markdown

Copy link
Copy Markdown
Contributor

@steverydz steverydz left a comment

Choose a reason for hiding this comment

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

LGTM 👍

@ilayda-cp ilayda-cp merged commit 4723d4a into main Mar 26, 2026
14 checks passed
@ilayda-cp ilayda-cp deleted the WD-35298-add-tracking-to-search branch March 26, 2026 13:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants