- InstantSearch banners: use a rule to add banner data to the
renderingContent.widgets.bannersfield, so that supported InstantSearch widgets render the banner for you. - Custom banners: use a rule to add banner data to the
userDatafield. Your own UI code reads this data and renders the banner.
InstantSearch banners
If your site already uses an InstantSearchHits or InfiniteHits
widget, you can display banners automatically based on a Visual Editor rule which adds banner data to the search response.
This requires InstantSearch.js version 4.73.0 or later, React InstantSearch version 7.12.0 or later, or Vue InstantSearch version 4.19.0 or later.
Create a Visual Editor rule with a banner consequence
- Click Create your first Rule or New rule and select Visual Editor.
- In the It all starts here section, click Set query conditions.
- In the Your query field, enter
harry potterand click Apply. - In the What do you want to do? section, click Add Banner.
- Enter the required content for your banner: the URL for your banner image and click Apply.
- Review the banner preview above the results.
- Confirm your changes by clicking Review and Publish.
Make sure your search UI uses a supported InstantSearch widget (
Hits or InfiniteHits) and
is deployed on your website so it can display banners from the renderingContent.widgets.banners property in the API response.Create a rule with a banner consequence using the API
To add a rule with a banner consequence using the API, use thesaveRule method.
When adding a rule, you need to define a condition and a consequence.
In the consequence, add search parameters and configure renderingContent using the following template:
JSON
Render banner with InstantSearch
After adding the rule, you can display the banner in your UI with the InstantSearchHits or InfiniteHits widgets.
The banner renders automatically unless you configure the widget to hide it.
For example:
Custom banners
If you don’t use InstantSearch, or you need a fully custom banner, use this approach.Create a rule for returning custom data
If you want to motivate users to buy Harry Potter books, you can display a special promotional banner at the top of search results whenever their search query containsharry potter.
To display the banner:
- Create a rule that returns the banner data in the
userDatafield. - Update your search UI to read and render this
userData.
Create a rule with the API
To add a rule, you need to use thesaveRule method.
When setting a rule, you need to define a condition and a consequence.
For the preceding example, you want to show the banner whenever the query contains harry potter.
The match doesn’t need to be exact.
If the query is harry potter azkaban or books harry potter, you still want to display the promotion.
Create a rule in the dashboard
To add rules in the Algolia dashboard:- Go to the Algolia dashboard and select your Algolia .
- On the left sidebar, select Search.
- Select your Algolia index.
- Open the Rules page in the Algolia dashboard.
- Select Create your first rule or New rule. In the drop-down menu, click the Manual Editor option.
- In the Condition(s) section, keep Query toggled on, select Contains from the drop-down menu, and enter “harry potter” in the input field.
-
In the Consequence(s) section:
- Click Add consequence and select Return Custom Data.
- In the input field, add the data to return when a search query matches the rule:
{ "promo_content": "20% OFF on all Harry Potter books!" }
- Save your changes.
Duplicate rules to adapt to user search patterns
To ensure that the Samsung Galaxy Note 20 Ultra banner displays for the search term “note” in the preceding example:- Duplicate the existing Samsung Galaxy Note 20 Ultra rule.
- Edit the rule to change the Query search phrase to “Note”.
Retrieve the banner data in your UI
The search response includes your banner data in theuserData property.
This data isn’t displayed automatically:
your search UI must read userData and render the banner when it’s present.
For example, with InstantSearch you can use the queryRuleCustomData widget:
- InstantSearch.js:
queryRuleCustomData - React InstantSearch:
QueryRulesCustomData - Vue InstantSearch:
ais-query-rule-custom-data
Apply rules with context conditions
If you want to apply rules based on context, see:- InstantSearch.js:
queryRuleContext - React InstantSearch:
QueryRuleContext - Vue InstantSearch:
ais-query-rule-context
Determine priority when you have multiple banners
You may have several semi-permanent promotional banners for specific product categories, as well as some time-limited, temporary banners for certain products. For instance, an online IT hardware store has banners for the following categories:- Phones
- Tablet computers
- Laptop computers
- Desktop computers
- Infinix Note 40 Pro
- Xiaomi Redmi Note 14 Pro+
- Samsung Galaxy S25 Ultra
- Samsung Galaxy Tab S10 Ultra
- Samsung Galaxy Book3 360
- User starts on the Phones category page and sees the Phones banner.
- They search for
note. - At this point, three rules can match: the Phones category banner and the two product banners for Infinix Note 40 Pro and Xiaomi Redmi Note 14 Pro+.
- The two product banners are more specific than the category banner, so they take precedence over it.
- When multiple rules match, Algolia compares their
objectIDvalues and shows the banner whoseobjectIDcomes first alphabetically.
In this context,
objectID refers to the rule’s ID, not to any product or record objectID in your index.
Rule objectIDs are unique identifiers for rules.
When using the API, you can set them manually.
In the dashboard, they’re generated automatically.To control this tie-breaker, set or change the rule’s objectID with the saveRule method.