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,48 +20,52 @@ module Utils
|
|||||||
return if not_this_run?
|
return if not_this_run?
|
||||||
return if disabled?
|
return if disabled?
|
||||||
|
|
||||||
args = []
|
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)
|
# do not load .curlrc unless requested (must be the first argument)
|
||||||
args << "--disable" unless Homebrew::EnvConfig.curlrc?
|
args << "--disable" unless Homebrew::EnvConfig.curlrc?
|
||||||
|
|
||||||
args += %W[
|
args += %W[
|
||||||
--max-time 3
|
--max-time 3
|
||||||
--user-agent #{HOMEBREW_USER_AGENT_CURL}
|
--user-agent #{HOMEBREW_USER_AGENT_CURL}
|
||||||
--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}
|
||||||
]
|
]
|
||||||
metadata.each do |key, value|
|
metadata.each do |key, value|
|
||||||
next unless key
|
next unless key
|
||||||
next unless value
|
next unless value
|
||||||
|
|
||||||
key = ERB::Util.url_encode key
|
key = ERB::Util.url_encode key
|
||||||
value = ERB::Util.url_encode value
|
value = ERB::Util.url_encode value
|
||||||
args << "--data" << "#{key}=#{value}"
|
args << "--data" << "#{key}=#{value}"
|
||||||
end
|
end
|
||||||
|
|
||||||
# Send analytics. Don't send or store any personally identifiable information.
|
# Send analytics. Don't send or store any personally identifiable information.
|
||||||
# https://docs.brew.sh/Analytics
|
# https://docs.brew.sh/Analytics
|
||||||
# https://developers.google.com/analytics/devguides/collection/protocol/v1/devguide
|
# https://developers.google.com/analytics/devguides/collection/protocol/v1/devguide
|
||||||
# https://developers.google.com/analytics/devguides/collection/protocol/v1/parameters
|
# https://developers.google.com/analytics/devguides/collection/protocol/v1/parameters
|
||||||
if ENV["HOMEBREW_ANALYTICS_DEBUG"]
|
if ENV["HOMEBREW_ANALYTICS_DEBUG"]
|
||||||
url = "https://www.google-analytics.com/debug/collect"
|
url = "https://www.google-analytics.com/debug/collect"
|
||||||
puts "#{ENV["HOMEBREW_CURL"]} #{args.join(" ")} #{url}"
|
puts "#{ENV["HOMEBREW_CURL"]} #{args.join(" ")} #{url}"
|
||||||
puts Utils.popen_read ENV["HOMEBREW_CURL"], *args, url
|
puts Utils.popen_read ENV["HOMEBREW_CURL"], *args, url
|
||||||
else
|
else
|
||||||
pid = fork do
|
pid = fork do
|
||||||
exec ENV["HOMEBREW_CURL"],
|
exec ENV["HOMEBREW_CURL"],
|
||||||
*args,
|
*args,
|
||||||
"--silent", "--output", "/dev/null",
|
"--silent", "--output", "/dev/null",
|
||||||
"https://www.google-analytics.com/collect"
|
"https://www.google-analytics.com/collect"
|
||||||
|
end
|
||||||
|
Process.detach T.must(pid)
|
||||||
end
|
end
|
||||||
Process.detach T.must(pid)
|
|
||||||
end
|
end
|
||||||
|
nil
|
||||||
end
|
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)
|
||||||
|
@ -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