Overview
The Plausible Analytics tracker is a lightweight JavaScript snippet that enables privacy-focused web analytics on your website. It automatically captures pageviews and can be configured to track custom events, file downloads, outbound links, and more.Installation Methods
There are two primary ways to integrate Plausible Analytics into your website:- Script Tag
- NPM Package
Add the Plausible script to your website’s Replace
<head> section:yourdomain.com with your actual domain name as configured in your Plausible account.The
defer attribute ensures the script loads asynchronously without blocking page rendering.Configuration Options
The tracker accepts various configuration options to customize its behavior:Script Attributes
When using the script tag method, configure behavior through data attributes:| Attribute | Description | Example |
|---|---|---|
data-domain | Required - Your site’s domain | data-domain="example.com" |
data-api | Custom API endpoint for proxying | data-api="https://analytics.example.com/api/event" |
data-exclude | Exclude specific pages from tracking | data-exclude="/admin/**" |
data-include | Only track specific pages | data-include="/blog/**" |
NPM Configuration
When using the NPM package, pass configuration options to theinit function:
Configuration Reference
Your site’s domain, as declared in your Plausible account settings.
The URL of the Plausible API endpoint. See the proxy guide for custom endpoints.
Whether to automatically capture pageviews. Set to
false for manual pageview tracking.Enable for single-page applications using hash-based routing (e.g.,
#/page). Read more in the hash-based routing docs.Automatically track clicks on outbound links.
Track file downloads. Can be
true or an object with custom file extensions:Automatically track form submissions.
Enable event capture on localhost for testing.
Log warnings when events are ignored.
Binds
track function to window.plausible for verification and debugging.Advanced Usage
Manual Initialization
For advanced control, you can manually initialize the tracker with custom settings:Proxying the Tracker
To avoid ad-blockers, proxy the Plausible script through your own domain:Excluding Pages
Exclude specific pages from tracking using wildcard patterns:*- matches any characters except forward slashes**- matches any characters including forward slashes
Verification
After installing the tracker, verify it’s working correctly:Check Browser Console
Open your browser’s developer console and look for any Plausible-related warnings or errors.
Verify window.plausible
Type
window.plausible in the console. If the tracker is loaded, you should see a function.Check Network Tab
Navigate your site and check the Network tab for requests to
/api/event with status code 202.Opt-out
Users can opt out of tracking by setting a localStorage flag:localStorage.plausible_ignore is set to "true".
More information: Excluding with localStorage
Next Steps
Custom Events
Track custom goals and user interactions
Custom Properties
Add metadata to your events
Events API
Server-side event tracking
Framework Guides
Integration guides for popular frameworks