Call init once at module scope of the client entry, before any component registers tools.
src/main.tsx
import { AgentStats } from '@agentstats/sdk'
AgentStats.init({ key: 'al_pub_…' })
Next.js 15.3+ runs instrumentation-client.ts in the browser before hydration.
instrumentation-client.ts
import { AgentStats } from '@agentstats/sdk'
AgentStats.init({ key: 'al_pub_…' })
On older versions, call init at module scope in a 'use client' component rendered by the root layout.
Call init before app.mount().
src/main.ts
import { createApp } from 'vue'
import { AgentStats } from '@agentstats/sdk'
import App from './App.vue'
AgentStats.init({ key: 'al_pub_…' })
createApp(App).mount('#app')
A client-only plugin runs before pages and components, so every tool registered later is tracked.
app/plugins/agentstats.client.ts
import { AgentStats } from '@agentstats/sdk'
export default defineNuxtPlugin(() => {
AgentStats.init({ key: 'al_pub_…' })
})
Call init in the client hooks file. In plain Svelte, put it at the top of src/main.ts.
src/hooks.client.ts
import { AgentStats } from '@agentstats/sdk'
AgentStats.init({ key: 'al_pub_…' })
No build step. Paste in <head>, before any script that registers tools.
index.html
<script src="https://agentstats.io/sdk/v1.js" data-key="al_pub_…" async></script>
Options are set with data- attributes. See Configuration.