Core 1.0.0-rc.1
Analytics Plugin
The analytics plugin turns Journey observation events into normalized analytics envelopes.
It does not change transition behavior. It listens to the runtime lifecycle and forwards a stable event shape to your analytics client.
Install And Use
import { createJourneyMachine } from "@rxova/journey-core";
import { createAnalyticsPlugin } from "@rxova/journey-core/analytics";
const machine = createJourneyMachine(journey, {
plugins: [
createAnalyticsPlugin({
machineId: "checkout",
includeStepMeta: true,
track: (event) => analytics.track(event.name, event.payload)
})
]
});
What You Get
The plugin augments the machine with:
type JourneyAnalyticsMachineExtension = {
trackAnalyticsEvent: (
name: string,
payload?: Record<string, unknown>
) => JourneyAnalyticsTrackedEvent;
};
That lets you send custom analytics markers alongside the built-in lifecycle events.
Built-In Event Names
The plugin emits normalized events for:
journey_startedstep_viewedstep_exitedtransition_startedtransition_succeededtransition_failedjourney_completedjourney_terminatednavigation_previousnavigation_last_visited
Every event includes:
nametimestamppayload- optional
machineId
Depending on the event, payload fields may include:
- raw
context stepIdfromtoeventTypetransitionIddwellMsdurationMsstepMeta,fromStepMeta,toStepMeta
Options
track(event): analytics sinkmachineId: optional identifier included in every tracked eventincludeStepMeta: include step metadata in emitted payloadsonError(error, event): handles tracker failures without breaking the machine
payload.context always contains the raw machine context from the current snapshot.
Safety Behavior
If track(...) throws, the machine continues running.
- when
onErroris provided, the plugin forwards the failure there - otherwise Journey reports a development warning
Analytics failures never block transitions, navigation, or snapshot commits.