How to anonymize IPs Google Analytics in 2021 on Discourse?

The above is correct (of course change your UA ID). Extra step that’s needed is: go to your admin settings and search for content security policy script src.

There add https://www.google-analytics.com/analytics.js, then it works.