About this project

The @vskstudio/takt-angular package offers a native Angular integration for the Takt analytics platform, focusing on privacy‑first data collection. It is designed for Angular 17 and later, and can be added to a project with a single package manager command. Installation Run: pnpm add @vskstudio/takt-angular @vskstudio/takt-core Bootstrap Integration In the root bootstrap call, register the provider using provideTakt. The provider initializes the core analytics library only in the browser, sends an initial pageview, activates optional auto‑capture features (outbound link clicks, file downloads, SPA navigation, etc.) and cleans up when the Angular app is destroyed. On the server side the provider is inert, making the library safe for server‑side rendering. Injectable Service TaktService can be injected anywhere in the application. It exposes methods such as track(eventName, options), pageview(), optOut() and optIn(). All methods are no‑ops before the library is initialized or when running on the server, ensuring they never throw. Declarative Click Tracking The TaktEventDirective allows developers to attach tracking to any clickable element via the taktEvent attribute, with optional taktProps and taktRevenue inputs. The directive resolves the live analytics instance at click time, keeping the markup clean. UI Widgets Two standalone components are provided: - TaktBadgeComponent renders a server‑generated SVG badge for a given domain. - TaktEmbedComponent renders a sandboxed iframe that displays public analytics dashboards. Both components are usable in any Angular template and support inputs for domain, theme, size, language and visual variant. Public Stats API The createStats helper creates a client for the public Takt API. It offers async methods summary, timeseries, realtime and breakdown, allowing developers to fetch aggregated analytics data programmatically. Framework‑Agnostic Custom Element For non‑Angular pages a self‑contained custom element named takt-analytics is exported. After calling defineTaktElement (or importing the module which auto‑runs the registration), the element can be placed in plain HTML and will automatically respect privacy settings such as outbound link tracking and file download tracking. A CDN bundle is also available for quick inclusion without a build step. Configuration Options TaktConfig supports a rich set of options, including domain, endpoint, outbound link tracking, file download tracking, SPA navigation, Do Not Track respect, localhost exclusion, sample rate, query string handling, path exclusions, URL scrubbing, and tagged element tracking. Defaults are sensible for most sites, and the configuration can be supplied to provideTakt at bootstrap. License The library is released under the MIT license.