Analytics and Consent
Decide whether to enable Google Analytics or AdSense, configure consent safely, update your legal disclosures, and verify that no script loads early.
By the end of this page, you will have made a deliberate off, analytics-only, advertising-only, or both decision and verified it in a production build. The recommended default is off: collect data only when it answers a product question you own.
What ships
NEXT_PUBLIC_GOOGLE_ANALYTICS_IDenables the Google Analytics component.NEXT_PUBLIC_GOOGLE_ADCODEenables the AdSense loader. It does not create ad placements for you.- Both script components return nothing outside production.
- Analytics and advertising are separate consent categories. Accepting measurement does not accept advertising.
- Missing, malformed, or old consent fails closed. Neither script renders until its category is explicitly allowed.
cookie_consentstores the versioned choice for 182 days withSameSite=LaxandSecureon HTTPS.- If neither vendor variable is configured, the banner and footer cookie-settings control are absent.
- The footer can reopen settings so a visitor can change or withdraw a choice.
- The separate admin app does not mount these scripts or the consent interface.
Choose the smallest useful setup
| Choice | When it fits | Cost |
|---|---|---|
| Off — recommended initially | You do not yet have an event question or reviewed privacy position | No traffic/product measurement from these providers |
| Analytics only | You need aggregate acquisition and usage measurement | Consent, data-governance, provider configuration, and data quality work |
| Advertising only | Advertising is part of the business model | Highest consent, policy, placement, and user-trust burden |
| Both | Measurement and advertising are both genuinely required | Two independent choices and two provider configurations to operate |
Do not enable analytics just to produce a dashboard. Define the decisions the data will change, the events needed, who reviews them, and when unused collection will be removed.
Configure the deployment
Add only the identifiers you use to the production environment:
NEXT_PUBLIC_GOOGLE_ANALYTICS_ID=G-XXXXXXXXXX
NEXT_PUBLIC_GOOGLE_ADCODE=ca-pub-XXXXXXXXXXXXXXXXThese are public build-time identifiers, not secrets. Rebuild after changing them. Configure the matching GA4 property or AdSense account for your production domains, regions, data retention, access, and any provider-side consent requirements.
Update LegalData.subProcessors and the privacy policy in src/config/legal.ts to match the providers and purposes you actually enable. Review the policy and banner wording with qualified counsel for the markets you serve. If you add a vendor or change what an existing consent category means, bump CONSENT_VERSION in src/lib/consent.ts; old choices will then be discarded and requested again.
Verify in production behavior
Development is not the final check: both vendor components intentionally return null unless NODE_ENV is production. Test a production build or controlled production deployment with browser storage and cookies cleared.
- Before choosing, confirm there is no Analytics or AdSense script request.
- Reject all, reload, and confirm neither provider loads.
- Allow analytics only and confirm GA loads while AdSense does not.
- Allow advertising only and confirm AdSense loads while GA does not.
- Reopen settings from the footer, withdraw consent, reload, and confirm the rejected category stays off.
- Inspect
cookie_consent: it should contain version1, two booleans, and a 182-day maximum age. - Remove both environment variables and rebuild; the banner, settings control, and provider scripts should all disappear.
- Check the admin origin separately; it should contain none of this customer-site tracking UI.
Use the browser network panel, not only the presence of a banner. The script components enforce consent; the banner is only the interface.
What is not finished for you
The starter does not define a product event taxonomy, custom business events, dashboards, retention goals, an AdSense placement component, or a legally approved consent program. It also cannot configure Google account settings for you. Add the minimum measurement layer your product needs and keep provider settings, public policy, and code behavior aligned.
For deployment checks, continue with Deployment and Security. The customer-facing policy is available at Privacy.
Source snapshot
Verified against starter commit 7580470: