my-analytics
v1.0.0
Published
A minimal Mixpanel-style tracking SDK with batching, retries, session tracking, and auto page-view capture.
Maintainers
Readme
my-analytics
A minimal Mixpanel-style tracking SDK — batching, retries, session tracking, and auto page-view capture. One source, two install channels.
Install
npm (React / Vue / Next.js)
npm install my-analyticsimport analytics from "my-analytics";
analytics.init("YOUR_PROJECT_TOKEN");
analytics.track("Signed Up", { plan: "pro" });
analytics.identify("user_123");
analytics.reset(); // on logoutCDN (<script> tag)
<script src="https://cdn.yoursite.com/v1/analytics.min.js"></script>
<script>
analytics.init("YOUR_PROJECT_TOKEN");
analytics.track("Signed Up", { plan: "pro" });
</script>API
| Method | Description |
| --- | --- |
| init(token, options?) | Start the SDK. options.autoTrackPageviews (default true) fires a Page Viewed event on load. |
| track(event, properties?) | Queue an event. Flushed every 5s or once 20 events accumulate. |
| identify(userId) | Link the anonymous device to a known user. |
| reset() | Clear identity on logout; start a fresh anonymous device id. |
| flush() | Force-send queued events now. |
Develop
npm install # install esbuild
npm run build # -> dist/analytics.esm.js, dist/analytics.min.js, dist/index.d.ts
npm pack # inspect the exact tarball npm would publishOpen test/index.html in a browser after building to fire test events and watch them hit the network.
Publish
npm login
npm publishprepublishOnly rebuilds dist/ automatically before every publish.
