feat: support user-configured Google Analytics reporting
Allow users to set a custom Google Analytics tracking ID to report user behaviour via new environment variable: $HOMEBREW_ADDITIONAL_GOOGLE_ANALYTICS_ID. If provided, this tracking ID will be used _in addition to_ the default tracking ID used by <https://brew.sh/analytics/>.
This commit is contained in:
parent
58662f8da8
commit
7866a4b586
@ -11,6 +11,10 @@ module Homebrew
|
|||||||
module_function
|
module_function
|
||||||
|
|
||||||
ENVS = {
|
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: {
|
HOMEBREW_ARCH: {
|
||||||
description: "Linux only: Pass this value to a type name representing the compiler's `-march` option.",
|
description: "Linux only: Pass this value to a type name representing the compiler's `-march` option.",
|
||||||
default: "native",
|
default: "native",
|
||||||
|
@ -20,6 +20,8 @@ module Utils
|
|||||||
return if not_this_run?
|
return if not_this_run?
|
||||||
return if disabled?
|
return if disabled?
|
||||||
|
|
||||||
|
analytics_ids = ENV.fetch("HOMEBREW_ANALYTICS_IDS", "").split(",")
|
||||||
|
analytics_ids.each do |analytics_id|
|
||||||
args = []
|
args = []
|
||||||
|
|
||||||
# do not load .curlrc unless requested (must be the first argument)
|
# do not load .curlrc unless requested (must be the first argument)
|
||||||
@ -31,7 +33,7 @@ module Utils
|
|||||||
--data v=1
|
--data v=1
|
||||||
--data aip=1
|
--data aip=1
|
||||||
--data t=#{type}
|
--data t=#{type}
|
||||||
--data tid=#{ENV["HOMEBREW_ANALYTICS_ID"]}
|
--data tid=#{analytics_id}
|
||||||
--data cid=#{ENV["HOMEBREW_ANALYTICS_USER_UUID"]}
|
--data cid=#{ENV["HOMEBREW_ANALYTICS_USER_UUID"]}
|
||||||
--data an=#{HOMEBREW_PRODUCT}
|
--data an=#{HOMEBREW_PRODUCT}
|
||||||
--data av=#{HOMEBREW_VERSION}
|
--data av=#{HOMEBREW_VERSION}
|
||||||
@ -63,6 +65,8 @@ module Utils
|
|||||||
Process.detach T.must(pid)
|
Process.detach T.must(pid)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
nil
|
||||||
|
end
|
||||||
|
|
||||||
def report_event(category, action, label = os_arch_prefix_ci, value = nil)
|
def report_event(category, action, label = os_arch_prefix_ci, value = nil)
|
||||||
report(:event,
|
report(:event,
|
||||||
|
@ -64,12 +64,17 @@ setup-analytics() {
|
|||||||
if [[ -n "${HOMEBREW_LINUX}" ]]
|
if [[ -n "${HOMEBREW_LINUX}" ]]
|
||||||
then
|
then
|
||||||
# For Homebrew on Linux's analytics.
|
# For Homebrew on Linux's analytics.
|
||||||
HOMEBREW_ANALYTICS_ID="UA-76492262-1"
|
HOMEBREW_ANALYTICS_IDS="UA-76492262-1"
|
||||||
else
|
else
|
||||||
# Otherwise, fall back to Homebrew's analytics.
|
# Otherwise, fall back to Homebrew's analytics.
|
||||||
HOMEBREW_ANALYTICS_ID="UA-76679469-1"
|
HOMEBREW_ANALYTICS_IDS="UA-76679469-1"
|
||||||
fi
|
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
|
export HOMEBREW_ANALYTICS_USER_UUID
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user