Here's a quick and dirty way to opt out for BASH and ZSH users for easy copy/pasting.
BASH:
cat <<EOF >> .bashrc
# Opt out of Homebrew analytics
export HOMEBREW_NO_ANALYTICS=1
if [[ -e "$HOME/.homebrew_analytics_user_uuid" ]]; then
rm -f "$HOME/.homebrew_analytics_user_uuid"
fi
EOF
ZSH: cat <<EOF >> .zshrc
# Opt out of Homebrew analytics
export HOMEBREW_NO_ANALYTICS=1
if [[ -e "$HOME/.homebrew_analytics_user_uuid" ]]; then
rm -f "$HOME/.homebrew_analytics_user_uuid"
fi
EOF
Cheers.