Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add UI search event hooks #637

Open
tlvince opened this issue Jun 17, 2024 · 1 comment
Open

Add UI search event hooks #637

tlvince opened this issue Jun 17, 2024 · 1 comment

Comments

@tlvince
Copy link

tlvince commented Jun 17, 2024

I'm looking to add telemetry to @pagefind/default-ui to track engagement with the search component. Being able to hook into certain event types such as "search field focused", "form submitted", "results received" etc. would be super useful.

@tlvince
Copy link
Author

tlvince commented Jun 17, 2024

As a workaround, I'm inferring "form submitted" by checking for changes in the results div, with something like:

new MutationObserver((mutations) => {
  for (const mutation of mutations) {
    if (mutation.type === "childList") {
      mutation.addedNodes.forEach((node) => {
        if (
          node instanceof Element &&
          node.classList.contains("pagefind-ui__results")
        ) {
          console.log("Search: results received");
        }
      });
    }
  }
}).observe(document.querySelector("#search-container"), {
  childList: true,
  subtree: true,
});

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant