Plugins
Register Web Vitals, unhandled errors, or a custom plugin at init.
Add Web Vitals
pnpm add @hyperreal/landscape-plugins-web-vitals
import { init } from "@hyperreal/landscape-core";
import { webVitalsPlugin } from "@hyperreal/landscape-plugins-web-vitals";
init({
endpoint: "/api/events",
plugins: [webVitalsPlugin()],
});
webVitalsPlugin (packages/plugin-web-vitals/src/index.ts) records CLS, LCP, INP, FCP, and TTFB. Default event name: web_vital. Properties: name, value, rating, id.
webVitalsPlugin({ eventPrefix: "app_" }); // event name: app_web_vital
Capture unhandled errors
pnpm add @hyperreal/landscape-plugins-error-tracking
import { init } from "@hyperreal/landscape-core";
import { errorTrackingPlugin } from "@hyperreal/landscape-plugins-error-tracking";
init({
endpoint: "/api/events",
plugins: [errorTrackingPlugin()],
});
errorTrackingPlugin (packages/plugin-error-tracking/src/index.ts) listens to window error and unhandledrejection.
| Option | Default |
|---|---|
errorEventName |
"$error" |
rejectionEventName |
"$unhandled_rejection" |
$error properties: message, filename, lineno, colno, and stack when present. $unhandled_rejection properties: reason, and stack when the rejection is an Error.
Register after init
import { getClient } from "@hyperreal/landscape-core";
getClient()?.registerPlugin(webVitalsPlugin());
Custom events
Use track() from @hyperreal/landscape-core. See track.
Plugin contract
A plugin (packages/core/src/types.ts) may implement onInit, onBeforeTrack, onAfterTrack, onFlush, and onError. Returning null from onBeforeTrack drops the event.
Default circuit breaker: 3 consecutive plugin errors (pluginCircuitBreakerThreshold).