Capture purchase events

This is for:

Developer
Important

The Event Protocol and Coveo Relay are currently in open beta. If you’re interested in using the Event Protocol and Relay library, reach out to your Customer Success Manager (CSM).

This article explains how to capture purchase events and send the information to Coveo Usage Analytics (Coveo UA).

When to capture a purchase event

This event comes after the capture cart event and is sent when the user completes a purchase. The event can contain multiple products. For example, if two products were purchased at once, both would be grouped in the same purchase event.

The following image shows the action taken by a visitor to checkout (or purchase) the items in their cart from the online sporting goods store Barca Sports, which contains product specific information.

Barca purchase event

How to capture a purchase event

Capturing a purchase event depends on your implementation approach.

Capture a purchase event using Headless

If you’re using the Headless library, you can capture a purchase event by using the Cart controller.

For more details, see Managing the cart.

Capture a purchase event using Relay

If you’re using Relay library directly, when a user purchases one or more products, you can run the following code to capture the event.

const relay = createRelay({...}); 1
relay.emit('ec.purchase', { 2
    currency: 'USD', 3
    "transaction": {
        "id": "TRX_1234",
        "revenue": 781.25
    },
    "products": [
        {
            "product": {
            "productId": "XY-1234",
            "name": "Bluewater Canoe",
            "price": 540
            },
            "quantity": 1
        },
    ],
});
1 Initialize a Relay instance.
2 Use the emit function to send an event with Relay, specifying the event name. In this example, the value is ec.purchase since it’s sending a purchase event.
3 Include the necessary event data, as outlined in the reference documentation, including an array of products that were purchased.

For a detailed description of the functions offered by the library, see the Relay documentation.

Note

When sending events with Relay, you don’t need to include the meta object mentioned in the Event Protocol Reference documentation, as it’s automatically added by the library.

Validating the purchase event

It’s important to verify that your event is valid and contains the correct payload. Relay seamlessly integrates with Coveo Explorer, which can be used for event validation.

For more details on using Coveo Explorer to validate events, see Validating events.