Skip to main content

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:
  1. Script Tag - Add the Plausible script to your HTML template
  2. NPM Package - Install @plausible-analytics/tracker and initialize programmatically
The NPM package only works in browser environments. For SSR frameworks, ensure tracking code runs client-side only.

React

Create React App

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+)

Add to app/layout.tsx:

Pages Router (Next.js 12 and earlier)

Add to pages/_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

Add to public/index.html:

Vue Router

Track route changes:

Custom Events in Vue

Nuxt.js

Nuxt 3

Create a plugin at plugins/plausible.client.ts:
The .client suffix ensures it only runs on the client side.

Nuxt 2

Create plugins/plausible.client.js:
Register in nuxt.config.js:

Astro

Add the script to your base layout:
For client-side tracking with NPM:

Svelte / SvelteKit

SvelteKit

Add to src/routes/+layout.svelte:
Or use the script tag in src/app.html:

Angular

Add to src/index.html:
For NPM package with router tracking:

Gatsby

Install the plugin:
Configure in gatsby-config.js:

WordPress

For WordPress sites, use one of these methods:
  1. Official Plugin - Install the Plausible Analytics WordPress plugin from the plugin directory
  2. Manual Integration - Add the script tag to your theme’s header
  3. Theme Functions - Add via functions.php:

Static Site Generators

Jekyll

Add to _includes/head.html:

Hugo

Add to layouts/partials/head.html:

Eleventy (11ty)

Add to your base layout:

Single Page Applications (SPAs)

For SPAs, the tracker automatically detects URL changes via:
  • history.pushState
  • history.replaceState
  • Hash changes (with hashBasedRouting: true)
No additional configuration needed when using autoCapturePageviews: true (the default).

Hash-based Routing

For apps using hash-based routing (e.g., #/page):
Or with script tag:

Server-Side Rendering (SSR)

The Plausible tracker only works in browser environments. For SSR frameworks, ensure initialization happens client-side only.

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