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.

Basic example

const signal = {
    // Required fields
    signalType: "onSiteSearch",
    category: "Behavior",
    name: "onSiteSearch from website",
    searchTerm: "wireless headphones",
    numberOfResults: 47,
    effect: "positive"
};

// Send the signal
TLT.logSignal(signal);

Complete implementation example

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

// Check that the Connect SDK is present
if (window.TLT && window.TLT.isInitialized()) {
    const href = window.location.href;

    const signal = {
        signalType: "onSiteSearch",
        category: "Behavior",
        name: "onSiteSearch generated by website",
        searchTerm: "",
        numberOfResults: 0,
        effect: ""
    };

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

        // Clean up the search term (replace + with spaces, decode URL encoding)
        signal.searchTerm = signal.searchTerm.replaceAll("+", " ");
        signal.searchTerm = decodeURIComponent(signal.searchTerm);

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

        // Set effect based on whether results were found
        signal.effect = signal.numberOfResults ? "positive" : "negative";

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

        // Send signal to Acoustic
        window.TLT.logSignal(signal);
    }
}

Best practices

  1. Clean search terms - Remove URL encoding, replace + with spaces, and trim whitespace.
  2. Test extraction logic - Verify search term and result count extraction across different search scenarios.
  3. Consider multiple formats - Sites may display results differently (total count vs. page count).
  4. Fire on page load - Trigger the signal when the search results page loads rather than on form submission.
  5. Validate required data - Only send the signal if both search term and result count are available.

Troubleshooting

Signal not firing on search results page?

  • Verify your page detection logic correctly identifies search results pages.
  • Check that the Connect library initializes before your signal code runs.
  • Confirm URL pattern matching works for all search variations.
  • Use console.log() to debug the detection logic.

Search term not extracted correctly?

  • Check for different query parameter names (q, search, query, searchTerm).
  • Verify URL decoding handles special characters properly.
  • Test with multi-word searches to ensure spaces are handled correctly.
  • Look for search term in page content if not in URL.

Result count is zero or incorrect?

  • Verify the selector matches your results count element.
  • Check if results are loaded dynamically after page load.
  • For page-based counts, ensure calculation logic is correct.
  • Test with both zero-result and multi-result searches.

Effect not set correctly?

  • Ensure effect is set after determining numberOfResults.
  • Use ternary operator or conditional to set based on result count
  • Remember: results found = positive, no results = negative.