Installation
Add the script tag
Add the following script before the closing Replace
</body> tag on every page:https://analytics.example.com with your Sparklytics server URL.Configuration Options
Customize the script behavior usingdata-* attributes:
Available Attributes
| Attribute | Values | Description |
|---|---|---|
data-website-id | Required | Your website ID from the dashboard |
data-api-host | URL | Override API endpoint (default: same origin) |
data-exclude-hash | "true" | Skip tracking hash-only URL changes |
data-respect-dnt | "false" | Ignore DNT/GPC signals (default: respects them) |
data-disabled | "true" | Disable tracking (useful for dev/staging) |
data-track-links | "true" / "outbound" | Track all links or external links only |
data-track-scroll-depth | "true" / "25,50,75,100" | Track scroll milestones |
data-track-forms | "true" | Track form submissions |
Tracking Custom Events
Use the globalwindow.sparklytics API to track custom events:
Visitor Identification
By default, Sparklytics generates a privacy-friendly visitor ID based on IP + user agent (rotated daily). You can override this with a stable identifier:- Identify a visitor
- Reset identification
Custom visitor IDs are stored in
localStorage under the key sparklytics_visitor_id and persist across sessions. Maximum length: 64 characters.UTM Parameter Tracking
The snippet automatically captures and persists UTM parameters from the URL:utm_sourceutm_mediumutm_campaignutm_termutm_content
sessionStorage and attached to all events in the same session.
SPA Support
The script automatically tracks navigation in single-page applications by:- Intercepting
history.pushStateandhistory.replaceState - Listening to
popstateevents - Sending a new pageview when the URL changes
Privacy Features
Do Not Track (DNT) Respect
By default, the script respects browser privacy signals:navigator.doNotTrack === '1'navigator.globalPrivacyControl === true
No Cookies
Sparklytics never sets cookies. All tracking is cookieless and does not require consent banners in most jurisdictions.Example: Complete Setup
Here’s a production-ready configuration with all features enabled:Next Steps
Next.js SDK
First-class integration for Next.js with automatic route tracking
Custom Integration
Build a custom integration using the API directly