Use Relay to send events
Use Relay to send events
This is for:
DeveloperThis 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>",
trackingId: "<TRACKING_ID>",
url: "<COVEO_UA_ENDPOINT>",
});
Use an API key or search token to authenticate requests to Coveo. | |
Tracking ID | |
Event API endpoint |
Once an instance of the relay
object has been initalized, it can be used to send events using the emit
function.
Tracking ID
A Coveo organization can serve many ecommerce sites or applications, but all of the events in a user’s journey should be tied together for accurate data analytics and consistency.
tracking IDs segregate the data gathered from each of these sites or applications to ensure personalized and relevant output from your Coveo Machine Learning (Coveo ML) models, usable reporting, and clear merchandising actions. Each tracking ID points to a specific storefront, creating a way to bucket events that belong to different user journeys.
The tracking ID is defined when sending events to the Coveo Platform. Interfaces built with the Coveo Headless library or Atomic library automatically include the tracking ID in the events they send. While tracking ID values are specified when sending usage analytics events, each value that’s sent must be registered using a Property in your Coveo organization. See Properties for more information.
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 to be sent with each event:
-
barca_sports_us
-
barca_sports_ca
-
barca_parts_us
-
barca_parts_ca
Each of these tracking IDs is registered using a property in your Coveo organization to ensure that the data is correctly sent:
-
Barca Sports US
-
Barca Sports CA
-
Barca Parts US
-
Barca Parts CA
|
See What’s a 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 |
|
|
Where <ORG_ID>
is the unique identifier of your Coveo organization.