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.