Capture a product detail view event

This is for:

Developer

This article explains how to capture product detail view events and send the information to Coveo using the Coveo UA library.

When to send a product detail view event

Any time a product detail page (PDP) loads, a detail event must be sent to Coveo, together with the product information payload. Depending on your site’s design, detail events can be triggered from different pages.

The following image is taken from a product detail page view of the online sporting goods store Barca Sports, which contains product specific information.

Barca Product Detail View

Capture a product detail view event using Coveo UA library commands

When the user views the product details, you must run the following JavaScript code which contains Coveo UA library commands.

coveoua('ec:addProduct', {
    'id': 'SP00763_00002', 1
    'name': 'Modal Blue T-shirt',
    'category': 'clothing/t-shirts',
    'price': 42.00 2
});

coveoua('ec:setAction', 'detail'); 3
coveoua('send', 'event'); 4
1 Add product data payload
2 The currencyCode for the item’s price is set as a global field when initializing the Coveo UA library
3 Set the action type
4 Send the event

Add product data payload

The ec:addProduct command includes the relevant product data in the event you’re about to send. In this case the product dataset contains the product id, name, category, and price.

For more information, refer to the Coveo UA command list.

Product detail view dataset requirements

The following table lists the fields sent along with the event and the solutions that use these fields. Search, Listings, and Recs columns refer to whether the ML that powers those solutions needs those data points. The Reporting column is for general reporting purposes that encompasses all solutions. For more information on these fields, including other recommended and optional fields that can be sent, refer to the Product fields reference.

Field Priority Search Listings Recs Reporting

id

Required

check

check

check

check

name

Required

check

category

Required

check

check

check

check

price

Required

check

check

check

check

brand

Recommended

check

check

check

check

group1

Recommended

check

check

check

check

variant

Recommended

check

  1. Only needed when you need to setup ML to recommend at the group level.

Note

When you structure your items with product grouping, ensure that you add the group field to the product dataset in all sent events.

Using the recommended approach for product data, you would find, for example, "ec_item_group_id": "001" and "ec_product_id": "001-red" in the product dataset payload. The group can be represented by any string as long as it’s consistent. In other words, the same value (in this case, 001) is used on the different products in the group.

Set the action type

The ec:setAction command detail is used to send the product data payload.

Send the event

Finally, the send command sends an event with a given payload to the Coveo analytics endpoint.

Product detail view event validation

When the product detail view event is logged, use the developer tools for client-side request verification to inspect the event content to ensure everything done using the UI is captured as a set of consistent and coherent events. This must occur after the implementation is applied.

Inspect the product detail view event through the network browser and ensure it satisfies the following:

Barca PDP view network browser

1 The client ID (cid) is consistent with other events sent on the page.

2 The currency matches what’s being displayed to the visitor.

3 Confirm the event is a product detail view (pa).

4 Category values should use / to represent hierarchies and use | to represent multiple values.

Note

When logging events, the Coveo Platform expects the category values to be sent in a different format than when configuring category values for your products.

The format expected when uploading category values to your index is | for delimiting hierarchies and ; for delimiting multiple values. Whereas the format expected when logging events is / for delimiting hierarchies and | for delimiting multiple values.

When logging events, the Coveo Platform only requires the last level of the hierarchy to be sent.

For example, if you have a category defined in the index as Canoes & Kayaks ; Canoes & Kayaks|Kayaks ; Canoes & Kayaks|Kayaks|Tandem Kayaks, you only need to send Canoes & Kayaks/Kayaks/Tandem Kayaks in the event.

5 The product ID (pr1id) matches what’s set in the catalog entity. Similarly, if group and variant are being sent, they must also match.

Event field data mapping

The following table shows how the client-side fields are mapped to parameters in the analytics request sent to Coveo UA. You need to ensure this information is properly passed in the payload.

Field name Description Parameter

id

Identifier for the base product

pr1id

category

The product category

pr1ca

price

The price shown to the user (including discounts)

pr1pr

brand

The product brand

pr1br

name

The product name

pr1nm

group

The product group ID

pr1group

variant

The unique identifier of the variant selected

pr1va

For a complete list of parameters that can be sent in the event, see ​​Log Collect events.