Find Coveo Event Names, EASY!

Continuing with the topic of Coveo for Sitecore, I wanted to share something that I recently discovered and that has helped me tremendously.

Coveo has many many various javascript events that you can hook on to in order to get your code to run at the perfect time. There are events related to the query lifecycle, to facet sliders, to breadcrumb updates, page initialization, etc. Prior to discovering what I'm about to share with you, I would scour Google, searching for documentation and frankly, the documentation and question/answer posts were very hard to navigate at times, making the process of finding the right event a very frustrating one.

I was never able to find a page with all of the events listed out along with descriptions as to when, specifically, each event would run. I would still appreciate such a page, but this "hack" that I'm about to share is the closest thing that I have found to having all of the events listed in one page.

Here's an example of a Coveo event handler for the "duringQuery" Coveo event:
//functional code goes here 

Since every single Coveo search page loads all of the Coveo javascript resources, you have the ability to explore this library of code through your browser's dev tools (Chrome being my favorite). That's pretty obvious, but the best part is that Coveo took ALL of the events and added them as properties that are easily accessible to you.

So here is what you do, go to a Coveo search page and let it load fully. Next, go to your console window and type "Coveo." Then, type the word "event". Chrome will run a search for all of the javascript objects with "event" in the name, which corresponds to all of the various Coveo event categories that exist. You will see there are MANY, likely more than you thought there were. Choose an category that corresponds to the type of event that you are looking for.

Then, type a "." and begin to explore the actual event properties within that event category. As you search through these properties, the ones that are events correspond to strings that you would normally type into your javascript event handler. Once you've picked your event, you can use that javascript dot notation as your event name in the event handler. For example, I could use "Coveo.QueryEvents.duringQuery" instead of the "duringQuery" string in the example shown above.

There's still the question of "When does this even go off?", but that can usually be figured out by analyzing the event name and with some experimenting as you're programming. At least now you know what events exist, which is a very good starting point.

So, if you're looking for a particular Coveo event, or are just curious what events exist, look no further than your dev tools console window!

Add comment