Every plugin exported from @spoar/sdk/plugins, with its signature and a usage example.
Import plugins from @spoar/sdk/plugins and pass them in plugins, or add one later with analytics.use(plugin).
import { createAnalytics } from "@spoar/sdk";
import { errors, speedInsights } from "@spoar/sdk/plugins";
export const analytics = createAnalytics({
project: "example.com",
key: "pk_...",
endpoint: "/_ra",
plugins: [speedInsights(), errors()],
});Each plugin has its own page with the events it sends and their props. The overview has one table of every plugin and explains how to write your own.
pageviews()pageviews(): PluginSends a pageview on load and on client-side navigation. It is on by default, so add it yourself only after setting pageviews: false. See Pageviews.
createAnalytics({ pageviews: false, plugins: [pageviews()] });speedInsights(options?)speedInsights(options?: { sampleRate?: number; random?: () => number; load?: () => Promise<Vitals> }): PluginSends web_vital for LCP, INP, CLS, FCP and TTFB. sampleRate is the share of page loads that measure, from 0 to 1, and defaults to 1. random and load exist for tests. See Speed insights.
createAnalytics({ plugins: [speedInsights({ sampleRate: 0.5 })] });errors()errors(): PluginSends error for uncaught errors and unhandled rejections, with the last 20 breadcrumbs. Messages, stacks and breadcrumbs are scrubbed of query strings, emails, tokens and long numbers. See Errors.
createAnalytics({ plugins: [errors()] });scrub(text)scrub(text: string): stringThe scrubbing function errors() uses, exported for your own error reporting.
scrub("GET /api/users?token=abc failed for ada@example.com"); // "GET /api/users[x] failed for [x]"scrollDepth()scrollDepth(): PluginSends scroll_depth with the deepest percentage reached on a page. See Scroll depth.
createAnalytics({ plugins: [scrollDepth()] });engagement()engagement(): PluginSends engagement with the milliseconds a page was visible. See Engagement.
createAnalytics({ plugins: [engagement()] });clicks()clicks(): PluginSends click for elements with data-spoar-click. See Clicks.
createAnalytics({ plugins: [clicks()] });autocapture()autocapture(options?: { kinds?: ("click" | "submit" | "change" | "rage")[] }): PluginSends autocapture for clicks and form submits, with change and rage as opt-in kinds. It never records input values. See Autocapture.
createAnalytics({ plugins: [autocapture({ kinds: ["click", "submit", "rage"] })] });outboundLinks()outboundLinks(): PluginSends outbound_click for links to other hosts and file_download for file links. See Outbound links.
createAnalytics({ plugins: [outboundLinks()] });forms()forms(): PluginSends form_submit with the form id and action path. See Forms.
createAnalytics({ plugins: [forms()] });ignoreSelf()ignoreSelf(): PluginSends nothing. Opening any page with ?spoar=ignore opts that browser out. See Ignore self.
createAnalytics({ plugins: [ignoreSelf()] });botSignals()botSignals(): PluginSends nothing of its own. It adds bot hint bits to every event. See Bot signals.
createAnalytics({ plugins: [botSignals()] });experiments(assigned)experiments(assigned: { [experiment: string]: string }): PluginSends experiment_exposure per experiment and adds an experiment:<id> prop to every event. See Experiments.
createAnalytics({ plugins: [experiments({ hero: "b" })] });notFound()notFound(): PluginSends not_found with the referrer on pages marked as not found. See Not found.
createAnalytics({ plugins: [notFound()] });groups<Groups>()groups<Map extends GroupMap = GroupMap>(): Groups<Map>Returns a plugin with set(type, id, traits?) and leave(type). Joined groups are added to every event as the group:<type> dimension. See Groups.
const workspace = groups<{ company: { plan: "free" | "pro" } }>();
createAnalytics({ plugins: [workspace] });
workspace.set("company", "acme", { plan: "pro" });speedProps(metric, sampleRate, connection)speedProps(metric: Measured, sampleRate: number, connection: string | null): PropsTurns a web-vitals metric into web_vital props. speedInsights() uses it, and it is exported for custom measuring.
SpeedOptions: the options of speedInsights.Groups<Map> and TraitsArgs<Map, Type>: the plugin type groups() returns and the typed arguments of its set.