Using Relay to send events

This is for:

Developer
In this article

This article discusses how to use Relay to send events to Coveo Usage Analytics (Coveo UA).

Relay’s initialization options let you authenticate requests and direct them to the correct endpoint. Once set up, Relay actively manages various aspects of generic event logging, including enriching events with browser-specific details like user agent and local time. It also maintains a unique clientId for each browser and device combination.

The following section provides an overview of how to initialize Relay using NPM. For more detailed information on all the available functionality, see the Relay documentation.

Note

When sending events with Relay, you don’t need to send generic user information such as clientId or the timestamp as Relay automatically enriches the events with this information.

Initialize Relay

Note

You can also initialize Relay using a CDN. For more information, see the Using the Relay CDN.

To install the package, run the following command:

npm install @coveo/relay

After installing Relay, initialize the library using the createRelay method:

import { createRelay } from '@coveo/relay';

const relay = createRelay({
    token: "<COVEO_API_KEY_OR_SEARCH_TOKEN>", 1
    trackingId: "<TRACKING_ID>", 2
    url: "<COVEO_UA_ENDPOINT>", 3
});

Once an instance of the relay object has been initalized, it can be used to send events using the emit function.

User authentication

Replace <COVEO_API_KEY_OR_SEARCH_TOKEN> with a search token or an API key that grants the Push access level on the Analytics Data domain in the target organization. To use that same search token or API key for your search interface as a whole, also grant it the Allowed access level on the Execute Queries domain privilege.

Important

We strongly recommend that the access token enforces a searchHub value. See Defining the search hub in the authentication for more details.

Tracking ID

A Coveo organization can serve many ecommerce sites or applications. It’s important to segregate the data gathered from each of these sites or applications to ensure personalized and relevant outputs from your Coveo Machine Learning models, as well as usable reporting, and clear merchandising actions.

A tracking ID is a unique identifier used to differentiate and categorize Coveo Usage Analytics (Coveo UA) data by site or app. Similar to the organization ID which identifies the organization itself, the tracking ID points to a specific storefront, creating a way to bucket events belonging to different user journeys.

Note

The trackingId parameter can only contain letters, numbers, hyphens (-), underscores (_), and periods (.). For example, barca_sports_us-2.1.

In a user journey, all events should be tied together for consistency and for accurate data analytics. The tracking ID is therefore the common thread that connects all user actions within a single experience, facilitating the process of analyzing the data including user behavior and preferences.

Example

Your Coveo organization powers two brands: Barca sports and Barca parts. You operate in two different countries: United States and Canada.

Therefore, you have four different sites that require their own unique tracking ID:

  • barca_sports_us

  • barca_sports_ca

  • barca_parts_us

  • barca_parts_ca

Important

A single user journey can’t span multiple tracking IDs, and UA data is segregated by tracking ID. Therefore when you analyze metrics like views, clicks, or conversions, the Advanced Reports will show them for each tracking ID.

Additionally, the tracking ID shouldn’t be confused with other factors such as the site’s domain, locale, or catalog ID.

See Tracking ID for more information.

Event API endpoint

To log UA events for an organization, use the Coveo Event API endpoint to send Coveo UA events.

When initializing your library, replace <COVEO_UA_ENDPOINT> with the following:

Coveo Endpoint

Prod

https://<ORG_ID>.analytics.org.coveo.com/rest/organizations/<ORG_ID>/events/v1

HIPAA

https://<ORG_ID>.analytics.orghipaa.coveo.com/rest/organizations/<ORG_ID>/events/v1