PageSourceSearch

https://railsblocks.com/assets/controllers/component_search_contro…27a728c1da3d86ff278ee2d95f0bac0bdd567774.js

js railsblocks.com collected 2026-09-25 20:22:59 UTC 892 bytes, 36 lines download raw bytes

1import { Controller } from "@hotwired/stimulus";
2
3export default class extends Controller {
4  static targets = ["searchInput"];
5  static values = {
6    delay: { type: Number, default: 1000 }, // Delay before tracking search
7  };
8
9  connect() {
10    this.searchTimeout = null;
11  }
12
13  trackSearch(event) {
14    const query = event.target.value.trim();
15
16    // Clear any existing timeout
17    clearTimeout(this.searchTimeout);
18
19    // Only track if there's a query
20    if (query.length > 0) {
21      this.searchTimeout = setTimeout(() => {
22        if (typeof fathom !== "undefined") {
23          fathom.trackEvent("component search");
24        }
25
26        // Track with PostHog
27        if (typeof posthog !== "undefined") {
28          posthog.capture("component search", {
29            query: query,
30            query_length: query.length,
31          });
32        }
33      }, this.delayValue);
34    }
35  }
36};

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.