diff --git a/web/templates/search.html b/web/templates/search.html
index 851fca0..720beb9 100644
--- a/web/templates/search.html
+++ b/web/templates/search.html
@@ -147,13 +147,15 @@
list.appendChild(li);
});
}
- fetch(bust("{% url 'api_get_search_history' %}"), {
+ function refetchHistory(){
+ fetch(bust("{% url 'api_get_search_history' %}"), {
cache: 'no-store',
credentials: 'same-origin'
- })
- .then(r=>r.json()).then(j=>{
+ }).then(r=>r.json()).then(j=>{
if (j.ok) renderHistory(j.items);
}).catch(()=>{});
+ }
+ refetchHistory();
// Recently viewed
function renderRecent(items){
@@ -174,13 +176,34 @@
list.appendChild(li);
});
}
- fetch(bust("{% url 'api_get_recent_views' %}"), {
+ function refetchRecent(){
+ fetch(bust("{% url 'api_get_recent_views' %}"), {
cache: 'no-store',
credentials: 'same-origin'
- })
- .then(r=>r.json()).then(j=>{
+ }).then(r=>r.json()).then(j=>{
if (j.ok) renderRecent(j.items);
}).catch(()=>{});
+ }
+ refetchRecent();
+
+ // ✅ Log searches with Beacon on submit (this is what was missing)
+ const searchForm = document.querySelector('form.search-form');
+ if (searchForm){
+ searchForm.addEventListener('submit', ()=>{
+ try{
+ const fd = new FormData(searchForm);
+ const data = new URLSearchParams();
+ data.append('q', (fd.get('q') || '').trim());
+ // selected checkboxes (match your field names)
+ ['subject','illustration','application','scripture_raw','source','talk_title','talk_number','entry_code']
+ .forEach(k=>{
+ if (fd.get(k)) data.append(`sel[${k}]`, 'on');
+ });
+ const blob = new Blob([data.toString()], { type:'application/x-www-form-urlencoded' });
+ navigator.sendBeacon("{% url 'api_log_search' %}", blob);
+ }catch(_){}
+ });
+ }
// Dropdown toggle for History
document.querySelectorAll('.dropdown-toggle').forEach(btn=>{