Skip to content

Vanilla JS

Akayashuu edited this page Jun 12, 2026 · 1 revision

Vanilla JS

@vskstudio/takt-core is the framework-agnostic core every wrapper builds on. Fully typed, dependency-free, SSR-safe, it works in any bundler — and ships the CDN snippet too.

pnpm add @vskstudio/takt-core
# or: npm install @vskstudio/takt-core
# or: yarn add @vskstudio/takt-core
# or: bun add @vskstudio/takt-core

init() + track()

Call init() once at startup: it creates the shared instance, emits the initial pageview and wires up SPA navigation (pushState/replaceState/popstate/hashchange). Then emit events from anywhere with track().

import { init, track } from '@vskstudio/takt-core'

// Once, at app startup.
init({ domain: 'example.com', outbound: true })

// Everywhere else.
track('Signup', { props: { plan: 'pro' } })

init() is idempotent: a second call disposes the previous instance's listeners before creating a new one. The full option list lives in the configuration and the API reference.

Revenue

track()'s public type only accepts props. To attach revenue, go through the instance returned by init() — the amount is a string matching \d+(\.\d{1,2})?, the currency a 3-letter code:

const takt = init({ domain: 'example.com' })

takt.track('Purchase', {
  props: { plan: 'pro' },
  revenue: { amount: '29.00', currency: 'EUR' }
})

pageview() + consent

pageview() emits a pageview manually (rarely needed — navigation is tracked automatically). optOut() / optIn() drive per-visitor consent, persisted in localStorage (takt_ignore):

import { pageview, optOut, optIn } from '@vskstudio/takt-core'

optOut() // no event sent
optIn()  // resumes tracking
pageview()

See Privacy for the exact order of the guardrails.

CDN snippet

No bundler? The same package ships a ready-to-use script — a single tag in the <head>, init done from data-* attributes:

<script defer src="https://cdn.jsdelivr.net/npm/@vskstudio/takt-core/dist/takt.js" data-domain="example.com"></script>

On the snippet side, only window.takt(...) (the track function) is exposed — see Installation for the queue shim and API reference for the global.

Source on GitHub: github.com/vskstudio/takt-core · package on npm: @vskstudio/takt-core.


Source: github.com/vskstudio/takt-core · npm @vskstudio/takt-core

Takt — @vskstudio/takt-core


React · Vue · Svelte wrappers: see the docs site.

Clone this wiki locally