Why would anybody opt-in to analytics of a website they are visiting - even if it's strictly first-party, not sharing it with advertizers or Google, just for improving the site? You are gonna click "no".
Same with application analytics - if you know as a developer which functions people use how frequently, and where the app crashes, everyone benefits. The potential dangers are theoretical at best, and you can always opt out. But if it is opt-in, you get completely skewed results.
Controversial opinion, but I think opt-out should be the default in 90% of the cases, and to prevent the undesired outcome (e.g. people making ad profiles) you should not require out-in, but just ban the undesired outcome.
You know it's a bad thing when you say "If I ask users for consent, nobody will agree to this."
I as a customer want full control of my data and if you, the website owner, try to force me into giving data that I did not consent to (invasive site analytics, for example, that track my page behavior), I will go out of my way to block that through extensions and by just banning things at the DNS level.
That is not the "tragedy of the commons". (Even if Tragedy of the Commons is rubbish)
Make clear why, and people will opt in. If they do not tough luck. Be more attractive next time.
I have experience in exactly this (in a different domain).
If there is something that gives you an aggregate benefit, but no immediate benefit, and you have to go out of your way to agree, and maybe there is some scary legalese that you have to sign, then most people will just not bother.
I don't mean harmful things like sharing PII with advertizers, political parties, or law enforcement, but only things like censuses, public transportation statistics, application crash analytics.