@anested/analytics
v1.2.0
Published
Lightweight analytics & SEO intelligence tracking for websites — pageviews, sessions, scroll depth, click tracking, SEO audits, Web Vitals, social referrer detection, device intelligence, lead-capture forms, and optional visitor consent popup
Maintainers
Readme
@anested/analytics
Lightweight analytics & SEO intelligence library — under 8KB. Drop one script tag and get:
- Auto pageview & session tracking
- Scroll depth, click intelligence (rage clicks, dead clicks)
- Social referrer detection (Google, Facebook, Instagram, Twitter/X, LinkedIn, YouTube, TikTok, Reddit, and 20+ more)
- Extended device detection (brand, model, OS, browser)
- SEO audits (titles, meta, OG tags, structured data, heading structure)
- Web Vitals (LCP, FID, CLS)
- Optional visitor consent popup (collects name + location permission)
- SPA / Next.js / React Router support
Quick Start
Script tag (simplest)
<script
defer
src="https://api.analytics.anested.com/a.js"
data-key="YOUR_TRACKING_KEY"
data-host="https://api.analytics.anested.com"
></script>NPM (React / Next.js)
npm install @anested/analyticsimport { init } from "@anested/analytics";
init({
key: "YOUR_TRACKING_KEY",
host: "https://api.analytics.anested.com",
});Configuration
All options are set via data-* attributes on the script tag, or as properties passed to init().
| Attribute / Option | Default | Description |
|--------------------|---------|-------------|
| data-key | — | Required. Your tracking key from the Anested Analytics dashboard |
| data-host | https://api.analytics.anested.com | Analytics server URL |
| data-clicks | true | Track click events (rage clicks, dead clicks, outbound links) |
| data-scroll | true | Track scroll depth |
| data-seo | true | Run client-side SEO audit on every page |
| data-performance | true | Measure Web Vitals (LCP, FID, CLS) |
| data-consent | false | Show visitor consent popup (name + optional location) |
| data-debug | false | Log all events to the browser console |
Consent Popup (data-consent="true")
When data-consent="true", on the visitor's first visit a compact bottom sheet appears:
- Asks for the visitor's name (optional free-text field)
- A pre-ticked checkbox: "Allow location access (for analytics only, never shared)"
- A Continue button
On submit:
- The name is stored in
localStorageand attached to every event asvisitor_name - If location was allowed, the browser requests geolocation permission and attaches coordinates to the pageview
- The popup is never shown again on the same device (stored in
localStorage._ac)
<script
defer
src="https://api.analytics.anested.com/a.js"
data-key="YOUR_KEY"
data-host="https://api.analytics.anested.com"
data-consent="true"
></script>Social Referrer Detection
The library automatically detects which platform sent the visitor:
google · facebook · instagram · twitter · linkedin · youtube · reddit · tiktok · pinterest · whatsapp · telegram · snapchat · discord · github · medium · substack · duckduckgo · bing · yahoo · producthunt · hackernews · slack · direct · referral
If UTM source is present (utm_source=google), it takes priority.
Device Detection
Each pageview includes:
device—"mobile"|"tablet"|"desktop"device_brand— e.g."Apple","Samsung","Google","Xiaomi"…device_model— e.g."iPhone","Galaxy S24","Pixel 8"…os/os_version—"iOS 17.4","Android 14","Windows 10/11"…browser/browser_version—"Chrome 125","Safari 17"…
Public API
// Custom event
window.analytica.track("button_clicked", { label: "Get Started", page: "/" });
// Set visitor name programmatically (if not using the consent popup)
window.analytica.identify("Jane Doe");
// Request browser location after user interaction
window.analytica.requestLocation((granted) => {
console.log("Location granted:", granted);
});
// Get the anonymous visitor ID for the current device
const vid = window.analytica.getVisitorId();
// Opt out of all tracking
window.analytica.optOut();SPA Support
Works automatically with React Router, Next.js App Router, Vue Router, etc.
The library intercepts history.pushState / replaceState and re-fires pageviews on navigation.
Subdomain Support
Each subdomain is tracked as a separate site. Register each one independently:
anested.com → one site
blog.anested.com → separate site (own analytics stream)
shop.anested.com → separate site (own analytics stream)License
MIT © Anested
