brew/Library/Homebrew/utils/analytics.sh

54 lines
1.6 KiB
Bash
Raw Normal View History

# Setup analytics and delete old analytics UUIDs.
2021-04-21 21:12:27 +09:00
# HOMEBREW_LINUX, HOMEBREW_REPOSITORY is set by bin/brew
# HOMEBREW_NO_ANALYTICS is from the user environment.
# shellcheck disable=SC2154
2018-10-04 09:31:37 +01:00
setup-analytics() {
local git_config_file="${HOMEBREW_REPOSITORY}/.git/config"
2018-10-04 09:31:37 +01:00
local legacy_uuid_file="${HOME}/.homebrew_analytics_user_uuid"
2021-04-21 21:12:27 +09:00
if [[ -f "${legacy_uuid_file}" ]]
then
2021-04-21 21:12:27 +09:00
rm -f "${legacy_uuid_file}"
fi
local user_uuid
user_uuid="$(git config --file="${git_config_file}" --get homebrew.analyticsuuid 2>/dev/null)"
if [[ -n "${user_uuid}" ]]
then
git config --file="${git_config_file}" --unset-all homebrew.analyticsuuid 2>/dev/null
fi
2021-04-21 21:12:27 +09:00
if [[ -n "${HOMEBREW_NO_ANALYTICS}" ]]
then
2016-05-01 22:04:46 +08:00
return
fi
2018-10-04 09:31:37 +01:00
local message_seen analytics_disabled
2021-04-21 21:12:27 +09:00
message_seen="$(git config --file="${git_config_file}" --get homebrew.analyticsmessage 2>/dev/null)"
analytics_disabled="$(git config --file="${git_config_file}" --get homebrew.analyticsdisabled 2>/dev/null)"
if [[ "${message_seen}" != "true" || "${analytics_disabled}" == "true" ]]
then
# Internal variable for brew's use, to differentiate from user-supplied setting
export HOMEBREW_NO_ANALYTICS_THIS_RUN="1"
return
fi
2021-04-21 21:12:27 +09:00
if [[ -n "${HOMEBREW_LINUX}" ]]
then
# For Homebrew on Linux's analytics.
HOMEBREW_ANALYTICS_IDS="UA-76492262-1"
else
# Otherwise, fall back to Homebrew's analytics.
HOMEBREW_ANALYTICS_IDS="UA-76679469-1"
fi
if [[ -n "${HOMEBREW_ADDITIONAL_GOOGLE_ANALYTICS_ID}" ]]
then
HOMEBREW_ANALYTICS_IDS="${HOMEBREW_ANALYTICS_IDS},${HOMEBREW_ADDITIONAL_GOOGLE_ANALYTICS_ID}"
fi
export HOMEBREW_ANALYTICS_IDS
export HOMEBREW_ANALYTICS_USER_UUID
}