Analytics
The analytics plugin converts runtime observations into a stable event envelope and sends them to your analytics sink.
Install and use
Section titled “Install and use”import { createAnalyticsPlugin } from "@rxova/journey-core/plugins";
const machine = createGraphJourney(definition, { plugins: [ createAnalyticsPlugin({ track: (event) => analytics.track(event.name, event.payload), onError: (error, event) => report(error, event) }) ]});Lifecycle names include journey.transition, journey.navigationBlocked, journey.error, and
journey.<status>.
Event envelope
Section titled “Event envelope”type AnalyticsTrackedEvent = { name: string; timestamp: number; stepId: string | null; payload: Readonly<Record<string, unknown>>;};Sink exceptions are captured and never rethrown into the journey pipeline.
const api = machine.plugins.analytics;
api.trackAnalyticsEvent("coupon_applied", { code: "SAVE20" });api.getRecentEvents(); // last 100 successes and failuresapi.clearRecentEvents();now may be supplied as an injectable clock for tests.