Enable on-site search signals in the Connect web library

You can enable the Connect library to record the search terms that your website visitors use and the number of results they get. The on-site search signal usually requires little to moderate effort to configure.

Availability

The on-site search signal is supported by Premium and Ultimate subscriptions.

Configuration

The Connect library provides a method, TLT.logSignal() with which to send the signal to the Acoustic Connect endpoint, as a JSON object.

If you have already enabled the page view signal on your website, you could adopt a similar approach for the on-site search signal, capturing the URL of the search results page. In many cases the search results URL will include a query string containing the search term.

You must populate the required fields before sending the signal: the search term (what the user searched for) and the number of results returned by the search. You could capture the search term from the query string, scrape the search term from the page, or capture the value entered by the user in a search field. The number of search results is often available in the page body. Some websites (BBC, for example) only show the number of search results pages rather than the actual results. In that case, you may need to do some maths to get the number of results.

Example from bbc.co.uk

Example from bbc.co.uk

If no results are returned for a search, set the effect field to "negative".

Required fields

FieldValuesDefinition
categoryString. Valid value - Behavior. The category of the signal. Do not edit.
effectString. Valid values:

- negative
- positive
Describes the effect of the signal on engagement. It is intended to be used for engagement index scoring.

If a search term returns results, send positive as the value. If there are no results, send negative.
nameString, up to 256 characters Assign a name to the signal to differentiate it from other signals.
numberOfResultsNumberThe number of results that matched the search term.

You must provide a value for this field, or the signal will be ignored.
searchTermStringThe word or phrase that the visitor searched for.

You must provide a value for this field, or the signal will be ignored.
signalTypeString. Valid value -
onSiteSearch.
The type of signal to enable. Do not edit.

Optional fields

FieldValuesDefinition
signalCustomAttributesArrayAllows for custom attributes that are not predefined by the product

Example

// Check that the Connect SDK is present
if (window.TLT && window.TLT.isInitialized()) {

    const href = window.location.href;

    const signal = {
        signalType: "onSiteSearch",
        name: "onSiteSearch generated by web site",
        category: "Behavior",
        searchTerm: "", // Required
        numberOfResults: 0, // Required
        effect: "", // Required
        signalCustomAttributes: []
    };

    // If we are on the search results page
    if (href.includes("s?searchTerm=")) {

        // Get search term from the query string
        signal.searchTerm = href.split("s?searchTerm=")[1] || "";
        // If there are multiple words in the search term, replace "+" with spaces
        signal.searchTerm = signal.searchTerm.replaceAll("+", " ");

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

        // Set "positive" or "negative" effect depending on the number of results
        signal.effect = (signal.numberOfResults) ? "positive" : "negative";

        // Optional: display signal in console
        console.log("onSiteSearch signal: " + JSON.stringify(signal, undefined, 2));

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

}