React + Plausible
Lightweight, cookie-free analytics with Plausible; it counts client-side navigations itself. This page shows exactly what pickstack adds to a React project for Plausible: the packages, the new files and the changes to existing ones. Every combination is installed, built, linted and tested in CI.
$ npm create pickstack@latest my-app -- --framework react --modules plausible --yesCustomize in the configurator
Packages it adds
| Package | Version | Type |
|---|---|---|
@plausible-analytics/tracker | ^0.4.7 | runtime |
New files
VITE_PLAUSIBLE_DOMAIN=
import { init } from "@plausible-analytics/tracker";
/** Plausible; off until the site's domain is set (see .env.example). Call it once. */
export function initAnalytics() {
const domain = import.meta.env.VITE_PLAUSIBLE_DOMAIN;
if (!domain) return;
init({ domain });
}
Changes to existing files
import { StrictMode } from "react"; import { createRoot } from "react-dom/client"; import App from "./App";+import { initAnalytics } from "./analytics"; import "./index.css"; +initAnalytics();+ createRoot(document.getElementById("root")!).render( <StrictMode> <App />⋯ 3 unchanged lines
Project files
.env.example.gitignoreREADME.mdindex.htmlpackage.jsonsrc/App.tsxsrc/analytics.tssrc/components/Counter.tsxsrc/index.csssrc/main.tsxtsconfig.jsonvite.config.ts