Enable on-site search signals in the Connect web library

The on-site search signal captures the search terms visitors use on your website and the number of results returned. This helps identify what users are looking for, discover content gaps and understand search effectiveness.

Reasons to enable:

  • Track popular search terms
  • Identify zero-result searches for content optimization
  • Segment users based on search behavior
  • Trigger campaigns for users who can't find what they're looking for

Availability: Premium and Ultimate


Implementation considerations

Data extraction approaches

  • From URL query string. Many sites include search terms in the URL (for example, ?searchTerm=headphones). Extract the term by parsing the query string. Remember to decode URL encoding and replace + with spaces.
  • From page content. Scrape the search term displayed on the results page. Often shown in headings or result summaries.
  • From input field. Capture the value from the search input field. Useful if search doesn't navigate to a new page.

Number of results

The number of search results is typically available in the page body. Consider these scenarios:

  • Direct result count. Most sites display total results (for example, "Showing 47 results"). Scrape this number directly.
  • Page-based display. Some sites only show number of pages (for example, "Page 1 of 5"). If this is the case, calculate total results: pages × results per page.
Example from bbc.co.uk

Example from bbc.co.uk

  • Zero results. Set effect to negative when no results are found. This helps identify content gaps and failed searches.

Relationship to page view signal

If you've already enabled the page view signal, you can adopt a similar approach for the on-site search signal by capturing the URL of the search results page.


Configuration

Method

TLT.logSignal(signalObject)

Sends the signal to the Acoustic Connect endpoint as a JSON object. The Connect library must be initialized before calling this method.

Signal structure

Top-level fields

  • category: String - Valid value - Behavior.
  • description: String - Description of the signal
  • effect: String - Describes the effect of the signal on engagement. Valid values: negative, positive. If a search term returns results, send positive. If there are no results, send negative.
  • name: String - Name to differentiate this signal from others (for example, "onSiteSearch from online store"). Max length - 256 chars.
  • signalType (required): String - Valid value - onSiteSearch.

Signal content

  • numberOfResults (required): Number - The number of results that matched the search term
  • searchTerm (required): String - The word or phrase that the visitor searched for
  • signalCustomAttributes: Array of objects - Additional custom attributes. Each object has name and value string fields.

Example

This example extracts the search term from the URL query string and scrapes the result count:

if (window.TLT && window.TLT.isInitialized()) {
    const href = window.location.href;

    // Check if we are on the search results page
    if (href.includes("s?searchTerm=")) {
        // Extract and clean search term from query string
        let searchTerm = href.split("s?searchTerm=")[1] || "";
        searchTerm = searchTerm.replaceAll("+", " ");
        searchTerm = decodeURIComponent(searchTerm);

        // Scrape number of results from the page
        const numberOfResults = Number(document.querySelector(".itemCount")?.innerText) || 0;

        const signal = {
            signalType: "onSiteSearch",
            category: "Behavior",
            name: "onSiteSearch generated by website",
            
            // Required fields
            searchTerm: searchTerm,
            numberOfResults: numberOfResults,
            
            // Set effect based on whether results were found
            effect: numberOfResults ? "positive" : "negative"
        };

        // Optional: Log signal for debugging
        console.log("onSiteSearch signal:", JSON.stringify(signal, null, 2));

        // Send signal to Connect
        TLT.logSignal(signal);
    }
}