Class: FastlaneCore::AnalyticsIngesterClient

Inherits:
Object
  • Object
show all
Defined in:
fastlane_core/lib/fastlane_core/analytics/analytics_ingester_client.rb

Instance Method Summary collapse

Constructor Details

#initialize(ga_tracking) ⇒ AnalyticsIngesterClient

Returns a new instance of AnalyticsIngesterClient.



13
14
15
# File 'fastlane_core/lib/fastlane_core/analytics/analytics_ingester_client.rb', line 13

def initialize(ga_tracking)
  @ga_tracking = ga_tracking
end

Instance Method Details

#post_event(event) ⇒ Object



17
18
19
20
21
22
23
24
25
26
# File 'fastlane_core/lib/fastlane_core/analytics/analytics_ingester_client.rb', line 17

def post_event(event)
  # If our users want to opt out of usage metrics, don't post the events.
  # Learn more at https://docs.fastlane.tools/#metrics
  if Helper.test? || FastlaneCore::Env.truthy?("FASTLANE_OPT_OUT_USAGE")
    return nil
  end
  return Thread.new do
    send_request(event)
  end
end

#post_request(event) ⇒ Object



35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'fastlane_core/lib/fastlane_core/analytics/analytics_ingester_client.rb', line 35

def post_request(event)
  connection = Faraday.new(GA_URL) do |conn|
    conn.request(:url_encoded)
    conn.adapter(Faraday.default_adapter)
  end
  connection.headers[:user_agent] = 'fastlane/' + Fastlane::VERSION
  connection.post("/collect", {
    v: "1",                                            # API Version
    tid: @ga_tracking,                                 # Tracking ID / Property ID
    cid: event[:client_id],                            # Client ID
    t: "event",                                        # Event hit type
    ec: event[:category],                              # Event category
    ea: event[:action],                                # Event action
    el: event[:label] || "na",                         # Event label
    ev: event[:value] || "0",                          # Event value
    aip: "1"                                           # IP anonymization
  })
end

#send_request(event, retries: 2) ⇒ Object



28
29
30
31
32
33
# File 'fastlane_core/lib/fastlane_core/analytics/analytics_ingester_client.rb', line 28

def send_request(event, retries: 2)
  post_request(event)
rescue
  retries -= 1
  retry if retries >= 0
end