From 0b79f48aad33a0b89fd6dc07d0103040449361b5 Mon Sep 17 00:00:00 2001 From: Mike McQuaid Date: Mon, 28 Mar 2016 09:33:45 +0100 Subject: [PATCH] Add opt-in Google Analytics. Add the first Google Analytics usage to monitor the command names that are run by Homebrew. --- Library/brew.sh | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/Library/brew.sh b/Library/brew.sh index eb6c19a97d..cbde0e7c4c 100644 --- a/Library/brew.sh +++ b/Library/brew.sh @@ -198,6 +198,39 @@ EOS esac fi +if [[ -n "$HOMEBREW_ANALYTICS" ]] +then + # User UUID file. Used for Homebrew user counting. Can be deleted and + # recreated with no adverse effect (beyond our user counts being inflated). + HOMEBREW_ANALYTICS_USER_UUID_FILE="$HOME/.homebrew_analytics_user_uuid" + if [[ -r "$HOMEBREW_ANALYTICS_USER_UUID_FILE" ]] + then + HOMEBREW_ANALYTICS_USER_UUID="$(cat "$HOMEBREW_ANALYTICS_USER_UUID_FILE")" + else + HOMEBREW_ANALYTICS_USER_UUID="$(uuidgen)" + echo "$HOMEBREW_ANALYTICS_USER_UUID" > "$HOMEBREW_ANALYTICS_USER_UUID_FILE" + fi + export HOMEBREW_ANALYTICS_ID="UA-75654628-1" + export HOMEBREW_ANALYTICS_USER_UUID + + # Send the to-be-executed command as an "App Screen View". Anonymise the IP + # address (aip=1) and don't send or store any personally identifiable + # information. + # https://developers.google.com/analytics/devguides/collection/protocol/v1/devguide#screenView + # https://developers.google.com/analytics/devguides/collection/protocol/v1/parameters + curl https://www.google-analytics.com/collect -d v=1 \ + --silent --max-time 3 --output /dev/null \ + --user-agent "$HOMEBREW_USER_AGENT_CURL" \ + -d tid="$HOMEBREW_ANALYTICS_ID" \ + -d cid="$HOMEBREW_ANALYTICS_USER_UUID" \ + -d aip=1 \ + -d an=Homebrew \ + -d av="$HOMEBREW_VERSION" \ + -d t=screenview \ + -d cd="$HOMEBREW_COMMAND" \ + & +fi + if [[ -n "$HOMEBREW_BASH_COMMAND" ]] then # source rather than executing directly to ensure the entire file is read into