The discussion outlines the setup of Google Analytics 4 (GA4) for Discourse, with users and developers sharing guidance. TechGeek suggests adding gtag.js directly or using Google Tag Manager, while justin confirms the integration is now available in core via the ga_version setting, requiring a switch to v4_gtag in Admin settings. Users like Paracelsus and datvnn share successful implementations, noting the loss of historical data in GA4. j127 explains how to send data to both Universal Analytics and GA4 simultaneously for data continuity. driib asks about GDPR compliance, and justin suggests using a theme component for custom gtag configurations. TechGeek reports duplicate page views with v4_gtag and questions if admin-level code insertion can be avoided.
Google has recently released Google Analytics 4, Below are few suggestions for Discourse:
Add gtag.js directly to your pages: Add option in Dashboard to add Google Analytics 4 gtag.js directly (Yes, this can be done by embedding gtag directly in head, but for discourse additional configuration may be required). While this may take some time for development, second option can work for most meanwhile
Add gtag.js directly to your web pages that are already - tagged with analytics.js: while this is an option currently, but Universal Analytics will be phased out over a period of time
To upgrade to Universal Analytics v4 which uses gtag as a wrapper for analytics.js, head to Admin > Settings and search for ga_version. Switch this setting to v4_gtag and refresh to upgrade to version 4.
Be aware in upgrading to v4 you will need to change any custom events you’ve defined in theme components to use the new gtag API instead of ga.