Tracking Script
The TideMeter tracking script (@tidemeter/tracker) is an ultra-lightweight analytics tracker that collects page view data without using cookies or collecting personal information.
Installation
Add the tracking script to your website’s HTML:
<script
defer
data-website-id="your-website-id"
src="https://your-tidemeter-instance.com/t.js"
></script>Place this just before the closing </body> tag for optimal performance.
How It Works
The tracker:
- Listens for page load and navigation events
- Collects anonymous page view data (URL, referrer, screen size, language)
- Sends a
POSTrequest to/api/collecton your TideMeter instance vianavigator.sendBeacon()(withfetch+keepaliveas fallback) - Never creates cookies, uses local storage, or fingerprints visitors
Data Collected
Each page view event includes:
| Field | Description | Example |
|---|---|---|
url | Current page URL | /blog/hello-world |
referrer | Referrer URL | https://google.com |
title | Page title | Hello World - My Blog |
screen | Screen dimensions | 1920x1080 |
language | Browser language | en-US |
websiteId | Your website identifier | abc123 |
What’s NOT Collected
- IP addresses (not sent by the tracker; hashed server-side then discarded)
- Cookies or local storage values
- User accounts or login info
- Form data or page content
- Mouse movements or keypresses
Configuration Attributes
| Attribute | Required | Default | Description |
|---|---|---|---|
data-website-id | Yes | — | Your website’s unique identifier |
data-host-url | No | Script origin | Override the API endpoint URL |
data-auto-track | No | true | Automatic page view tracking |
data-respect-dnt | No | true | Respect the browser Do-Not-Track setting |
data-domains | No | All domains | Comma-separated whitelist of allowed domains |
Example: Custom API Endpoint
<script
defer
data-website-id="your-website-id"
data-host-url="https://analytics.example.com"
src="https://your-tidemeter-instance.com/t.js"
></script>Example: Manual Tracking
<script
defer
data-website-id="your-website-id"
data-auto-track="false"
src="https://your-tidemeter-instance.com/t.js"
></script>
<script>
// Track a page view manually
tidemeter.track();
</script>Example: Custom Events
<script>
// Track a named event with properties
tidemeter.track("signup", { plan: "pro" });
// Identify a user (links anonymous visitor to known user ID)
tidemeter.identify("user-id-123");
</script>Example: Domain Restriction
<script
defer
data-website-id="your-website-id"
data-domains="example.com,app.example.com"
src="https://your-tidemeter-instance.com/t.js"
></script>Public API
The tracker exposes a global tidemeter object:
// Track a page view (auto-called on load if data-auto-track is true)
tidemeter.track();
// Track a named event with optional properties
tidemeter.track("signup", { plan: "pro" });
// Identify a user (links anonymous visitor to a known user ID)
tidemeter.identify("user-id-123");SPA Support
TideMeter automatically detects Single Page Application (SPA) navigation by listening to the browser’s popstate event and intercepting History.pushState/replaceState methods. No additional configuration needed for:
- Next.js
- React Router
- Vue Router
- SvelteKit
- Any framework using the History API
Bot Detection
The tracker checks navigator.webdriver to skip tracking for automated browsers. Server-side, additional bot detection filters requests based on User-Agent regex patterns matching common bots, crawlers, and spiders.
Performance
The tracker is designed to have zero impact on your site’s performance:
- Size: ~1.5KB gzipped (compared to ~45KB for Google Analytics)
- Loading: Uses
deferattribute, never blocks rendering - Network: Uses
navigator.sendBeacon()for non-blocking requests (falls back tofetchwithkeepalive) - CPU: Minimal JavaScript execution
- No external dependencies: Self-contained IIFE bundle
Content Security Policy (CSP)
If you use a Content Security Policy, add the following directives:
script-src 'self' https://your-tidemeter-instance.com;
connect-src 'self' https://your-tidemeter-instance.com;Building the Tracker
To build the tracker from source:
# From the monorepo root
pnpm --filter @tidemeter/tracker build
# Watch mode
pnpm --filter @tidemeter/tracker devThe build uses Rollup with TypeScript and Terser for minification, outputting a single dist/t.js file.
The built script will be available in the packages/tracker/dist/ directory.