Documentation
Integration guide and API reference.
Overview
ShopGate Rewrite Search is designed to be dropped into your existing frontend with minimal configuration. Our JavaScript plugin automatically intercepts search inputs, processes the query through our AI engine, and redirects the user to your search results page with the optimized query.
How it works
- Capture: The plugin listens for the submit event on your search form.
- Rewrite: It sends the raw query to the ShopGate API.
- Redirect: The API returns the optimized query, and the plugin redirects the browser to your search results page with the new query parameters.
Integration
Simply add our SDK to your <head> and initialize it with your API key and selector.
1. Add the Script
<script src="https://cdn.shopgate.ai/v1/sdk.js"></script>2. Initialize
<script>
ShopGate.init({
apiKey: 'YOUR_PUBLIC_API_KEY',
selector: 'input[name="q"]', // Selector for your search input
redirectUrl: '/search', // Your search results page
// Optional: Customize parameter mapping
onRewrite: (response) => {
const params = new URLSearchParams();
params.set('q', response.query);
return params.toString();
}
});
</script>Example Flow
- 1.User types
"nike ruing shos"and hits enter. - 2.Plugin intercepts the submit and calls ShopGate API.
- 3.API identifies "Nike Running Shoes" as the core query.
- 4.Plugin redirects user to:
/search?q=nike+running+shoes