Track events using the Coveo app for Shopify
Track events using the Coveo app for Shopify
Coveo Analytics events are crucial for analyzing your storefront performance and powering Coveo Machine Learning (Coveo ML) models.
This article explains how the Coveo AI Search and Discovery app tracks commerce events. If you’re not using the app, see Custom implementations: Track events without the Coveo AI Search & Discovery app.
Types of events
There are four types of commerce events:
|
Note
Under the Coveo Event Protocol (EP), the Commerce API logs search events server-side automatically for you. |
How to track events
The Coveo Atomic and Headless libraries each log certain types of events. You’ll have to use a web pixel to track the other events.
The following table summarizes how commerce events are tracked:
Event | Atomic [1] | Headless |
---|---|---|
Click |
Logged automatically by Atomic |
Logged by Headless controllers [2] |
Cart |
Logged by Coveo web pixel |
|
Product view |
||
Purchase |
Logged by Coveo web pixel |
1. Be sure to initialize the web pixel as soon as possible.
-
To log click and product view events, see Displaying products.
-
To log cart events, see Managing the cart.
Coveo web pixel
The Coveo AI Search & Discovery app uses a web pixel to log certain commerce events based on your implementation approach.
The web pixel must be initialized before it can log events, so initialize it after you synchronize your Shopify product catalog with Coveo. The earlier you initialize the web pixel, the earlier it can start logging events to power your Coveo ML models.
Initialize the web pixel
-
Create a snippet named
initialize-analytics.liquid
and paste the following code:<!-- snippets/initialize-analytics.liquid --> <script type="module"> import {init, fetchAppProxyConfig} from 'https://static.cloud.coveo.com/shopify/v1/headless/commerce.esm.js'; const config = await fetchAppProxyConfig({
marketId: {{ localization.market.id | encode_url_component }}, }); init(config);
</script>
The Coveo Shopify app contains an App Proxy endpoint that returns an object containing the access token, organization ID and tracking ID, which are required to initialize the web pixel. The init
function initializes the web pixel with the configuration returned by the App Proxy endpoint (see @coveo/shopify). -
Include this snippet in your
theme.liquid
file, just before the closing</head>
tag:{% render 'initialize-analytics' %}
-
Verify your setup by loading a storefront page and confirming that cart events, product view events, and purchase events appear in your analytics.
Web pixel lifecycle
The lifecycle of the Coveo AI Search & Discovery app web pixel is as follows:
-
Deployed when you synchronize your Shopify product catalog with Coveo.
-
Updated to reflect the changes in your store when you manually synchronize your Shopify product catalog with Coveo.
-
Removed when you unlink your Coveo organization from your store.