diff --git a/app/assets/javascripts/discourse/app/components/search-menu/results.hbs b/app/assets/javascripts/discourse/app/components/search-menu/results.hbs index a026fd5322f..bfbf0911971 100644 --- a/app/assets/javascripts/discourse/app/components/search-menu/results.hbs +++ b/app/assets/javascripts/discourse/app/components/search-menu/results.hbs @@ -43,6 +43,7 @@ @resultTypes={{this.resultTypesWithComponent}} @topicResultsOnly={{true}} @closeSearchMenu={{@closeSearchMenu}} + @searchLogId={{this.searchLogId}} /> {{/if}} {{/if}} diff --git a/app/assets/javascripts/discourse/app/components/search-menu/results.js b/app/assets/javascripts/discourse/app/components/search-menu/results.js index 3be639b32b4..4c8be480c06 100644 --- a/app/assets/javascripts/discourse/app/components/search-menu/results.js +++ b/app/assets/javascripts/discourse/app/components/search-menu/results.js @@ -46,6 +46,10 @@ export default class Results extends Component { return content; } + get searchLogId() { + return this.search.results.grouped_search_result?.search_log_id; + } + @action updateSearchTopics(value) { this.searchTopics = value; diff --git a/app/assets/javascripts/discourse/app/components/search-menu/results/types.hbs b/app/assets/javascripts/discourse/app/components/search-menu/results/types.hbs index 2c9660a994b..11cf81ebb71 100644 --- a/app/assets/javascripts/discourse/app/components/search-menu/results/types.hbs +++ b/app/assets/javascripts/discourse/app/components/search-menu/results/types.hbs @@ -11,10 +11,19 @@ {{#each resultType.results as |result|}} {{! template-lint-disable no-pointer-down-event-binding }} {{! template-lint-disable no-invalid-interactive }} -
  • +
  • { return helper.response({}); }); + + server.post("/search/click", () => { + return helper.response({ success: "OK" }); + }); }); test("full page search - the right filters are shown", async function (assert) { @@ -1140,6 +1144,10 @@ acceptance("Search - assistant", function (needs) { ], }); }); + + server.post("/search/click", () => { + return helper.response({ success: "OK" }); + }); }); test("initial options - shows category shortcuts when typing #", async function (assert) { diff --git a/spec/system/search_spec.rb b/spec/system/search_spec.rb index 623ba33da70..fdd932cc09d 100644 --- a/spec/system/search_spec.rb +++ b/spec/system/search_spec.rb @@ -106,5 +106,25 @@ describe "Search", type: :system do search_page.click_search_icon expect(search_page).to have_topic_title_for_first_search_result(topic.title) end + + it "tracks search result clicks" do + expect(SearchLog.count).to eq(0) + + visit("/") + search_page.click_search_icon + search_page.type_in_search_menu("test") + search_page.click_search_menu_link + + expect(search_page).to have_topic_title_for_first_search_result(topic.title) + find(".search-menu-container .search-result-topic", text: topic.title).click + + try_until_success { expect(SearchLog.count).to eq(1) } + try_until_success { expect(SearchLog.last.search_result_id).not_to eq(nil) } + + log = SearchLog.last + expect(log.term).to eq("test") + expect(log.search_result_id).to eq(topic.first_post.id) + expect(log.search_type).to eq(SearchLog.search_types[:header]) + end end end