Or if you want to cover existing users, just ask during the first interactive invocation, when there is no prior user chosen setting (works for new installs too)...
pseudocode:
choice = no
if $brew_prefix/etc/homebrew.yaml:
choice = read analytics $brew_prefix/etc/homebrew.yaml
else:
if interactive-tty and cmd != "--prefix":
choice = ask-user "enable anonymous analytics (it helps us!)? Y/N: "
write analytics=<choice> $brew_prefix/etc/homebrew.yaml
if choice == yes:
enable-analytics
pseudocode: