DNS level blocking with a Pihole is much safer in this regard, but also less capable, since it only works on anything that uses a dedicated domain that can be identified.
In this case, google analytics only goes through analytics.google.com, so it’s easy to block at a DNS level.