Browser SDK

Configuration

Every option accepted by AgentStats.init() and the script tag.
AgentStats.init({
  key: 'al_pub_…',
  captureArgs: true,
  captureResults: false,
  redactKeys: ['email', 'phone'],
  metadata: { app: 'storefront', version: '1.2.3' },
})

Options

key
string required
The project's public key from Project settings → Setup, e.g. al_pub_….
captureArgs
boolean | (tool, args) => unknown
Default true: arguments are sent as-is, apart from redactKeys. false sends none. A function decides per call. See Privacy.
captureResults
boolean | (tool, result) => unknown
Default false. true stringifies results and cuts them at 2,000 characters. A function keeps what it returns, or nothing for undefined. See Privacy.
captureErrors
boolean | (error) => string | null
Default true: failed calls keep their message, cut at 1,000 characters. false keeps none. A function gets { tool, message, name, code, error } and returns the text to keep. See Privacy.
redactKeys
string[]
Default []. Values of matching keys become "[redacted]" at any depth. Case-insensitive substring match.
metadata
Record<string, unknown>
Static properties attached to every batch, such as app name or release version.
sessionTimeoutMs
number
Idle time before a new agent session starts. Default 1800000 (30 minutes).
flushIntervalMs
number
How often queued events are sent. Default 2000.
maxBatchSize
number
Maximum events per request. Default 25.
autoInstrument
boolean
Default true. Set to false to stop patching document.modelContext and wrap tools manually with AgentStats.wrap().
trackAgentBrowsers
boolean
Default true. Records AI agents browsing your pages in a real browser: Claude in Chrome taking and giving back control, Claude's built-in browser, automation (Playwright, Puppeteer) and visits your server integration verified. Only agents are recorded, page by page; nothing about people, and no visitor id. They show on Bot traffic under Agents in the browser.
trackPageviews
boolean
Default true. Records pageviews and track() goals for Visitors, without cookies or personal data. Ignored on localhost unless allowLocalhost is set.
hashRouting
boolean
Default false. Count the part after #/ as the page, for hash-based routers.
outboundLinks
boolean
Default false. Record clicks on links to other sites as the Outbound Link: Click goal.
fileDownloads
boolean | string[]
Default false. Record clicks on file links as the File Download goal: true for the usual types, or a list of extensions.
allowLocalhost
boolean
Default false. Record pageviews on localhost and other local addresses too.
agentSignals
boolean
Default true. With Visitors, send counts and timings of how each page was used (pointer moves, clicks, key presses), so agents driving a real browser are kept out of the human numbers. Never content, positions or elements. See Agents aren't people.
debug
boolean
Log initialisation and every batch to the console.
disabled
boolean
Do nothing. Handy for development and tests.

Script tag attributes

The script tag reads its options from data- attributes:

AttributeEquivalent
data-key="al_pub_…"key
data-capture-args="false"captureArgs: false
data-capture-errors="false"captureErrors: false
data-capture-results="true"captureResults: true
data-redact-keys="email,phone"redactKeys: ['email', 'phone']
data-pageviews="false"trackPageviews: false
data-hash-routinghashRouting: true
data-outbound-linksoutboundLinks: true
data-file-downloads or data-file-downloads="pdf,zip"fileDownloads
data-allow-localhostallowLocalhost: true
data-agent-signals="false"agentSignals: false
data-debug="true"debug: true
<script
  src="https://agentstats.io/sdk/v1.js"
  data-key="al_pub_…"
  data-redact-keys="email,phone"
  async
></script>