Merge pull request #12236 from knksmith57/support-custom-google-analytics-id-override

feat: support user-configured Google Analytics reporting
This commit is contained in:
Mike McQuaid 2021-10-20 10:42:03 +01:00 committed by GitHub
commit 9b5f191db1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 53 additions and 40 deletions

View File

@ -11,6 +11,10 @@ module Homebrew
module_function
ENVS = {
HOMEBREW_ADDITIONAL_GOOGLE_ANALYTICS_ID: {
description: "Additional Google Analytics tracking ID to emit user behaviour analytics to. " \
"For more information, see: <https://docs.brew.sh/Analytics>",
},
HOMEBREW_ARCH: {
description: "Linux only: Pass this value to a type name representing the compiler's `-march` option.",
default: "native",

View File

@ -20,6 +20,8 @@ module Utils
return if not_this_run?
return if disabled?
analytics_ids = ENV.fetch("HOMEBREW_ANALYTICS_IDS", "").split(",")
analytics_ids.each do |analytics_id|
args = []
# do not load .curlrc unless requested (must be the first argument)
@ -31,7 +33,7 @@ module Utils
--data v=1
--data aip=1
--data t=#{type}
--data tid=#{ENV["HOMEBREW_ANALYTICS_ID"]}
--data tid=#{analytics_id}
--data cid=#{ENV["HOMEBREW_ANALYTICS_USER_UUID"]}
--data an=#{HOMEBREW_PRODUCT}
--data av=#{HOMEBREW_VERSION}
@ -63,6 +65,8 @@ module Utils
Process.detach T.must(pid)
end
end
nil
end
def report_event(category, action, label = os_arch_prefix_ci, value = nil)
report(:event,

View File

@ -64,12 +64,17 @@ setup-analytics() {
if [[ -n "${HOMEBREW_LINUX}" ]]
then
# For Homebrew on Linux's analytics.
HOMEBREW_ANALYTICS_ID="UA-76492262-1"
HOMEBREW_ANALYTICS_IDS="UA-76492262-1"
else
# Otherwise, fall back to Homebrew's analytics.
HOMEBREW_ANALYTICS_ID="UA-76679469-1"
HOMEBREW_ANALYTICS_IDS="UA-76679469-1"
fi
export HOMEBREW_ANALYTICS_ID
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
}