Relay Reference
Relay Reference
|
|
Relay v1 has been deprecated. If you’re implementing Relay, refer to the documentation for the latest version. All new implementations are strongly encouraged to use Event Protocol where practical. If you’re currently using v1 of Relay, refer to the upgrade guide to update to the latest version. |
|
|
The Event Protocol and Coveo Relay library are generally available for Commerce. However, they’re in closed beta for Coveo for Service, Website, and Workplace implementations. If you’re interested in using the Event Protocol and Relay library for these implementations, contact your customer success manager (CSM). |
Interfaces
Environment
Platform abstraction interface used by Relay to operate in different execution environments, such as browsers, or custom contexts.
Functions
-
generateUUID
Generates a UUID string.
-
Returns
string
-
-
getLocation
Returns the first 1024 characters of the current location (URL) context, or
nullif not available.-
Returns
nil|string
-
-
getReferrer
Returns the first 1024 characters of the referring URL, or
nullif it is not available.-
Returns
nil|string
-
-
getUserAgent
Returns the current user agent string, or
nullif not available.-
Returns
nil|string
-
-
send
Sends an analytics event to the Event API.
-
Parameters
-
url:
stringAPI endpoint where the event should be sent.
-
token:
stringAPI token used for authorization.
-
event:
RelayEventEvent payload to send.
-
-
Returns
void
-
Properties
-
runtime:
browser|null|customCurrent runtime context for Relay. It has three possible values.
"browser"indicates a standard web environment."null"disables all side effects (for example, for unit testing)."custom"represents a user-supplied environment. -
storage:
StorageStorage implementation used to persist data. Should implement the standard
Storageinterface.
EventConfig
The EventConfig object provides additional information for the configuration associated with the event.
Properties
-
trackingId:
nil|stringThe unique identifier of a web property. See What’s a tracking ID?.
Meta
The Meta object provides a structured representation of metadata associated with an emitted event.
This object is auto-populated by Relay.
Properties
-
clientId:
stringPersistent unique identifier of a device.
-
config:
EventConfigConfiguration associated with the event.
-
location:
nil|stringBrowser Location’s
hrefproperty if set. -
referrer:
nil|stringBrowser Document’s referrer property if set.
-
source:
string[]Names and versions of the client side libraries which built and emitted this event.
-
ts:
numberTimestamp when the event was emitted.
-
type:
stringEvent’s type that was emitted.
-
userAgent:
nil|stringBrowser Navigator’s user agent property if set.
Relay
Relay instance. This object provides a comprehensive set of variables and methods for interacting with the Event API.
Functions
-
emit
Sends an event to the Event API.
-
Parameters
-
type:
stringEvent’s type to be emitted.
-
payload: Record<
string|any>Payload to include within the event.
-
-
Returns
void
-
-
getMeta
Gets the client-side generated meta object.
-
Parameters
-
type:
stringEvent’s type that will be included in the meta object.
-
-
Returns
Meta
-
-
off
Detach callbacks from events. If only the "type" parameter is set, all callbacks for the specified type will be removed.
-
Parameters
-
type:
stringEvent’s type.
-
callback:
EventCallbackCallback that should be removed.
-
-
Returns
void
-
-
on
Attaches an event callback to either all event types or a specific one. The callback set will be called when an event with the specified type is emitted. It’s not possible to modify the payload of the event sent to Coveo using this listener. Setting type as "*" will trigger the callback for all event types. Returns the "off" function to detach the event callback.
-
Parameters
-
type:
stringEvent’s type.
-
callback:
EventCallbackCallback that should be called when the event is emitted.
-
-
Returns
Off
-
-
updateConfig
Updates Relay’s configuration after its initialization.
-
Parameters
-
config: Partial<
RelayConfig>Configuration that should be updated.
-
-
Returns
void
-
Properties
-
version:
stringCurrent version of the Relay library.
RelayConfig
The RelayConfig object defines the configuration options for initializing a Relay instance.
Properties
-
environment:
CustomEnvironmentOptionally allows you to specify a custom environment for Relay, allowing integrations to override the default behavior. This is useful when Relay runs in unsupported or specialized contexts that require custom handling.
-
mode:
emit|disabledDefines the library mode. The available modes are
emitanddisabled.emitsends analytics events to Coveo to be stored.disabledprevents the emission of events and does not trigger callbacks.Default:
emit -
source:
string[]Optionally allows a Relay integration to specify the names of software packages Relay is being called from. These names will be transmitted with each event, along with Relay’s own version. The recommendation is to specify them using a 'softwarename@softwareversion' string.
-
token:
stringToken to authorize the access to the Event API endpoint.
-
trackingId:
nil|stringThe unique identifier of a web property. See What’s a tracking ID?. Can be null, in that case events are assigned to an internal default tracking ID.
-
url:
stringEndpoint defined to communicate with the Event API.
RelayEvent
Defines the structure of a RelayEvent, extending the RelayPayload.
Extends RelayPayload
Properties
-
meta: Readonly<
Meta>Read-only
metaproperty of Meta type.
Storage
Interface that defines a minimal key-value storage mechanism used by Relay.
Functions
-
getItem
Retrieves the stored string value associated with the specified key. Returns
nullif the key does not exist or has no value.-
Parameters
-
key:
stringKey corresponding to the desired value.
-
-
Returns
nil|string
-
-
removeItem
Removes the value associated with the specified key from storage. If the key does not exist, no action is taken.
-
Parameters
-
key:
stringKey to remove.
-
-
Returns
void
-
-
setItem
Stores a string value under the specified key. Overwrites any existing value.
-
Parameters
-
key:
stringKey under which the value should be stored.
-
data:
stringString data to store.
-
-
Returns
void
-
Functions
createRelay
Initializes the Relay library object.
-
Parameters
-
initialConfig:
RelayConfig
-
-
Returns
Relay
Type Aliases
CustomEnvironment
Partial override of the Environment interface, used to customize Relay’s behavior
in non-standard browser runtimes.
This type allows selective replacement of key environment functions without requiring
full control over all Environment responsibilities.
-
Type Pick<
Environment|generateUUID|getLocation|getReferrer|getUserAgent|send> &Storage
EventCallback
Callback to perform an action when a specified event is emitted.
-
Parameters
-
event:
RelayEventThe Relay event payload that triggered the callback.
-
-
Returns
void-
Type
-
Off
Function that detaches an event callback.
-
Returns
void-
Type
-
RelayPayload
Represents the payload sent with Relay. It is a object with string keys and values of any type.
-
Type Record<
string|any>