Hello everyone, in order to make my product more qualitative and adapt it to my customers, I would like to retrieve the search queries when the Inbox Block displays “No results found”, i.e. when I have not results to offer.
I’ve seen changes in the DOM with some div disappearing, but I don’t know how to get that back. an idea ? Behind I would like to do some statistics in order to know what is the next content to develop
I’d be interested in capturing search terms that lead to a 0-result too; in an ideal world they’d be tracked as such in GA, but that might require a query parameter in the URL. Following this topic in case a solution without too much custom coding comes up!
Just replace your WEBHOOK_URL and NAME_OF_INBOX_BLOCK in the code
Here is the code, This code uses a debounce function and a timer to delay sending search results to a webhook until the user stops typing in a search box for a specified amount of time.
let searchResults = null;
let typingTimer;
const onFilterChange = (e) => {
console.log(e.detail);
// e.detail contains the search data
// Store the search data in the variable searchResults
searchResults = {
search: e.detail.search,
filter: e.detail.filter
};
// Determine if the user has finished typing
clearTimeout(typingTimer);
typingTimer = setTimeout(() => {
sendSearchResults();
}, 3000); // 3 second delay
};
const sendSearchResults = () => {
if (searchResults !== null) {
console.log('Sending search results:', searchResults);
// Send data to a webhook via a POST request
const url = "WEBHOOK_URL";
let IDuser = window['logged_in_user']['airtable_record_id'];
const data = {
search: searchResults.search,
filter: searchResults.filter,
user: IDuser
};
fetch(url, {
method: "POST",
body: JSON.stringify(data),
headers: {
"Content-Type": "application/json"
}
})
.then(response => {
console.log(response);
})
.catch(error => {
console.error(error);
});
// Réinitialiser la variable searchResults
searchResults = null;
}
};
setTimeout(() => {
window.addEventListener('get-records-NAME_OF_INBOX_BLOCK:before', onFilterChange);
}, 1000); // 1000 milliseconds (1 second) delay
If someone wants to improve my code, don’t hesitate and send us the improvements