From 8dd5365ac7f7e54250b6f0bab495082324d95766 Mon Sep 17 00:00:00 2001 From: maebeale Date: Tue, 3 Mar 2026 07:33:53 -0500 Subject: [PATCH] Add Ahoy tracking to FAQs for search and view events FaqsController was missing the AhoyTracking concern, so FAQ searches and page views were not being captured as Ahoy events. This adds track_index_intent on index and track_view on show, matching the pattern used in other controllers. Co-Authored-By: Claude Opus 4.6 --- app/controllers/faqs_controller.rb | 3 +++ spec/requests/faqs_spec.rb | 32 ++++++++++++++++++++++++++++++ 2 files changed, 35 insertions(+) diff --git a/app/controllers/faqs_controller.rb b/app/controllers/faqs_controller.rb index 06d292728..7f8e6fbef 100644 --- a/app/controllers/faqs_controller.rb +++ b/app/controllers/faqs_controller.rb @@ -1,4 +1,5 @@ class FaqsController < ApplicationController + include AhoyTracking skip_before_action :authenticate_user!, only: [ :index, :show ] before_action :set_faq, only: [ :show, :edit, :update, :destroy ] @@ -8,10 +9,12 @@ def index @faqs = faqs.search_by_params(params.to_unsafe_h.slice("query", "published")) .by_position .page(params[:page]) + track_index_intent(Faq, @faqs, params) end def show authorize! @faq + track_view(@faq) end def new diff --git a/spec/requests/faqs_spec.rb b/spec/requests/faqs_spec.rb index 5cc465fd8..3ffd5cf06 100644 --- a/spec/requests/faqs_spec.rb +++ b/spec/requests/faqs_spec.rb @@ -23,6 +23,38 @@ let!(:unpublished_faq) { create(:faq, question: "Unpublished FAQ", answer: "Unpublished FAQ Body") } let!(:public_faq) { create(:faq, :published, question: "Public FAQ", answer: "Public FAQ Body", publicly_visible: true) } + describe "Ahoy tracking" do + before { sign_in admin } + + describe "GET /index" do + it "tracks a search event when a query param is present" do + expect(Analytics::AhoyTracker).to receive(:track_index_intent).with( + anything, Faq, params: anything, result_count: anything + ) + + get faqs_path, params: { query: "Published" } + end + + it "calls track_index_intent even without search params" do + expect(Analytics::AhoyTracker).to receive(:track_index_intent).with( + anything, Faq, params: anything, result_count: anything + ) + + get faqs_path + end + end + + describe "GET /show" do + it "tracks a view event" do + expect(Analytics::AhoyTracker).to receive(:track).with( + anything, :view, published_faq + ) + + get faq_path(published_faq) + end + end + end + describe "GET /index" do context "as an admin" do before { sign_in admin }