SDK reference

Configuration reference

DatabuddyProvider, init(), the Vue <Databuddy> component and the Nuxt module take the same options. The script tag takes them as data-* attributes.

app/layout.tsx
import { DatabuddyProvider } from "@databuddy/sdk/react";

<DatabuddyProvider
  clientId={process.env.NEXT_PUBLIC_DATABUDDY_CLIENT_ID}
  autocapture={{ webVitals: true, errors: true }}
  skipPaths={["/admin/**"]}
  maskPaths={["/users/*"]}
/>;

The Node client and server flags have their own options, on Node SDK and Server flags.

Browser options

OptionTypeDefaultWhat it does
clientIdstringFrom envYour website's client ID. Read from the env variable below when omitted.
autocaptureboolean | objectSee belowWhat's recorded besides pageviews. true turns everything on, false everything off.
disabledbooleanfalseSends nothing; every call does nothing. On DatabuddyProvider, flags serve their defaults too.
debugbooleanfalseLogs what the tracker does and loads its debug build.
consent() => booleanRead before every event and request; nothing is sent while it returns false. See consent.
beforeSend(event) => booleanSees every event before it's sent. Edit it in place, or return false to drop it.
filter(event) => booleanReturn false to skip an automatic pageview or page exit.
skipPathsstring[]Glob patterns for paths never tracked, such as ["/admin/**"].
maskPathsstring[]Glob patterns whose dynamic segments are masked in every path and URL sent, such as ["/users/*"].
stripParamsstring[]Query parameters never sent, such as ["gclid", "fbclid"], including from attribution and track() properties.
linkDomainsstring[]Your other domains; links and forms leading there carry the visitor's IDs. See cross-domain.
cleanUrlboolean | (href) => voidtrueWhat happens to IDs another domain carried in. A function hands the clean address to your router.
batchingfalse | { size?, timeoutMs? }{ size: 10, timeoutMs: 5000 }Groups events into fewer requests. false sends each event as it happens.
retriesfalse | { max?, initialDelayMs? }{ max: 3, initialDelayMs: 500 }Retries failed requests.
sampleRatenumber1Share of sessions tracked, from 0 to 1. Each session is kept or skipped whole: its pageviews, page exits, engagement, Web Vitals and errors. track() events and outgoing links are always sent.
replayboolean | { maskText?, recordIframes?, scriptUrl?, integrity? }falseRecords session replays. Page text and typed input are masked.
ignoreBotDetectionbooleanfalseTracks visitors that look like bots.
anonymizeVisitorIdsboolean | "auto"trueAnonymizes visitor IDs before storage.
usePixelbooleanfalseSends events with an image request instead of fetch.
apiUrlstringhttps://basket.databuddy.ccWhere events are sent.
cdnUrlstringhttps://cdn.databuddy.ccWhere the pinned scripts load from. See your own domain.
scriptUrlstringPinned CDN URLA self-hosted tracker build. Wins over cdnUrl.
scriptIntegritystringSRI hash for scriptUrl. Without one, a custom URL isn't verified.
autocapture keyDefaultRecords
interactionstrueTime on page, scroll depth, rage clicks, dead clicks and abandoned forms
webVitalsfalseFCP, LCP, INP, CLS, TTFB, and FPS
errorsfalseUncaught errors and unhandled rejections
outgoingLinksfalseClicks on links to other websites
attributesfalseClicks on elements with data-track attributes
hashChangesfalseHash changes as pageviews
FrameworkClient ID env variable
Next.jsNEXT_PUBLIC_DATABUDDY_CLIENT_ID
NuxtNUXT_PUBLIC_DATABUDDY_CLIENT_ID
Vite and othersNone read in the browser; pass clientId={import.meta.env.VITE_DATABUDDY_CLIENT_ID}

skipPaths and maskPaths ignore case, decode escaped characters and collapse repeated slashes, so /Creations/abc with ["/creations/*"] is sent as /creations/*. Every URL sent drops its query and fragment; campaign parameters and ad click IDs are sent as event properties instead. To apply the same rules on your server, import maskPathname and matchesSkipPattern from @databuddy/sdk/node.

Configure the script tag

The script tag uses the older flat names. To load the tracker from npm instead, call init() with the options above.

AttributeDefaultWhat it does
data-client-idRequiredYour client ID
data-track-interactionstrueEngagement, rage and dead clicks; "false" turns it off
data-track-web-vitalsOffFCP, LCP, INP, CLS, TTFB, and FPS
data-track-errorsOffUncaught errors
data-track-outgoing-linksOffClicks on links to other websites
data-track-attributesOffClicks on data-track elements
data-track-hash-changesOffHash changes as pageviews
data-batch-size10Events per batch; 1 with data-batch-timeout="0" sends each event at once
data-batch-timeout5000Batch timeout in ms
data-sampling-rate1Share of sessions tracked; see sampleRate
data-skip-patternsJSON array of paths never tracked
data-mask-patternsJSON array of paths to mask
data-strip-paramsJSON array, or one name, of query parameters never sent
data-link-domainsJSON array, or one domain, of your other domains
data-clean-urltrue"false" leaves carried IDs in the address for your app
data-consent-cookiename=value. The cookie with any other value withholds consent; no cookie means tracking goes ahead. Set it on the replay script too when replay loads alone. See consent cookie.
data-disabledOffSends nothing

Functions can't go in attributes. Set consent, beforeSend, filter or a cleanUrl function on window.databuddyConfig before the script loads. consentCookie can go there too, in place of data-consent-cookie.

Load the pinned scripts from your own domain

If your Content Security Policy only allows scripts from your own origin, rewrite a path to the CDN and point cdnUrl at it. The SDK keeps loading the same pinned files and integrity hashes from there as you upgrade.

next.config.ts
import type { NextConfig } from "next";

const nextConfig: NextConfig = {
  async rewrites() {
    return [{ source: "/x/:path*", destination: "https://cdn.databuddy.cc/:path*" }];
  },
};

export default nextConfig;
app/layout.tsx
<DatabuddyProvider cdnUrl="/x" />

The rewrite must pass files through unchanged, or the integrity check blocks them. Events still go to apiUrl, so allow https://basket.databuddy.cc in connect-src, or proxy it too.

Filter or edit events before they're sent

beforeSend gets each event after paths are masked and URLs cleaned. event.type names its shape, and checking it narrows the type. Edit the event in place to send less, or return false to drop it. A hook that throws drops the event.

analytics.ts
import { init } from "@databuddy/sdk";

init({
  clientId: "your-client-id",
  beforeSend: (event) => {
    if (event.type === "error") delete event.stack;
    if (event.type === "outgoing_link") event.text = "";
    return true;
  },
});
event.typeEventMain fields
pagePageview or page exitname (screen_view or page_exit), path, title, referrer, profileId
eventtrack() or data-track eventname, path, properties, profileId
outgoing_linkClick on a link to another websitehref, text, path, title
errorUncaught error, rejection or captureException()message, stack, filename, lineno, colno, errorType, path
web_vitalCore Web Vital or FPSmetricName, metricValue, path
engagementTime and interactions on one pagetimeOnPage, activeTime, maxScrollDepth, click counts, path

Every event also has eventId, timestamp, anonymousId and sessionId. beforeSend, filter and maskPaths don't apply to session replays, which mask page text and typed input but keep the page's structure and class names. Leave replay off if your privacy policy forbids that.

How is this guide?