Angular
Angular has a dedicated wrapper: @vskstudio/takt-angular (provider, service, directive, badge/embed components, web component), built on the @vskstudio/takt-core core. Standalone APIs for Angular 17+.
pnpm add @vskstudio/takt-angular @vskstudio/takt-core The package is fully typed and SSR-safe: on the server provideTakt is inert and TaktService no-ops. It exposes two entry points:
@vskstudio/takt-angular—provideTakt(), the injectableTaktService, the[taktEvent]directive, theTaktBadgeComponent/TaktEmbedComponentcomponents and theTAKT_CONFIGtoken. It also re-exportscreateStats,badgeUrl,embedUrlandPublicApiErrorfrom the core.@vskstudio/takt-angular/element— the self-contained<takt-analytics>web component for plain HTML.
Setup with provideTakt()
Register Takt once at bootstrap with provideTakt. It boots only in the browser, fires the initial pageview, wires up the requested autocapture, and disposes everything when the app is destroyed.
import { bootstrapApplication } from '@angular/platform-browser'
import { provideTakt } from '@vskstudio/takt-angular'
import { AppComponent } from './app/app.component'
bootstrapApplication(AppComponent, {
providers: [
provideTakt({
// domain defaults to location.hostname, endpoint to https://taktlytics.com/api/event
outbound: true, // auto-track outbound links
files: true // auto-track downloads (or pass ['pdf', 'zip'])
// spa: true, respectDnt: true, excludeLocalhost: true (defaults)
})
]
}) TaktConfig options:
| Option | Type | Default | Role |
|---|---|---|---|
domain | string | location.hostname | Site identifier |
endpoint | string | https://taktlytics.com/api/event | Ingestion URL. Pass /api/event for a same-origin first-party proxy. |
scriptOrigin | string | — | First-party origin to derive the endpoint from ({origin}/api/event); endpoint wins over it |
outbound | boolean | false | Tracks outbound links |
files | boolean \| string[] | false | Tracks downloads (optional extension list) |
spa | boolean | true | Tracks client navigation (auto pageviews) |
track404 | boolean | false | Reports a 404 event on error pages ([data-takt-404] / <meta name="takt:404"> marker, or a 404 HTTP status). |
tagged | boolean | false | Custom events from [data-takt-event] elements |
respectDnt | boolean | true | Respects Do Not Track |
excludeLocalhost | boolean | true | Ignores localhost / private IPs |
enabled | boolean | true | Stops all sending when false (overrides everything else) |
sampleRate | number | 1 | Samples sent events (0–1) |
trackQuery | boolean | false | Keeps the query string as-is |
queryParams | string[] | — | Allowlist of query params to keep |
exclude | string[] | — | Path prefixes never tracked, e.g. ['/app', '/account'] (segment-bounded) |
scrubUrl | (url) => url | — | Custom URL scrubbing (config only) |
The semantics of these settings are detailed in Configuration.
TaktService
Inject TaktService anywhere to emit events imperatively. No method ever throws before init or on the server: track() and pageview() are then no-ops that emit a single console.warn, while optOut() / optIn() stay silent.
import { Component, inject } from '@angular/core'
import { TaktService } from '@vskstudio/takt-angular'
@Component({ /* ... */ })
export class CheckoutComponent {
private readonly takt = inject(TaktService)
buy() {
this.takt.track('Purchase', {
props: { plan: 'pro' },
revenue: { amount: '29.00', currency: 'EUR' }
})
}
// takt.pageview(), takt.optOut(), takt.optIn() and takt.instance are also available.
} [taktEvent] directive
For declarative click tracking, the taktEvent directive resolves the live instance at click time. Import it into a standalone component:
import { TaktEventDirective } from '@vskstudio/takt-angular'
@Component({
standalone: true,
imports: [TaktEventDirective],
template: `
<button
taktEvent="Signup"
[taktProps]="{ plan: 'pro' }"
[taktRevenue]="{ amount: '29.00', currency: 'EUR' }"
>
Sign up
</button>
`
})
export class SignupComponent {} Widgets
Two standalone components render a site’s public widgets: TaktBadgeComponent (<takt-badge>, the server-rendered SVG image) and TaktEmbedComponent (<takt-embed>, the mini dashboard in an iframe). Both require a public and verified site.
import { TaktBadgeComponent, TaktEmbedComponent } from '@vskstudio/takt-angular'
@Component({
standalone: true,
imports: [TaktBadgeComponent, TaktEmbedComponent],
template: `
<takt-badge domain="example.com" variant="d"></takt-badge>
<takt-embed domain="example.com" theme="dark"></takt-embed>
`
})
export class PublicStatsComponent {} domain is required. The badge also accepts variant, glyph, lang, host and alt; the embed accepts theme, lang, host, width, height and title. host points at the Takt address (defaults to https://taktlytics.com) — set it if you serve the widgets from a custom domain. To read the same figures in TypeScript, the package re-exports createStats, badgeUrl, embedUrl and PublicApiError from the core.
<takt-analytics> web component
For non-Angular pages (or a plain <script> tag), use the self-contained <takt-analytics> element. spa, respect-dnt and exclude-localhost are on by default: set them to "false" to disable. outbound, files, track404 and tagged are presence flags — the attribute alone turns them on.
import { defineTaktElement } from '@vskstudio/takt-angular/element'
defineTaktElement() // also auto-runs on import <takt-analytics domain="example.com" outbound files></takt-analytics> Recognised attributes:
| Attribute | Value | Role |
|---|---|---|
domain | string | Site identifier |
endpoint | string | Ingestion URL |
script-origin | string | First-party origin to derive the endpoint from |
spa | "false" to disable | Tracks client navigation (auto pageviews) |
respect-dnt | "false" to disable | Respects Do Not Track |
exclude-localhost | "false" to disable | Ignores localhost / private IPs |
enabled | "false" to disable | Stops all sending |
sample-rate | number | Samples sent events (0–1) |
track-query | presence | Keeps the query string as-is |
query-params | comma-separated list | Allowlist of query params to keep |
exclude | comma-separated list | Path prefixes never tracked |
outbound | presence | Tracks outbound links |
files | presence | Tracks downloads (no extension list here) |
track404 | presence | Reports a 404 event on error pages |
tagged | presence | Custom events from [data-takt-event] elements |
scrubUrl has no attribute form: go through provideTakt() for custom URL scrubbing.
Via CDN (bundles the core, no build step):
<script type="module" src="https://unpkg.com/@vskstudio/takt-angular"></script>
<takt-analytics></takt-analytics> provideTakt returns EnvironmentProviders: install it at bootstrap. TAKT_CONFIG is an InjectionToken holding the resolved config, if you need to read it elsewhere.