Log view events with Coveo UA

This is for:

Developer
In this article

You can use the Atomic library to assemble feature-rich Coveo-powered search interfaces that leverage Coveo Usage Analytics (Coveo UA). Atomic automatically logs search, click, and custom events for user interactions in your search interfaces. Search and click events provide the data to power most Coveo Machine Learning (Coveo ML) models, except for Content Recommendations (CR).

The output of a CR model depends on view events and the user’s action history. Atomic doesn’t log these events for you, so you should ensure that you’re sending view events for each page that you want to be able to recommend.

The Relay library, which is included in Atomic, lets you send EP view events to Coveo.

Tip
Leading practice

Start sending view events as soon as you can to gather data that your CR models can learn from.

Send view events with Relay

Use the relay.emit function on your Engine to send events to Coveo. The emit function accepts two parameters: the event type and the event payload.

The event type is the string name of the event, in this case itemView, and the event payload is a JSON object containing the data to be sent to Coveo.

const searchInterface = document.querySelector('atomic-search-interface');
await searchInterface.initialize({
    // ...
    analytics: {
        analyticsMode: "next",
        trackingId: "UA-123456789-1",
    }
});

searchInterface.engine.relay.emit('itemView', { 1
    itemMetadata: { 2
        uniqueFieldName: "permanentid",
        uniqueFieldValue: "kayak-paddle-01",
        author: "Barca Sports",
        url: "https://www.mydomain.com/l/products/kayak-paddle-01",
        title: "Bamboo Kayak Paddle"
    },
});
1 Pass in the name of the event as the first parameter of the emit function.
2 Pass in the event payload required for the itemview event. No need to send the meta object, as it’s automatically handled by Relay.

You can also use the Relay library directly to log view events on pages you want to be able to recommend but on which you don’t use Atomic. See the Relay library documentation.