Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

analytics: remove unused analytics. #2752

Merged
merged 1 commit into from
Jun 9, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 1 addition & 4 deletions Library/Homebrew/brew.rb
Expand Up @@ -134,25 +134,22 @@ def require?(path)
$stderr.puts # seemingly a newline is typical
exit 130
rescue BuildError => e
Utils::Analytics.report_exception(e)
Utils::Analytics.report_build_error(e)
e.dump
exit 1
rescue RuntimeError, SystemCallError => e
Utils::Analytics.report_exception(e)
raise if e.message.empty?
onoe e
$stderr.puts e.backtrace if ARGV.debug?
exit 1
rescue MethodDeprecatedError => e
Utils::Analytics.report_exception(e)
onoe e
if e.issues_url
$stderr.puts "If reporting this issue please do so at (not Homebrew/brew or Homebrew/core):"
$stderr.puts " #{Formatter.url(e.issues_url)}"
end
exit 1
rescue Exception => e
Utils::Analytics.report_exception(e)
onoe e
if internal_cmd && defined?(OS::ISSUES_URL)
$stderr.puts "#{Tty.bold}Please report this bug:#{Tty.reset}"
Expand Down
1 change: 0 additions & 1 deletion Library/Homebrew/brew.sh
Expand Up @@ -278,7 +278,6 @@ fi
# shellcheck source=/dev/null
source "$HOMEBREW_LIBRARY/Homebrew/utils/analytics.sh"
setup-analytics
report-analytics-screenview-command

# Let user know we're still updating Homebrew if brew update --preinstall
# exceeds 3 seconds.
Expand Down
7 changes: 2 additions & 5 deletions Library/Homebrew/formula_installer.rb
Expand Up @@ -271,14 +271,11 @@ def install
oh1 "Installing #{Formatter.identifier(formula.full_name)} #{options.join " "}" if show_header?

if formula.tap && !formula.tap.private?
category = "install"
action = ([formula.full_name] + options).join(" ")
Utils::Analytics.report_event(category, action)
Utils::Analytics.report_event("install", action)

if installed_on_request
category = "install_on_request"
action = ([formula.full_name] + options).join(" ")
Utils::Analytics.report_event(category, action)
Utils::Analytics.report_event("install_on_request", action)
end
end

Expand Down
21 changes: 5 additions & 16 deletions Library/Homebrew/utils/analytics.rb
Expand Up @@ -61,22 +61,11 @@ def report_event(category, action, label = os_prefix_ci, value = nil)
ev: value)
end

def report_exception(exception, options = {})
if exception.is_a?(BuildError) &&
exception.formula.tap &&
exception.formula.tap.installed? &&
!exception.formula.tap.private?
report_event("BuildError", exception.formula.full_name)
end

fatal = options.fetch(:fatal, true) ? "1" : "0"
report(:exception,
exd: exception.class.name,
exf: fatal)
end

def report_screenview(screen_name)
report(:screenview, cd: screen_name)
def report_build_error(exception)
return unless exception.formula.tap
return unless exception.formula.tap.installed?
return if exception.formula.tap.private?
report_event("BuildError", exception.formula.full_name)
end
end
end
Expand Down
53 changes: 0 additions & 53 deletions Library/Homebrew/utils/analytics.sh
Expand Up @@ -66,56 +66,3 @@ setup-analytics() {
export HOMEBREW_ANALYTICS_ID
export HOMEBREW_ANALYTICS_USER_UUID
}

report-analytics-screenview-command() {
[[ -n "$HOMEBREW_NO_ANALYTICS" || -n "$HOMEBREW_NO_ANALYTICS_THIS_RUN" ]] && return

# Don't report commands that are invoked as part of other commands.
[[ "$HOMEBREW_COMMAND_DEPTH" != 1 ]] && return

# Don't report non-official commands.
if ! [[ "$HOMEBREW_COMMAND" = "bundle" ||
"$HOMEBREW_COMMAND" = "services" ||
-f "$HOMEBREW_LIBRARY/Homebrew/cmd/$HOMEBREW_COMMAND.rb" ||
-f "$HOMEBREW_LIBRARY/Homebrew/cmd/$HOMEBREW_COMMAND.sh" ||
-f "$HOMEBREW_LIBRARY/Homebrew/dev-cmd/$HOMEBREW_COMMAND.rb" ||
-f "$HOMEBREW_LIBRARY/Homebrew/dev-cmd/$HOMEBREW_COMMAND.sh" ]]
then
return
fi

# Don't report commands used mostly by our scripts and not users.
case "$HOMEBREW_COMMAND" in
--prefix|analytics|command|commands)
return
;;
esac

local args=(
--max-time 3
--user-agent "$HOMEBREW_USER_AGENT_CURL"
--data v=1
--data aip=1
--data t=screenview
--data tid="$HOMEBREW_ANALYTICS_ID"
--data cid="$HOMEBREW_ANALYTICS_USER_UUID"
--data an="$HOMEBREW_PRODUCT"
--data av="$HOMEBREW_VERSION"
--data cd="$HOMEBREW_COMMAND"
)

# Send analytics. Don't send or store any personally identifiable information.
# http://docs.brew.sh/Analytics.html
# https://developers.google.com/analytics/devguides/collection/protocol/v1/devguide#screenView
# https://developers.google.com/analytics/devguides/collection/protocol/v1/parameters
if [[ -z "$HOMEBREW_ANALYTICS_DEBUG" ]]
then
"$HOMEBREW_CURL" https://www.google-analytics.com/collect \
"${args[@]}" \
--silent --output /dev/null &>/dev/null & disown
else
local url="https://www.google-analytics.com/debug/collect"
echo "$HOMEBREW_CURL $url ${args[*]}"
"$HOMEBREW_CURL" "$url" "${args[@]}"
fi
}
4 changes: 1 addition & 3 deletions docs/Analytics.md
Expand Up @@ -18,14 +18,12 @@ Homebrew's analytics record some shared information for every event:
- If the Google Analytics anonymous IP setting is enabled, i.e. `1` (https://developers.google.com/analytics/devguides/collection/protocol/v1/parameters#aip)
- The Homebrew application name, e.g. `Homebrew` (https://developers.google.com/analytics/devguides/collection/protocol/v1/parameters#an)
- The Homebrew application version, e.g. `0.9.9` (https://developers.google.com/analytics/devguides/collection/protocol/v1/parameters#av)
- The Homebrew analytics hit type, e.g. `screenview` (https://developers.google.com/analytics/devguides/collection/protocol/v1/parameters#t)
- The Homebrew analytics hit type, e.g. `event` (https://developers.google.com/analytics/devguides/collection/protocol/v1/parameters#t)

Homebrew's analytics records the following different events:

- a `screenview` hit type with the official Homebrew command you have run (with arguments stripped), e.g. `brew list` (not `brew list foo` or any external commands except `bundle` and `services`)
- an `event` hit type with the `install` event category and the Homebrew formula from a non-private GitHub tap you have requested to install plus any used options, e.g. `wget --with-pcre` as the action and an event label e.g. `macOS 10.12, non-/usr/local, CI` to indicate the OS version, non-standard installation location and invocation as part of CI. This allows us to identify the formulae that need fixing and where more easily.
- an `event` hit type with the `BuildError` event category and the Homebrew formula that failed to install, e.g. `wget` as the action and an event label e.g. `macOS 10.12`
- an `exception` hit type with the `exception` event category and exception description of the exception name, e.g. `FormulaUnavailableError` and whether the exception was fatal e.g. `1`

You can also view all the information that is sent by Homebrew's analytics by setting `HOMEBREW_ANALYTICS_DEBUG=1` in your environment. Please note this will also stop any analytics from being sent.

Expand Down