Analytics Setup
Analytics is optional in NuxtBase and defaults to disabled.
That is a good default. Buyers should not be forced to wire analytics before they can install, customize, or validate the product.
Default: Analytics Disabled
Section titled “Default: Analytics Disabled”The baseline env value is:
NUXT_PUBLIC_ANALYTICS_PROVIDER=noneWith this setting, no analytics provider is loaded.
Supported Providers
Section titled “Supported Providers”NuxtBase currently supports these values:
ga4umamiplausiblenone
The provider selection is parsed in shared/config/analytics.ts, and only the selected provider is added to the @nuxt/scripts registry.
GA4 Setup
Section titled “GA4 Setup”NUXT_PUBLIC_ANALYTICS_PROVIDER=ga4NUXT_PUBLIC_SCRIPTS_GOOGLE_ANALYTICS_ID=G-XXXXXXXXXXUse this when you want standard Google Analytics 4 tracking.
How to Get the GA4 Measurement ID
Section titled “How to Get the GA4 Measurement ID”Official Google Analytics references:
Practical setup steps:
- Sign in to Google Analytics.
- Create a GA4 account or use an existing one.
- Create a GA4 property for your site if you do not already have one.
- In
Admin, openData Streamsand create aWebstream for your site. - Open that web stream and copy the
Measurement IDthat starts withG-. - Paste it into
NUXT_PUBLIC_SCRIPTS_GOOGLE_ANALYTICS_ID. - Restart the app and verify that the Google Analytics script loads.
Umami Setup
Section titled “Umami Setup”NUXT_PUBLIC_ANALYTICS_PROVIDER=umamiNUXT_PUBLIC_SCRIPTS_UMAMI_ANALYTICS_WEBSITE_ID=your-website-idNUXT_UMAMI_HOST=https://your-umami-instance.comNUXT_UMAMI_DOMAINS=app.example.com,staging.example.comNUXT_UMAMI_HOST and NUXT_UMAMI_DOMAINS are optional, but helpful when you run your own Umami instance or want to scope domains explicitly.
How to Get the Umami Website ID and Script URL
Section titled “How to Get the Umami Website ID and Script URL”Official Umami references:
Practical setup steps:
- Sign in to Umami Cloud or your self-hosted Umami instance.
- Open
Websitesand clickAdd website. - Enter the site name and domain, then save.
- Open the website settings and go to the
Tracking codesection. - Copy the
data-website-idvalue from the tracking snippet intoNUXT_PUBLIC_SCRIPTS_UMAMI_ANALYTICS_WEBSITE_ID. - Copy the tracker host from the script URL into
NUXT_UMAMI_HOSTif you are not using the default hosted setup. - If you only want the tracker to run on specific domains, copy those hostnames into
NUXT_UMAMI_DOMAINS. - Restart the app and verify that the Umami script loads.
In other words:
NUXT_PUBLIC_SCRIPTS_UMAMI_ANALYTICS_WEBSITE_IDmaps to Umami’sdata-website-idNUXT_UMAMI_HOSTmaps to the tracker host used by the scriptNUXT_UMAMI_DOMAINSmaps to Umami’s optionaldata-domainssetting
Plausible Setup
Section titled “Plausible Setup”There are two supported patterns.
Current Plausible Script ID
Section titled “Current Plausible Script ID”NUXT_PUBLIC_ANALYTICS_PROVIDER=plausibleNUXT_PUBLIC_SCRIPTS_PLAUSIBLE_ANALYTICS_SCRIPT_ID=your-script-idNUXT_PLAUSIBLE_HOST=https://your-plausible-instance.comLegacy Domain-Based Config
Section titled “Legacy Domain-Based Config”NUXT_PUBLIC_ANALYTICS_PROVIDER=plausibleNUXT_PUBLIC_SCRIPTS_PLAUSIBLE_ANALYTICS_DOMAIN=example.comNUXT_PLAUSIBLE_HOST=https://your-plausible-instance.comThe template supports either script-id based setup or the older domain-based fallback.
How to Get the Plausible Script ID or Domain
Section titled “How to Get the Plausible Script ID or Domain”Official Plausible references:
Practical setup steps:
- Sign in to Plausible and add your site.
- In the site setup flow, enter the domain you want Plausible to track.
- Open the site’s
Settings, then go to theSite Installationarea inGeneral. - Copy the installation snippet that Plausible generates for that site.
- If your snippet uses a personalized script such as
https://plausible.io/js/pa-XXXXX.js, copy thepa-XXXXXpart intoNUXT_PUBLIC_SCRIPTS_PLAUSIBLE_ANALYTICS_SCRIPT_ID. - If you prefer the older domain-based setup, put the tracked domain into
NUXT_PUBLIC_SCRIPTS_PLAUSIBLE_ANALYTICS_DOMAINinstead. - If you are self-hosting Plausible or using a custom Plausible host, put that base URL into
NUXT_PLAUSIBLE_HOST. - Restart the app and verify that the Plausible script loads.
For this template:
- use the script ID path when Plausible gives you a personalized
pa-XXXXX.jssnippet - use the domain fallback only when that better matches your existing Plausible setup
Runtime Behavior
Section titled “Runtime Behavior”Analytics loading is centralized in Nuxt config, not scattered through components.
That matters because:
- only one provider is loaded at runtime
- the app can stay clean when analytics is off
- provider mismatches are easier to debug
There is also a small client plugin that warns when the selected provider does not appear to have the required script configuration.
Recommended Setup Sequence
Section titled “Recommended Setup Sequence”- keep analytics on
noneduring initial local setup - choose one provider only
- add the provider-specific env vars
- restart the app
- confirm the browser loads the expected tracking script
What to Check in the Browser
Section titled “What to Check in the Browser”After enabling analytics, verify:
- the correct script appears in the page
- the browser console does not show provider mismatch warnings
- your analytics dashboard receives a pageview or test event