posthog-js
Version:
Posthog-js allows you to automatically capture usage and send events to PostHog.
41 lines (37 loc) • 1.87 kB
TypeScript
/** Subset of the web-vitals library's `ReportOpts` passed to metric observers. */
interface WebVitalsReportOpts {
reportAllChanges?: boolean;
reportSoftNavs?: boolean;
}
type WebVitalsMetricCallbacks = {
onLCP: (onReport: (metric: any) => void, opts?: WebVitalsReportOpts) => void;
onCLS: (onReport: (metric: any) => void, opts?: WebVitalsReportOpts) => void;
onFCP: (onReport: (metric: any) => void, opts?: WebVitalsReportOpts) => void;
onINP: (onReport: (metric: any) => void, opts?: WebVitalsReportOpts) => void;
};
type WebVitalsCallbacks = WebVitalsMetricCallbacks & {
withoutAttribution?: WebVitalsMetricCallbacks;
};
/**
* Web Vitals entrypoint (soft navigations, with attribution)
*
* Identical to web-vitals-with-attribution.ts, but built against pinned stable
* web-vitals 6.x so the observers understand the `reportSoftNavs` option.
* That option scopes each metric to the browser's Soft Navigation entries, so on a
* single-page app the measurement window restarts on client-side route changes
* instead of accumulating against the original hard-navigation timestamp.
*
* This is loaded lazily when soft navigations are enabled and at least one metric
* uses attribution. The bundle includes unattributed observers as well, allowing
* the SDK to keep CLS and FCP unattributed by default. The feature relies on Chrome's
* experimental Soft Navigation Detection API.
*
* Note: as with the non-soft-navs attribution build, attributed onCLS can cause memory
* issues in SPAs because it holds references to DOM elements that may be detached
* during navigation.
*
* @see web-vitals-soft-navs.ts for the lighter soft-navs bundle
* @see web-vitals-with-attribution.ts for the default attribution bundle
*/
declare const postHogWebVitalsCallbacks: WebVitalsCallbacks;
export { postHogWebVitalsCallbacks as default };