Analytics
Analytics (Plausible or Google Analytics)
You can integrate either Plausible (privacy-friendly, no cookies) or Google Analytics (free, uses cookies).
- GA uses cookies → you’ll likely need the Cookie Consent Modal.
- Plausible doesn’t use cookies → no consent modal needed (hosted plan is paid; self-hosting is free but requires extra setup).
Option A — Plausible
Hosted Plausible
-
Sign up for a hosted Plausible account.
-
Create your site (add your domain). Use that domain (without
www
) asPLAUSIBLE_SITE_ID
:
PLAUSIBLE_SITE_ID=
- Add the script tag Plausible shows you to
app.head
inmain.wasp
:
// main.wasp
app OpenSaaS {
wasp: {
version: "^0.13.0"
},
title: "My SaaS App",
head: [
"",
],
//...
- API key: in Plausible, go to Settings → copy your API key and put it in
.env.server
asPLAUSIBLE_API_KEY
.
No Cookies
Plausible doesn’t use cookies, so you do not add it to the Cookie Consent Modal. Including the script in app.head
is enough.
Option B — Google Analytics
1) Switch stats provider in code (for Admin Dashboard)
Update src/analytics/stats.ts
to use the Google Analytics provider (replace the Plausible import with GA).
(Snippet shown exactly as in the original docs.)
//...
import { getDailyPageViews, getSources } from './providers/plausibleAnalytics';
import { getDailyPageViews, getSources } from './providers/googleAnalytics';
export const calculateDailyStats: DailyStatsJob = async (_args, context) => {
//...
}
2) Create a GA4 Property
Sign up for Google Analytics → in the Admin panel (bottom left) create a Property for your app.
From the Installation Instructions, choose Install manually and locate:
<your-google-analytics-id>
https://www.googletagmanager.com/gtag/js?id=<your-google-analytics-id>
3) Add GA ID to the client (works with the Cookie Consent Modal)
Put the ID into .env.client
:
REACT_APP_GOOGLE_ANALYTICS_ID= # e.g. G-123456
noscript note
Google Tag Manager may suggest adding a noscript
snippet after <body>
. Skip it. Users rarely browse with JS off, and Wasp requires JS anyway.
4) Enable GA Data API for server-side stats (Admin Dashboard)
To fetch analytics for your Admin Dashboard via API:
- Create a Google Cloud project (if you don’t have one).
- Enable the Google Analytics Data API (GA4) in the Cloud Console (Library).
- Create credentials → Service account key (role: Viewer).
- Download the JSON key (keep it secure; don’t commit it).
- In GA (not Cloud Console): Admin → Property → Property Access Management → add the service account email (
[email protected]
) with Viewer.
Encode private key (base64) and add to .env.server
:
Add client_email
and private_key
to .env.server
as GOOGLE_ANALYTICS_CLIENT_EMAIL
/ GOOGLE_ANALYTICS_PRIVATE_KEY
.
Important: because Google's key is PEM, base64-encode the private key with the command below, then paste the encoded value into GOOGLE_ANALYTICS_PRIVATE_KEY
.
echo -n "-----BEGIN PRIVATE KEY-----\nMI...A++eK\n-----END PRIVATE KEY-----" | base64
Put the base64 result under GOOGLE_ANALYTICS_PRIVATE_KEY
in .env.server
.
Add your Property ID (9 digits from GA: Admin → Property → Property Settings → Property Details) to .env.server
as GOOGLE_ANALYTICS_PROPERTY_ID
.
What’s next?
Metrics are in place. Time to set up auth.