Overview
Plausible Analytics can be integrated with any modern web framework. This guide covers common integration patterns for popular frameworks and provides framework-specific examples.General Approach
All frameworks support one or both of these integration methods:- Script Tag - Add the Plausible script to your HTML template
- NPM Package - Install
@plausible-analytics/trackerand initialize programmatically
The NPM package only works in browser environments. For SSR frameworks, ensure tracking code runs client-side only.
React
Create React App
- Script Tag
- NPM Package
Add the script to
public/index.html:React Router
For single-page applications with React Router, pageviews are automatically tracked when using the NPM package. For manual pageview tracking:Custom Events in React
Next.js
App Router (Next.js 13+)
- Script Component
- NPM Package
Add to
app/layout.tsx:Pages Router (Next.js 12 and earlier)
Add topages/_app.js:
Tracking Route Changes
Next.js App Router automatically triggers pageviews on route changes. For Pages Router with manual tracking:Vue.js
Vue 3
- Script Tag
- NPM Package
Add to
public/index.html:Vue Router
Track route changes:Custom Events in Vue
Nuxt.js
Nuxt 3
Create a plugin atplugins/plausible.client.ts:
.client suffix ensures it only runs on the client side.
Nuxt 2
Createplugins/plausible.client.js:
nuxt.config.js:
Astro
Add the script to your base layout:Svelte / SvelteKit
SvelteKit
Add tosrc/routes/+layout.svelte:
src/app.html:
Angular
Add tosrc/index.html:
Gatsby
Install the plugin:gatsby-config.js:
WordPress
For WordPress sites, use one of these methods:- Official Plugin - Install the Plausible Analytics WordPress plugin from the plugin directory
- Manual Integration - Add the script tag to your theme’s header
- Theme Functions - Add via
functions.php:
Static Site Generators
Jekyll
Add to_includes/head.html:
Hugo
Add tolayouts/partials/head.html:
Eleventy (11ty)
Add to your base layout:Single Page Applications (SPAs)
For SPAs, the tracker automatically detects URL changes via:history.pushStatehistory.replaceState- Hash changes (with
hashBasedRouting: true)
autoCapturePageviews: true (the default).
Hash-based Routing
For apps using hash-based routing (e.g.,#/page):
Server-Side Rendering (SSR)
Detecting Client-Side
Testing
When testing your integration:1
Enable Localhost Tracking
2
Check Browser Console
Open DevTools and look for Plausible-related messages.
3
Verify Network Requests
Check the Network tab for POST requests to
/api/event with status 202.4
Use Real-time Dashboard
Visit your Plausible dashboard to see live visitor count.
Next Steps
Tracker Script
Full tracker configuration reference
Custom Events
Track custom goals and conversions
Custom Properties
Add metadata to your events
Events API
Server-side event tracking