# Submit search

When submitting Search results through Autocomplete, `submit` callback is called on these events:

* **`Enter` key press.**
* **`Submit button` click.**
* **`Keyword` click.**

By default `submit` checks if query/keyword length satisfies `minQueryLength`, sends `Search Submit event` to Nosto Analytics, and sends Search request to the Nosto Search API.

In the usual scenario, you want to render Search Results on submit, so you should override `submit` function:

```javascript
submit: async (query, config, options) => {
    if (
        query.length >= config.minQueryLength
    ) {
        const response = await search(
            {
                query,
            },
            {
                redirect: true,
                track: config.nostoAnalytics ? "serp" : undefined,
                ...options
            }
        )
        // Do something with response. For example, update Search Engine Results Page products state.
    }
},
```

To disable `submit` pass `undefined` value.\
\\

#### 📊 Nosto Analytics (enabled by default)

Setting `nostoAnalytics: true` will enable Nosto Analytics tracking. Tracking results can be seen in the Nosto Dashboard under Search & Categories -> Analytics page.

{% hint style="info" %}
Note: You should additionally add click events on your search results page according to [Nosto Tech Docs](/techdocs/implementing-nosto/implement-search/search.md#search-product-click) with `type: serp || category` according to the results page type.
{% endhint %}

#### 📈 Google Analytics (enabled by default)

By default, we send `pageview` events to existing GA tag, found in shop site. To send `pageview` events with correct search information, a minimal configuration is needed in `googleAnalytics` property.

* **`serpPath`** - Search query url parameter name
* **`queryParamName`** - Search query url parameter name
* **`enabled`** - Enable Google Analytics

For example, if search results URL is <https://examplenostoshop.com/search-results?query=shoes>, then configuration should be:

```javascript
googleAnalytics: {
    serpPath: "search-results",
    queryParamName: "query",
    enabled: true
}
```

To disable Google Analytics, set `googleAnalytics: false`.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.nosto.com/techdocs/implementing-nosto/implement-search/search/implement-autocomplete-using-library/initialization/submit-search.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
