Lightweight event tracking for JavaScript & TypeScript apps.
Easily track and sync user interactions anywhere in your app, with optional auto-syncing, user data collection, and unique event tracking.
Track events anywhere in your app.
Auto-sync tracked events whenever they occur.
Prevent duplicate event tracking with onlyTrackUniqueEvents.
Collect user data (OS, browser, location) if enabled.
Query previous events using trace.query().
Clear all stored events when needed.
npm install trace-everythingor
yarn add trace-everythingor
bun add trace-everythingimport { createTrace } from "trace-everything";
// Create a trace instance
const trace = createTrace({
onlyTrackUniqueEvents: true, // Prevent duplicate event tracking
collectUserData: true, // Capture OS, browser, location, etc.
});useEffect(() => {
trace
.track("page_visit", {
path: window.location.href,
})
.sync(async (event) => {
// Automatically send analytics when a user visits a page
await sendToAnalyticsService({
browser: event.browser,
location: event.location,
device: event.deviceType,
os: event.os,
path: event.properties.path,
});
});
}, []);<button
onClick={() => {
trace
.track("product_saved", {
productId: "123",
category: "electronics",
price: 299.99,
saveMethod: "manual",
})
.sync(async (event) => {
// Notify user when they save a product
await sendProductSaveNotification(event);
});
}}
>
{trace.query("product_saved") ? "Saved" : "Save"} Product
</button><button
onClick={() => {
trace.track("scroll_depth", { scroll: "75%" });
}}
>
Go to next page
</button>The .sync() function allows you to automatically send tracked events to a server, analytics tool, or any custom destination.
trace.track("user_signup", { plan: "pro" }).sync(async (event) => {
await sendToServer(event);
});If .sync() is not used, the event is still stored in localStorage and can be retrieved later using:
const lastSignup = trace.query("user_signup");
console.log(lastSignup);Setting onlyTrackUniqueEvents to true ensures that an event is only tracked once per session.
If a user saves the same product multiple times, it will not trigger additional events.
const trace = createTrace({ onlyTrackUniqueEvents: true });
trace.track("product_saved", { productId: "123" });You can retrieve stored events using trace.query():
const savedEvent = trace.query("product_saved");
console.log(savedEvent ? "User has saved a product" : "No saved products yet");To reset the event log:
trace.clear();
console.log("All events cleared!");