import { CoreEvents, MetricEvents, PluginTable } from "../Metrics/types.cjs"; import { Metric } from "../Metrics/Metric.cjs"; import { InteractionEvents, ReliabilityEvents } from "./types.cjs"; //#region src/Interactions/InteractionMetric.d.ts /** * Interaction Metric * * An extension of the core `Metric` interface designed to track * the reliability of micro interactions * * ```typescript * const MyInteraction = new InteractionMetric("Sign Up"); * * async function onSubmitForm(username: string, password: string) { * myInteraction.start(); * try { * await fetch({ * url: "/signup", * data: JSON.stringify({ username, password }) * }); * await redirectToHome(); * myInteraction.succeed() * } catch(error) { * myInteraction.fail({ error }) * } * } * * myInteraction.on("start" | "stop" | "success" | "failure" | "reset", (metric) => { * // Adds an event listener to your InteractionMetric's events * await fetch({ * url: "/analytics-service", * data: JSON.stringify(metric) * }); * }) * ``` */ declare class InteractionMetric = Record, F extends Record = Record, P extends PluginTable = PluginTable> extends Metric & MetricEvents, P> { data?: S | F; failed: boolean; succeeded: boolean; static readonly events: { success: ReliabilityEvents.success; failure: ReliabilityEvents.failure; start: CoreEvents.start; stop: CoreEvents.stop; reset: CoreEvents.reset; }; /** * Succeed * * Records a stop time, a duration, and moves your metric's * status to `complete`. This method can also be supplied with * any arbitrary data to associate with the status of the * Metric. Emits the Metric's `success` and `stop` events */ succeed(data?: S, stopTime?: number): void; /** * Fail * * Records a stop time, a duration, and moves your metric's * status to `failed`. This method can also be supplied with * any arbitrary data to associate with the status of the Metric. * Emits the Metric's `failure` and `stop` events */ fail(data?: F, stopTime?: number): void; /** * Reset * * Resets the Metric's `startTime`, `stopTime`, `duration`, and `status` * back to their original state. Emits the Metric's `reset` event */ reset(): void; /** * Events * * Returns `CoreEvents` with extension for `success` and `failure` events */ get events(): { success: ReliabilityEvents.success; failure: ReliabilityEvents.failure; start: CoreEvents.start; stop: CoreEvents.stop; reset: CoreEvents.reset; }; } //#endregion export { InteractionMetric };