Track search queries in GoatCounter
Assisted-by: Claude Sonnet 4.6 via Claude Code
change plwloolzmlsommrtvwqmzooyqrquyolz
commit 5ecfd84cd3394796835da81848b104eaecf987b9
author Alpha Chen <alpha@kejadlen.dev>
date
parent xrrnxwnx
diff --git a/Rakefile b/Rakefile
index 51b4d5a..5f6acb6 100644
--- a/Rakefile
+++ b/Rakefile
@@ -282,6 +282,16 @@ file INDEX_HTML_PATH => [*EPISODE_HTML_PATHS, LAYOUT_TEMPLATE_PATH, INDEX_TEMPLA
           });
 
           sortSelect.addEventListener('change', (e) => applySort(e.target.value));
+
+          let searchTimer;
+          instance.on('results', () => {
+            const term = instance.searchTerm;
+            if (!term) return;
+            clearTimeout(searchTimer);
+            searchTimer = setTimeout(() => {
+              window.goatcounter?.count({ path: 'search:' + term, title: 'Search: ' + term, event: true });
+            }, 800);
+          });
         </script>
       HTML
     })