Skip to content

Commit

Permalink
analytics: remove UUID.
Browse files Browse the repository at this point in the history
We don't use this at all with InfluxDB and don't need it any more for GA
so let's just remove it.
  • Loading branch information
MikeMcQuaid committed Feb 20, 2023
1 parent a222a5b commit 5784453
Show file tree
Hide file tree
Showing 7 changed files with 26 additions and 64 deletions.
15 changes: 6 additions & 9 deletions Library/Homebrew/cmd/analytics.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,6 @@ def analytics_args
`brew analytics` (`on`|`off`):
Turn Homebrew's analytics on or off respectively.
`brew analytics regenerate-uuid`:
Regenerate the UUID used for Homebrew's Google Analytics (not InfluxDB).
EOS

named_args %w[state on off regenerate-uuid], max: 1
Expand All @@ -36,20 +33,20 @@ def analytics
when nil, "state"
if Utils::Analytics.disabled?
puts "Analytics are disabled."
elsif Homebrew::EnvConfig.no_google_analytics?
puts "InfluxDB analytics are enabled."
puts "Google Analytics are disabled."
else
puts "Analytics are enabled."
if Homebrew::EnvConfig.no_google_analytics?
puts "Google Analytics are disabled."
elsif Utils::Analytics.uuid.present?
puts "UUID: #{Utils::Analytics.uuid}"
end
end
when "on"
Utils::Analytics.enable!
when "off"
Utils::Analytics.disable!
when "regenerate-uuid"
Utils::Analytics.regenerate_uuid!
Utils::Analytics.delete_uuid!
opoo "Homebrew no longer uses an analytics UUID so this has been deleted!"
puts "brew analytics regenerate-uuid is no longer necessary."
else
raise UsageError, "unknown subcommand: #{args.named.first}"
end
Expand Down
12 changes: 4 additions & 8 deletions Library/Homebrew/utils/analytics.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def report_google(type, metadata = {})
--data aip=1
--data t=#{type}
--data tid=#{analytics_id}
--data cid=#{ENV.fetch("HOMEBREW_ANALYTICS_USER_UUID")}
--data uid=n0thxg00gl3
--data an=#{HOMEBREW_PRODUCT}
--data av=#{HOMEBREW_VERSION}
]
Expand Down Expand Up @@ -202,27 +202,23 @@ def no_message_output?
ENV["HOMEBREW_NO_ANALYTICS_MESSAGE_OUTPUT"].present?
end

def uuid
Homebrew::Settings.read :analyticsuuid
end

def messages_displayed!
Homebrew::Settings.write :analyticsmessage, true
Homebrew::Settings.write :caskanalyticsmessage, true
end

def enable!
Homebrew::Settings.write :analyticsdisabled, false
delete_uuid!
messages_displayed!
end

def disable!
Homebrew::Settings.write :analyticsdisabled, true
regenerate_uuid!
delete_uuid!
end

def regenerate_uuid!
# it will be regenerated in next run unless disabled.
def delete_uuid!
Homebrew::Settings.delete :analyticsuuid
end

Expand Down
47 changes: 10 additions & 37 deletions Library/Homebrew/utils/analytics.sh
Original file line number Diff line number Diff line change
@@ -1,28 +1,23 @@
# Migrate analytics UUID to its new home in Homebrew repo's git config and
# remove the legacy UUID file if detected.
# Setup analytics and delete old analytics UUIDs.
# HOMEBREW_LINUX, HOMEBREW_REPOSITORY is set by bin/brew
# HOMEBREW_NO_ANALYTICS is from the user environment.
# shellcheck disable=SC2154
migrate-legacy-uuid-file() {
local legacy_uuid_file analytics_uuid

legacy_uuid_file="${HOME}/.homebrew_analytics_user_uuid"
setup-analytics() {
local git_config_file="${HOMEBREW_REPOSITORY}/.git/config"

local legacy_uuid_file="${HOME}/.homebrew_analytics_user_uuid"
if [[ -f "${legacy_uuid_file}" ]]
then
analytics_uuid="$(cat "${legacy_uuid_file}")"
if [[ -n "${analytics_uuid}" ]]
then
git config --file="${HOMEBREW_REPOSITORY}/.git/config" --replace-all homebrew.analyticsuuid "${analytics_uuid}" 2>/dev/null
fi
rm -f "${legacy_uuid_file}"
fi
}

setup-analytics() {
local git_config_file="${HOMEBREW_REPOSITORY}/.git/config"

migrate-legacy-uuid-file
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

if [[ -n "${HOMEBREW_NO_ANALYTICS}" ]]
then
Expand All @@ -39,28 +34,6 @@ setup-analytics() {
return
fi

HOMEBREW_ANALYTICS_USER_UUID="$(git config --file="${git_config_file}" --get homebrew.analyticsuuid 2>/dev/null)"
if [[ -z "${HOMEBREW_ANALYTICS_USER_UUID}" ]]
then
if [[ -x /usr/bin/uuidgen ]]
then
HOMEBREW_ANALYTICS_USER_UUID="$(/usr/bin/uuidgen)"
elif [[ -r /proc/sys/kernel/random/uuid ]]
then
HOMEBREW_ANALYTICS_USER_UUID="$(tr a-f A-F </proc/sys/kernel/random/uuid)"
else
HOMEBREW_ANALYTICS_USER_UUID="$(uuidgen)"
fi

if [[ -z "${HOMEBREW_ANALYTICS_USER_UUID}" ]]
then
# Avoid sending bogus analytics if no UUID could be generated.
export HOMEBREW_NO_ANALYTICS_THIS_RUN="1"
return
fi
git config --file="${git_config_file}" --replace-all homebrew.analyticsuuid "${HOMEBREW_ANALYTICS_USER_UUID}" 2>/dev/null
fi

if [[ -n "${HOMEBREW_LINUX}" ]]
then
# For Homebrew on Linux's analytics.
Expand Down
2 changes: 1 addition & 1 deletion completions/bash/brew
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Bash completion script for brew(1)

if [[ -n ${POSIXLY_CORRECT} ]] || shopt -oq posix
if test -v POSIXLY_CORRECT || test -o posix
then
echo "Homebrew Bash completions do not work in POSIX mode" 1>&2
return
Expand Down
7 changes: 5 additions & 2 deletions docs/Analytics.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,15 @@ For analytics sent to Google Analytics, which is in the process of being phased

- The Homebrew user agent, e.g. `Homebrew/3.3.0 (Macintosh; Intel Mac OS X 10.15.6) curl/7.64.1`.
- The [Google Analytics version](https://developers.google.com/analytics/devguides/collection/protocol/v1/parameters#v), i.e. `1`.
- The Homebrew [analytics tracking ID](https://developers.google.com/analytics/devguides/collection/protocol/v1/parameters#tid), e.g. `UA-75654628-1`.
- A Homebrew [analytics user ID](https://developers.google.com/analytics/devguides/collection/protocol/v1/parameters#cid), e.g. `1BAB65CC-FE7F-4D8C-AB45-B7DB5A6BA9CB`. This is generated by `uuidgen` and stored in the repository-specific Git configuration variable `homebrew.analyticsuuid` within `$(brew --repository)/.git/config`. This does not allow us to track individual users, but does enable us to accurately measure user counts versus event counts. The ID is specific to the Homebrew package manager, and does not permit Homebrew maintainers to e.g. track you across websites you visit. It is only used with Google Analytics.
- The Homebrew [analytics tracking ID](https://developers.google.com/analytics/devguides/collection/protocol/v1/parameters#tid), i.e. `UA-76679469-1` on macOS and `UA-76492262-1` on Linux. This value is constant and is the same for all users.
- Whether the [Google Analytics anonymous IP setting](https://developers.google.com/analytics/devguides/collection/protocol/v1/parameters#aip) is enabled, i.e. `1`.
- The Homebrew [application name](https://developers.google.com/analytics/devguides/collection/protocol/v1/parameters#an), e.g. `Homebrew`.
- The Homebrew [analytics hit type](https://developers.google.com/analytics/devguides/collection/protocol/v1/parameters#t), e.g. `event`.

We previously recorded but have now removed:

- A Homebrew [analytics user ID](https://developers.google.com/analytics/devguides/collection/protocol/v1/parameters#cid), e.g. `1BAB65CC-FE7F-4D8C-AB45-B7DB5A6BA9CB`. This was generated by `uuidgen` and stored in the repository-specific Git configuration variable `homebrew.analyticsuuid` within `$(brew --repository)/.git/config`. This did not allow us to track individual users, but does enable us to accurately measure user counts versus event counts. The ID was specific to the Homebrew package manager, and did not permit Homebrew maintainers to e.g. track you across websites you visit. It was only used with Google Analytics.

Homebrew's analytics records the following different events:

- The `install` event category and the Homebrew formula from a non-private GitHub tap you install plus any used options (e.g. `wget --HEAD`) as the action. This allows us to identify which formulae where work should be prioritised, as well as how to handle possible deprecation or removal of any.
Expand Down
3 changes: 0 additions & 3 deletions docs/Manpage.md
Original file line number Diff line number Diff line change
Expand Up @@ -79,9 +79,6 @@ Read more at <https://docs.brew.sh/Analytics>.
`brew analytics` (`on`|`off`)
<br>Turn Homebrew's analytics on or off respectively.

`brew analytics regenerate-uuid`
<br>Regenerate the UUID used for Homebrew's Google Analytics (not InfluxDB).

### `autoremove` [`--dry-run`]

Uninstall formulae that were only installed as a dependency of another formula and are now no longer needed.
Expand Down
4 changes: 0 additions & 4 deletions manpages/brew.1
Original file line number Diff line number Diff line change
Expand Up @@ -92,10 +92,6 @@ Control Homebrew\'s anonymous aggregate user behaviour analytics\. Read more at
\fBbrew analytics\fR (\fBon\fR|\fBoff\fR)
Turn Homebrew\'s analytics on or off respectively\.
.
.P
\fBbrew analytics regenerate\-uuid\fR
Regenerate the UUID used for Homebrew\'s Google Analytics (not InfluxDB)\.
.
.SS "\fBautoremove\fR [\fB\-\-dry\-run\fR]"
Uninstall formulae that were only installed as a dependency of another formula and are now no longer needed\.
.
Expand Down

0 comments on commit 5784453

Please sign in to comment.