Using "Display Specific Info" Query Rules with InstantSearch.js. How do you display?

After setting up a consequence for “Displaying Specific Info” like in the documentation, I have no idea how to now use the userData object on the front-end.

How do you display the content?

{
    "condition": { /* [...] */ },
    "consequence": {
        "userData": {
            "message": "Summer Sales going on!",
            "blink": true,
            "url": "https:/www.my-awesome-shop.com/sales/summer"
        }
    }
}

Hi Giovanni,
The server should send the userData next to the hits, something like:

{ hits:[], userData: [] }

With InstantSearch.js, you might need to use connectors to access the server response object:

1 Like

Thanks Nicolas, I found the property :slight_smile:

Example of a custom widget where I’m using the property:

// custom wiget
search.addWidget({
	render: function(renderOptions) {
		var results = renderOptions.results;
		
		if(results.userData){
			 document.getElementById('customWidget').textContent = results.userData[0].userData.message;
		}
	}
});

Not a good final solution, but a start. Thanks!

2 Likes

Here’s an example on how to do it with connectHits