Module: Utils::Analytics

Defined in:
brew/Library/Homebrew/utils/analytics.rb,
brew/Library/Homebrew/extend/os/mac/utils/analytics.rb

Class Method Summary collapse

Class Method Details

.clear_os_prefix_ciObject



12
13
14
15
16
# File 'brew/Library/Homebrew/utils/analytics.rb', line 12

def clear_os_prefix_ci
  return unless instance_variable_defined?(:@os_prefix_ci)

  remove_instance_variable(:@os_prefix_ci)
end

.custom_prefix_labelObject



8
9
10
# File 'brew/Library/Homebrew/utils/analytics.rb', line 8

def custom_prefix_label
  "custom-prefix"
end

.os_prefix_ciObject



18
19
20
21
22
23
24
25
# File 'brew/Library/Homebrew/utils/analytics.rb', line 18

def os_prefix_ci
  @os_prefix_ci ||= begin
    os = OS_VERSION
    prefix = ", #{custom_prefix_label}" unless Homebrew.default_prefix?
    ci = ", CI" if ENV["CI"]
    "#{os}#{prefix}#{ci}"
  end
end

.report(type, metadata = {}) ⇒ Object



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# File 'brew/Library/Homebrew/utils/analytics.rb', line 27

def report(type,  = {})
  return if ENV["HOMEBREW_NO_ANALYTICS"] || ENV["HOMEBREW_NO_ANALYTICS_THIS_RUN"]

  args = []

  # do not load .curlrc unless requested (must be the first argument)
  args << "-q" unless ENV["HOMEBREW_CURLRC"]

  args += %W[
    --max-time 3
    --user-agent #{HOMEBREW_USER_AGENT_CURL}
    --data v=1
    --data aip=1
    --data t=#{type}
    --data tid=#{ENV["HOMEBREW_ANALYTICS_ID"]}
    --data cid=#{ENV["HOMEBREW_ANALYTICS_USER_UUID"]}
    --data an=#{HOMEBREW_PRODUCT}
    --data av=#{HOMEBREW_VERSION}
  ]
  .each do |key, value|
    next unless key
    next unless value

    key = ERB::Util.url_encode key
    value = ERB::Util.url_encode value
    args << "--data" << "#{key}=#{value}"
  end

  # Send analytics. Don't send or store any personally identifiable information.
  # https://docs.brew.sh/Analytics
  # https://developers.google.com/analytics/devguides/collection/protocol/v1/devguide
  # https://developers.google.com/analytics/devguides/collection/protocol/v1/parameters
  if ENV["HOMEBREW_ANALYTICS_DEBUG"]
    url = "https://www.google-analytics.com/debug/collect"
    puts "#{ENV["HOMEBREW_CURL"]} #{args.join(" ")} #{url}"
    puts Utils.popen_read ENV["HOMEBREW_CURL"], *args, url
  else
    pid = fork do
      exec ENV["HOMEBREW_CURL"],
           *args,
           "--silent", "--output", "/dev/null",
           "https://www.google-analytics.com/collect"
    end
    Process.detach pid
  end
end

.report_build_error(exception) ⇒ Object



82
83
84
85
86
87
88
89
90
91
92
# File 'brew/Library/Homebrew/utils/analytics.rb', line 82

def report_build_error(exception)
  return unless exception.formula.tap
  return unless exception.formula.tap.installed?
  return if exception.formula.tap.private?

  action = exception.formula.full_name
  if (options = exception.options&.to_a&.join(" "))
    action = "#{action} #{options}".strip
  end
  report_event("BuildError", action)
end

.report_event(category, action, label = os_prefix_ci, value = nil) ⇒ Object



74
75
76
77
78
79
80
# File 'brew/Library/Homebrew/utils/analytics.rb', line 74

def report_event(category, action, label = os_prefix_ci, value = nil)
  report(:event,
         ec: category,
         ea: action,
         el: label,
         ev: value)
end