Skip to content

Event Capture

The SDK exposes specific functions to capture user events. Each event function receives two objects:

  1. An object with the event information, which must be validated against the event’s specific schema.
  2. An additional object for metadata, which allows complementary data to be attached to the event.

These functions can be accessed through the track object. The general form is as follows:

analytics.track.eventName(eventProps, metadata)

The list of available events is described in the Event Schemas section. In addition, if you are using TypeScript, the type of the props each event receives is exported. The following general form is used:

import { EventNameProps, EventMetadata } from "@reservamos/browser-analytics"
const eventProps: EventNameProps = {}
// EventMetadata is a general type, you can use it for every event.
const metadata: EventMetadata = {}
analytics.track.eventName(eventProps, metadata)

The captured events are sent to Mixpanel for analysis.

Below, the search event is presented as an example of how to capture events with the SDK.

Search event example

import analytics, { SearchProps, EventMetadata } from "@reservamos/browser-analytics";
const searchProps: SearchProps = {
Departure: "2024-11-02",
"Departure Delta": 1,
Destination: "Querétaro",
Origin: "Ciudad de México",
"Origin Terminal": "Terminal Norte CDMX",
Passengers: 1,
Route: "Ciudad de México - Querétaro",
product: "web",
"Destination Terminal": "Terminal Queretaro"
};
const metadata: EventMetadata = {
campaign: "summer-sale",
salesforceID: "SF1234"
};
analytics.track.search(searchProps, metadata);

The second object received in the function ({ campaign: "summer-sale", salesforceID: "SF1234" }) is used to send additional metadata associated with the event.

This is only an example of how to capture a search event. The SDK can be extended to capture other custom events in the same way, such as purchases, registrations, etc.