About this project

tgram‑analytics JS SDK is a minimal client library for sending analytics events to a tgram‑analytics server. It runs in the browser using only native APIs, has no external dependencies and the built file is under two kilobytes when gzipped, making it fast to load. Key features include: - Zero dependencies and a tiny bundle size. - Full TypeScript definitions included, no separate @types package needed. - Privacy‑focused design: no cookies, no fingerprinting, optional respect for the browser Do Not Track setting, and session IDs stored only in sessionStorage. - Automatic pageview tracking for single‑page applications, with deduplication of consecutive identical URLs. Works with React Router, Vue Router, Next.js, Svelte Kit and any framework that uses the History API. - Manual event tracking via a simple track method, supporting scalar values and arrays of scalars for multi‑value properties. - Identify method to attach persistent user properties to all subsequent events. - Opt‑in/opt‑out control for user consent, with optional persistence handled by the application. - Optional batching of events to reduce network requests, configurable by maximum batch size and maximum wait time. - Configuration options for server URL, automatic pageview handling, DNT respect, context collection, and custom session IDs. - Simple installation via npm or a plain script tag for projects without a build step. - Comprehensive API: init, track, pageview, identify, opt, flush, reset. - Clear error handling for invalid event shapes and missing configuration. - MIT licensed and open for contributions. Typical usage involves importing the default export, initializing it once with the project API key and server URL, and then calling track wherever custom events need to be recorded. Pageviews are sent automatically unless disabled. The SDK also includes a global TGA object when loaded via a script tag, allowing immediate use without a module system. Privacy measures ensure that no persistent identifiers are stored beyond the current tab, and the server enforces a domain allowlist per project to prevent unauthorized data collection. For developers, the package provides build scripts, a test suite, TypeScript type checking, linting and formatting tools, and clear contribution guidelines. Overall, tgram‑analytics JS SDK offers a straightforward, low‑overhead way to collect event data while respecting user privacy and developer ergonomics.