How to access the Algolia Helper in Magento 2

I would like to interact with the algolia helper class on certain magento 2 pages but can’t find many examples. Currently I have the below code but the foo function never fires on the “result” helper event. Do I need to access the original helper instance and if so how do I do that? Or is there something wrong in the code?

    requirejs(['jquery', 'algoliaBundle'], function ($, algoliaBundle) {
    var algoliaConfig = window.algoliaConfig;

    $(function () {
        var client = algoliaBundle.algoliasearch(algoliaConfig.applicationId, algoliaConfig.apiKey);
        var helper = algoliaBundle.algoliasearchHelper(window.algolia, algoliaConfig.indexName);

        helper.on('result', function(content) {
            foo(content);
        });

        function foo(content) {
            alert(JSON.stringify(content, null, 2));
        }
    });
});

Hi @supplies,

Welcome to the Algolia Community!

You can use one of our events listed here.

Here is an example.

Let us know how this works for you!
Best regards,

Thanks for the response Cindy. But I would like access to the “results” event for the main Algolia Helper object which fires after new results are returned. In the code in my original post I forgot to mention that if I add helper.search() on the last line then that results event will fire, but not if I make a new search or filter selection on the page. That’s why I was wondering if the helper in my code is not the same helper instance of the filters/search and therefore not attached to that results event. Does that make sense?

How have others added a custom results event in magento 2?