ais-hits
<ais-hits // Optional parameters :escapeHTML="boolean" :class-names="object" :transform-items="function" />
About this widget
The ais-hits
is used to display a list of results.
To configure the number of hits to show, use the ais-hits-per-page
widget or the ais-configure
widget.
Examples
1
<ais-hits />
Props
escapeHTML
|
type: boolean
default: true
Optional
Whether to escape HTML entities from hits string values. |
||
Copy
|
|||
class-names
|
type: object
default: {}
Optional
The CSS classes to override.
|
||
Copy
|
|||
transform-items
|
type: function
default: x => x
Optional
Receives the items, and is called before displaying them. Should return a new array with the same shape as the original array. Useful for mapping over the items to transform, and remove or reorder them. |
||
Copy
|
Customize the UI
default
|
The slot to override the complete DOM output of the widget. Scope
|
||
Copy
|
|||
item
|
The slot to override the DOM output of the item. Scope
|
||
Copy
|
Sending Click and Conversion events
InstantSearch can connect with the Insights API client for JavaScript to allow sending click and conversion events right from the ais-hits
widget.
Requirements
This requires installing the search-insights
library separately:
You can refer to our insights API documentation for more details.
It’s a 3-step process:
1. Install the Insights API client for JavaScript
1
2
3
4
5
6
7
8
9
10
11
12
13
<script>
var ALGOLIA_INSIGHTS_SRC = "https://cdn.jsdelivr.net/npm/search-insights@1.1.1";
!function(e,a,t,n,s,i,c){e.AlgoliaAnalyticsObject=s,e.aa=e.aa||function(){
(e.aa.queue=e.aa.queue||[]).push(arguments)},i=a.createElement(t),c=a.getElementsByTagName(t)[0],
i.async=1,i.src=ALGOLIA_INSIGHTS_SRC,c.parentNode.insertBefore(i,c)
}(window,document,"script",0,"aa");
aa('init', {
appId: 'YourApplicationID',
apiKey: 'YourSearchOnlyAPIKey',
});
</script>
2. Connect the Insights API client for JavaScript with InstantSearch and enable clickAnalytics
1
2
3
4
5
6
7
<ais-instant-search
[...]
:insights-client="window.aa"
>
<ais-configure :clickAnalytics="true" />
<!-- widgets -->
</ais-instant-search>
3. Call the insights function from your ais-hits
component
1
2
3
4
5
6
7
8
9
10
<ais-hits>
<div slot-scope="{ items, insights }">
<div v-for="item in items">
<h1>{{item.name}}</h1>
<button @click="insights('clickedObjectIDsAfterSearch', { eventName: 'Add to cart', objectIDs: [item.objectID] })">
Add to cart
</button>
</div>
</div>
</ais-hits>
Provided props
insights
|
type: function
signature: (method: string, payload: object) => void
Sends insights events.
When not provided,
It is worth noting that each element of
For more details on the contraints that apply to each |
Example
1
2
3
4
5
6
7
8
9
10
11
12
13
<ais-hits>
<div slot-scope="{ items, insights }">
<div v-for="item in items">
<a href="/product?queryID={{item.__queryID}}">
<h1>{{item.name}}</h1>
</a>
<button @click="insights('clickedObjectIDsAfterSearch', { eventName: 'Add to cart', objectIDs: [item.objectID] })">
Add to cart
</button>
</div>
</div>
</ais-hits>
HTML output
1
2
3
4
5
6
7
8
9
10
11
12
13
<div class="ais-Hits">
<ol class="ais-Hits-list">
<li class="ais-Hits-item">
...
</li>
<li class="ais-Hits-item">
...
</li>
<li class="ais-Hits-item">
...
</li>
</ol>
</div>