app-tracker
v3.1.1
Published
App Tracker for Web-Applications
Readme
App Tracker for Web & Node.js
App Tracker is a TypeScript/JavaScript library for logging and tracking events in web and Node.js applications. It supports batching, flexible configuration, and sending logs to a central endpoint.
Runtime support: Node.js 16 or newer and modern browsers with fetch/XHR, Promise, and WeakSet. Missing browser storage or sendBeacon support is handled with fallbacks.
Installation
npm i app-trackerRegistration & API Key
- Register at App Tracker and create an application to get your API key.
Quick Start
import { AppTracker, AppTrackerService } from "app-tracker";
const config = {
userAgentOrOs: typeof window !== 'undefined' ? navigator.userAgent : require('os'),
logInConsole: true,
sendLogsInDevelopment: true,
// more options below
};
const tracker: AppTrackerService = AppTracker.init("API_KEY", config);
tracker.debug("Debug message", { foo: "bar" });
tracker.error("An error occurred", errorObj);Configuration
| Property | Type | Default | Description | |-----------------------------|--------------|--------------------------------|-------------| | sendLogsInDevelopment | boolean | false | Send logs during development | | logInConsole | boolean | false | Also log to the console | | endpointUrl | string | https://app-tracker-api.azurewebsites.net/ | Target endpoint for logs | | maxSendTries | number | 5 | Max. send attempts on error | | retryDelayMs | number | 10000 | Delay between send attempts in milliseconds | | requestTimeoutMs | number | 10000 | Timeout for each HTTP attempt in milliseconds | | maxLogsCount | number | 10 | Batch size for sending logs | | logLevel | LogType[] | [LogType.error] | Which log types are sent | | sendLogsByTypesImmediately | LogType[] | [LogType.error, LogType.critical] | Types sent immediately | | userAgentOrOs | any | | Browser: navigator.userAgent, Node: require('os') |
LogType: debug, info, log, warn, error, critical
Architecture & Features
- Singleton Service: Always access via
AppTracker.init()orAppTracker.getService() - Batching: Logs are collected and sent after
maxLogsCountor immediately for critical errors - Explicit flush: Call and await
tracker.flush()before a controlled Node.js shutdown - Environment Awareness: Automatically adapts for browser/Node.js
- Browser correlation: Generates one in-memory correlation ID per page lifetime and includes it in every browser log batch. Node.js payloads do not include it. Use
tracker.getCorrelationId()to display the current ID when needed. - Secure Sending: API key required, retry mechanism on errors
- External Dependency: Uses
cross-fetchfor HTTP requests
Build & Development
- Build:
npm run build(TypeScript compile & copy tolib/) - Minify:
npm run terser(Terser minification of JS files) - Lint:
npm run lint(TSLint) - Format:
npm run format(Prettier)
FAQ
Where do I get my API key?
Register at https://www.app-tracker.cloud/ and create an application.
How can I suppress logs in development?
Set
sendLogsInDevelopment: falsein the configuration.
How do I send custom log types?
Use the
debug,info,warn,error,criticalmethods of the service object.
Further Information
- See
src/app-tracker.service.tsfor service logic - See
src/log.tsfor configuration and log types - See
.github/copilot-instructions.mdfor developer guidelines
