class FastlaneCore::AnalyticsSession

Constants

GA_TRACKING

Attributes

client[RW]
session_id[RW]

Public Class Methods

new(analytics_ingester_client: AnalyticsIngesterClient.new(GA_TRACKING)) click to toggle source
# File fastlane_core/lib/fastlane_core/analytics/analytics_session.rb, line 13
def initialize(analytics_ingester_client: AnalyticsIngesterClient.new(GA_TRACKING))
  require 'securerandom'
  @session_id = SecureRandom.uuid
  @client = analytics_ingester_client
  @threads = []
  @launch_event_sent = false
end

Public Instance Methods

action_completed(completion_context: nil) click to toggle source
# File fastlane_core/lib/fastlane_core/analytics/analytics_session.rb, line 45
def action_completed(completion_context: nil)
end
action_launched(launch_context: nil) click to toggle source
# File fastlane_core/lib/fastlane_core/analytics/analytics_session.rb, line 21
def action_launched(launch_context: nil)
  if should_show_message?
    show_message
  end

  if @launch_event_sent || launch_context.p_hash.nil?
    return
  end

  @launch_event_sent = true
  builder = AnalyticsEventBuilder.new(
    p_hash: launch_context.p_hash,
    session_id: session_id,
    action_name: nil,
    fastlane_client_language: launch_context.fastlane_client_language
  )

  launch_event = builder.new_event(:launch)
  post_thread = client.post_event(launch_event)
  unless post_thread.nil?
    @threads << post_thread
  end
end
finalize_session() click to toggle source
# File fastlane_core/lib/fastlane_core/analytics/analytics_session.rb, line 66
def finalize_session
  @threads.map(&:join)
end
should_show_message?() click to toggle source
# File fastlane_core/lib/fastlane_core/analytics/analytics_session.rb, line 55
def should_show_message?
  return false if FastlaneCore::Env.truthy?("FASTLANE_OPT_OUT_USAGE")

  file_name = ".did_show_opt_info"
  new_path = File.join(FastlaneCore.fastlane_user_dir, file_name)
  return false if File.exist?(new_path)

  File.write(new_path, '1')
  true
end
show_message() click to toggle source
# File fastlane_core/lib/fastlane_core/analytics/analytics_session.rb, line 48
def show_message
  UI.message("Sending anonymous analytics information")
  UI.message("Learn more at https://docs.fastlane.tools/#metrics")
  UI.message("No personal or sensitive data is sent.")
  UI.message("You can disable this by adding `opt_out_usage` at the top of your Fastfile")
end