--- title: Use Relay to send events slug: o1n90002 canonical_url: https://docs.coveo.com/en/o1n90002/ collection: coveo-for-commerce source_format: adoc --- # Use Relay to send events This article discusses how to use Relay to send [events](https://docs.coveo.com/en/260/) to [Coveo Analytics](https://docs.coveo.com/en/182/). 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](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/User-Agent) and local time. It also maintains a unique [clientId](https://docs.coveo.com/en/lbjf0131/) for each browser and device combination. The following section provides an overview of how to initialize Relay using [NPM](https://www.npmjs.com/). For more detailed information on all the available functionality, see the [Relay documentation](https://docs.coveo.com/en/relay/latest/). > **Note** > > When sending events with Relay, you don't need to send generic user information such as [clientId](https://docs.coveo.com/en/lbjf0131/) 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](https://docs.coveo.com/en/relay/latest/usage#cdn). To install the package, run the following command: ```bash npm install @coveo/relay ``` After installing Relay, initialize the library using the [`createRelay`](https://docs.coveo.com/en/relay/latest/reference#createrelay) method: ```js import { createRelay } from '@coveo/relay'; const relay = createRelay({ token: "", <1> trackingId: "", <2> url: "", <3> }); ``` <1> Use an API key or search token to [authenticate requests](https://docs.coveo.com/en/o8ld0051/) to Coveo. <2> [Tracking ID](#tracking-id) <3> [Event API endpoint](#event-api-endpoint) Once an instance of the `relay` object has been initialized, it can be used to send events using the `emit` function. ### Tracking ID A [Coveo organization](https://docs.coveo.com/en/185/) can serve many Coveo-powered commerce sites or applications, but all [Coveo Analytics events](https://docs.coveo.com/en/260/) in a user's journey should be tied together with a single tracking ID for accurate data analytics and consistency. [tracking IDs](https://docs.coveo.com/en/o8rb0139/) segregate the data gathered from each of these sites or applications to ensure personalized and relevant output from your [Coveo Machine Learning (Coveo ML)](https://docs.coveo.com/en/188/) [models](https://docs.coveo.com/en/1012/), usable [reporting](https://docs.coveo.com/en/266/), and clear merchandising actions. Each tracking ID points to a specific ecommerce [storefront](https://docs.coveo.com/en/p33g0410/), creating a way to distinguish between distinct sites and their respective user journeys. The tracking ID is defined when sending events to the [Coveo Platform](https://docs.coveo.com/en/186/). Interfaces built with the Coveo [Headless library](https://docs.coveo.com/en/lcdf0493/) or [Atomic library](https://docs.coveo.com/en/lcdf0264/) automatically include the tracking ID in the events they send. While tracking ID values are specified when sending [Coveo Analytics events](https://docs.coveo.com/en/260/), each value that's sent must be registered using a [**Property**](https://docs.coveo.com/en/o7vh0012/) in your [Coveo organization](https://docs.coveo.com/en/185/). To learn how to map your [storefront](https://docs.coveo.com/en/p33g0410/) architecture and use tracking IDs in Coveo for Commerce, refer to the [Coveo for Commerce setup guide](https://docs.coveo.com/en/o25a0034/). **Example** Your [Coveo organization](https://docs.coveo.com/en/185/) 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](https://docs.coveo.com/en/185/) to ensure that the data is correctly sent: * **Barca Sports US** * **Barca Sports CA** * **Barca Parts US** * **Barca Parts CA** > **Important** > > * The `trackingId` parameter can only contain lowercase letters, numbers, underscores (`_`), hyphens (`-`), and periods (`.`). > For example, the following tracking IDs would be valid: > > ** `barca_sports1_us` > > ** `barca-sports1-us` > > ** `barca.sports1.us` > > * A single user journey can't span multiple tracking IDs, and [Coveo Analytics data](https://docs.coveo.com/en/259/) is segregated by tracking ID. > When you analyze metrics like views, clicks, or conversions, the [Advanced Reports](https://docs.coveo.com/en/lbtf7260/) will show them for each tracking ID. > > * Tracking IDs shouldn't be confused with other factors such as the site's domain, [locale](https://docs.coveo.com/en/p4tf0351/), or catalog ID. See [What's a tracking ID?](https://docs.coveo.com/en/n8tg0567/) for more information. ### Event API endpoint To log [Coveo Analytics events](https://docs.coveo.com/en/260/) for an [organization](https://docs.coveo.com/en/185/), use the Coveo Event API endpoint to send events. When initializing your library, replace `` with the following: [%header,cols="2"] |=== |Coveo |Endpoint |Prod |`+https://.analytics.org.coveo.com/rest/organizations//events/v1+` |[HIPAA](https://docs.coveo.com/en/1853/) |`+https://.analytics.orghipaa.coveo.com/rest/organizations//events/v1+` |=== Where `` is the [unique identifier of your Coveo organization](https://docs.coveo.com/en/n1ce5273/).