Analytics

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

  1. Sign up for a hosted Plausible account.

  2. Create your site (add your domain). Use that domain (without www) as PLAUSIBLE_SITE_ID:

bash
PLAUSIBLE_SITE_ID=
  1. Add the script tag Plausible shows you to app.head in main.wasp:
javascript

    // main.wasp
    app OpenSaaS {
      wasp: {
        version: "^0.13.0"
      },
      title: "My SaaS App",
      head: [
        "",
      ],
      //...
  
  1. API key: in Plausible, go to Settings → copy your API key and put it in .env.server as PLAUSIBLE_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.)

javascript

    //...
    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>

Put the ID into .env.client:

bash
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.

bash
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.

i

Curious how others ship with this stack? Follow us on X for showcases, and join Discord to ask questions and get feedback in minutes.