Search term tracking - #800
Conversation
|
Hi @jdelagarzaf i implemented your feedbacks but run into some errors still Fixed: I moved tracking into a Stimulus controller pushing to window.dataLayer (not gtag, which was scoped/broken as you noted). I also verified this manually in browser's console which event fires correctly with search_term/category/location. Now event fires on search submit, not on page render, so no more inflated counts from reloads/pagination. RuboCop is also clean. I also rebased the branch onto main so history's no longer contaminated. Stuck: The fix works in a real browser, but I can't get the automated system spec to reliably observe the same event — passes manually, fails in Capybara/Cuprite despite trying a few approaches. Would love your help with this |
Hi @hazelngan , Also, the homepage has a separate search that is also untracked. Located at home/index.html.slim:9 with no search controller and no action. Searches from there result in no tracking And check this out: location is always undefined. tag at navbar/component.html.slim:11, not the search bar's tag at search_bar/component.html.erb:39. About your specs, The request spec is a false negative. Small detail: clearing the keyword fires a search event with search_term: "". Prevent that from happening; otherwise, it'll show up as empty search terms. |
@jdelagarzaf I edited the untracked preview template, the homepage search, the location selector bug, and the JSON.stringify masking in the system spec. I then confirmed in dataLayer locally: search events now carry the right search_term, category, and location together on the same object, from both the homepage and results page. All 4 specs pass on my terminal as well |
|
Great job Hazel! The feature as it stands is complete in code, unless you'd like to add filter capture. Currently, filters and pills that are activated are indistinguishable from regular searches. If you'd like to expand the ticket's capabilities and if it is in scope, you could add records of them. Besides that, now all that is left to do is configure it from the GTM console with the event name |


No description provided.