---
# System prepended metadata

title: Sparq Custom Javascript hooks.

---

# Sparq Custom Javascript hooks.

## On search init hook.

`onSearchInit(params) `

Whenever a new search is about to be sent to the Sparq servers, this hook is called with the raw query string and filter data. 

The params object after modifying should be returned back from the hook function, else it will corrupt the search functionality

#### The event receives the following data :

`params` - The search query to be sent to Sparq servers

The `params` object contains the following attributes 

- `query` - The text search query. 
- `filter` - A filter string which will be sent to the backend server. 

You can modify any of the query or filter data to modify the search behavior and change as per your requirements. 


Here is an implementation example.

```
window.sq = window.sq || {};

window.sq.onSearchInit = function(params) {
  console.log('params are here', params); // contains filter and query.

  /*
  	//you can update value of filter here
      params.filter = params.filter + " AND vendor=\"ADIDAS\" "
  */

  return params; // DO NOT REMOVE THIS. Removing this will corrupt search
}
```