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
Homebrew (opt-in) Analytics tweaks. #57
Conversation
-d an="$HOMEBREW_PRODUCT" \ | ||
-d av="$HOMEBREW_VERSION" \ | ||
-d t="screenview" \ | ||
-d cd="$HOMEBREW_COMMAND" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We talk about only logging official commands, right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated with this in place. See
brew/Library/Homebrew/utils/analytics.sh
Lines 27 to 34 in 7cb6c73
# Don't report non-official commands. | |
if ! [[ -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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should reduce duplication here as argument list is the same.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't know how to do that easily in Bash CC @UniqMartin.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use a variable for url?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not just the URL but e.g. the arguments like --silent
being omitted and not doing a &>/dev/null & disown
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use bash array then?
6a65e5b
to
7cb6c73
Compare
Updated:
|
7cb6c73
to
840b6ab
Compare
Updated:
|
else | ||
"non-/usr/local" | ||
end | ||
ci = ", CI=1" if ENV["CI"] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this just be CI
(i.e. without =1
)?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could be.
I wonder if it's worth stapling the Google certificate chain to prevent certain classes of MITM attacks. https://src.chromium.org/viewvc/chrome/trunk/src/net/http/transport_security_state_static.json gives some insight into what Google promises for its properties. |
@tdsmith Feels overkill to me but if you felt like making a PR I'd not oppose that. |
f5b9715
to
0bc7d3a
Compare
Updated:
|
0bc7d3a
to
80bb958
Compare
Updated:
I'll merge this as-is tomorrow unless there are any objections and open a new PR to 🚢 this to all users. |
metadata_args = metadata.map do |key, value| | ||
["-d", "#{key}=#{value}"] if key && value | ||
end.compact.flatten | ||
debug = !!ENV["HOMEBREW_ANALYTICS_DEBUG"] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
RuboCop doesn't fully approve. !ENV["HOMEBREW_ANALYTICS_DEBUG"].nil?
maybe?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Weird. !!
will never be nil
. I'll take a look, thanks.
Homebrew will shortly begin gathering anonymous aggregate user behaviour analytics and reporting these to Google Analytics. | ||
|
||
## Why? | ||
Homebrew is provided free of charge and run entirely by volunteers in their spare time. As a result, we do not have the resources to do detailed user studies of Homebrew users to decide on how best to design future features and prioritise current work. Anonymous aggregate user analytics allow us to prioritise fixes and features based on how, where and when people use Homebrew. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think a clear and detailed example will help. Identifying buggy formulae is one, since we will report build failures.
Two other things that seem interesting:
|
If this was shipped to users I'd agree but I think given it's still an opt-in feature there's no reason we can't keep moving forwards on this and deal with feedback after merging. Point taken, though.
We shouldn't track |
Agreed. Will address this in the next PR.
This is done already; see |
4f325ac
to
f21db5c
Compare
Updated:
|
91e62bf
to
cd587a5
Compare
fi | ||
|
||
# Don't report commands used mostly by our scripts and not users. | ||
if [[ "$HOMEBREW_COMMAND" = "commands" ]] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There are many other commands also used in scripts. e.g. search
(without any option), list
, command
(to test the existence of external command) and even tap
(without any option or --list-*
option). There is also --cache
which it's not short circuited as --repo
/--prefix
does.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just a FYI note.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Which do you think we should remove? I'd like to know some of them that are actually being run by users.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Clearly, current blacklist approach doesn't scale well. It may be better to put all autocompletion script related commands into a separate group at first. e.g. a dedicate command for script autocompletion? (just a random idea)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@xu-cheng I don't think this needs to block this PR or even the feature shipping, though, given these are all run in forked background processes.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would be great to have a TODO comment for the time being.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree. Having a dedicated blacklisted entry point for things used from shell completion sounds like a good solution, that doesn't depend on “magic” like testing stdout
for a TTY.
cd587a5
to
bf67e93
Compare
Updated:
|
@@ -202,7 +202,10 @@ def install | |||
|
|||
oh1 "Installing #{Tty.green}#{formula.full_name}#{Tty.reset}" if show_header? | |||
|
|||
report_analytics_event("install", formula.full_name) | |||
unless exception.formula.tap.private? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like this should have been just formula.tap.private?
for the tests not to fail.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also tap can be nil.
bf67e93
to
cc81840
Compare
def report_analytics_exception(exception, options={}) | ||
if exception.is_a? BuildError | ||
def report_analytics_exception(exception, options = {}) | ||
if exception.is_a? BuildError && !exception.formula.tap.private? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
exception.is_a?(BuildError) && exception.formula.tap && !exception.formula.tap.private?
cc81840
to
4d98592
Compare
Updated based on feedback. Think this is good to 🚢 along with #67 now when they are both 💚. |
@@ -0,0 +1,71 @@ | |||
setup-analytics() { | |||
[[ -z "$HOMEBREW_AUTO_UPDATE" ]] && return | |||
[[ -n "$HOMEBREW_NO_AUTO_UPDATE" ]] && return |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You mean HOMEBREW_ANALYTICS
not UPDATE
right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
arrrgghh
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My code examples shouldn't always be copied verbatim. 😉 Good thing it was noticed before it could create any confusion. 🙇
cf5356b
to
b102233
Compare
- add `HOMEBREW_PRODUCT` global variable - only differentiate between `/usr/local` and `non-/usr/local` Homebrew prefixes to avoid sharing sensitive user information - note if e.g. build errors are occurring under CI - Add `HOMEBREW_NO_ANALYTICS` variable (this will be how people opt-out when this is enabled for everyone) - Add `HOMEBREW_ANALYTICS_DEBUG` variable to output all the analytics that are sent - Move Bash analytics code to `Library/Homebrew/utils/analytics.sh` - Add documentation for our analytics and why/what/when/how and opt-out - Only official Homebrew commands are reported - Ruby analytics are now reported in a forked, background process
brew tests
with your changes locally?HOMEBREW_PRODUCT
global variable/usr/local
andnon-/usr/local
Homebrewprefixes to avoid sharing sensitive user information
HOMEBREW_NO_ANALYTICS
variable (this will be how people opt-outwhen this is enabled for everyone)
HOMEBREW_ANALYTICS_DEBUG
variable to output all the analyticsthat are sent
Library/Homebrew/utils/analytics.sh
CC @xu-cheng and @UniqMartin for thoughts.
After this I think we've got everything we need to 🚢 analytics to everyone (i.e. remove the
HOMEBREW_ANALYTICS
checks). If any @Homebrew/maintainers disagree with this: let me know ASAP. Thanks!