Analytic Tracker is a TypeScript library for tracking and analyzing events.
- Track various types of events
- Automatically send events to a server
- Support for event categories, actions, labels, and values
- Configurable auto-send interval
Install using npm:
npm install git+https://github.com/louisxie0830/analytic-tracker.gitFirst, import the Tracker class and create an instance:
import Tracker from 'analytic-tracker';
// Create a Tracker instance
const tracker = new Tracker('/track');Use the trackEvent method to track an event:
tracker.trackEvent('video', 'play', 'promo_video', 'start');
tracker.trackEvent('button', 'click', 'signup_button', '1');You can pass a custom send interval (in milliseconds) when creating the Tracker instance:
const tracker = new Tracker('/track', 5000); // Send events every 5 secondsTo stop auto-sending events, use the stopFlushInterval method:
tracker.stopFlushInterval();trackEvent(category: string, action: string, label?: string, value?: string, metadata?: object): void
Track an event.
category: The event category (required)action: The event action (required)label: The event label (optional)value: The event value (optional)metadata: Additional data (optional)
Stop auto-sending events.
This project is licensed under the MIT License.