Sha256: 334f08cb12fe16c3ce04552fdc915357291ec4e6359a785e176e7a9ade424639

Contents?: true

Size: 1.85 KB

Versions: 389

Compression:

Stored size: 1.85 KB

Contents

require_relative 'analytics_ingester_client'
require_relative 'action_launch_context'
require_relative 'analytics_event_builder'

module FastlaneCore
  class AnalyticsSession
    GA_TRACKING = "UA-121171860-1"

    private_constant :GA_TRACKING
    attr_accessor :session_id
    attr_accessor :client

    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

    def action_launched(launch_context: nil)
      unless did_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

    def action_completed(completion_context: nil)
    end

    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

    def did_show_message?
      file_name = ".did_show_opt_info"

      new_path = File.join(FastlaneCore.fastlane_user_dir, file_name)
      did_show = File.exist?(new_path)

      return did_show if did_show

      File.write(new_path, '1')
      false
    end

    def finalize_session
      @threads.map(&:join)
    end
  end
end

Version data entries

389 entries across 389 versions & 2 rubygems

Version Path
fastlane-2.129.0.beta.20190729200106 fastlane_core/lib/fastlane_core/analytics/analytics_session.rb
fastlane-2.129.0.beta.20190728200052 fastlane_core/lib/fastlane_core/analytics/analytics_session.rb
fastlane-2.129.0.beta.20190727200032 fastlane_core/lib/fastlane_core/analytics/analytics_session.rb
fastlane-2.129.0.beta.20190726200041 fastlane_core/lib/fastlane_core/analytics/analytics_session.rb
fastlane-2.128.1 fastlane_core/lib/fastlane_core/analytics/analytics_session.rb
fastlane-2.129.0.beta.20190725200033 fastlane_core/lib/fastlane_core/analytics/analytics_session.rb
fastlane-2.129.0.beta.20190723200012 fastlane_core/lib/fastlane_core/analytics/analytics_session.rb
fastlane-2.128.0 fastlane_core/lib/fastlane_core/analytics/analytics_session.rb
fastlane-2.128.0.beta.20190722200021 fastlane_core/lib/fastlane_core/analytics/analytics_session.rb
fastlane-2.128.0.beta.20190721200024 fastlane_core/lib/fastlane_core/analytics/analytics_session.rb
fastlane-2.128.0.beta.20190720200049 fastlane_core/lib/fastlane_core/analytics/analytics_session.rb
fastlane_iac_publish-0.1.5 fastlane_core/lib/fastlane_core/analytics/analytics_session.rb
fastlane-2.127.2 fastlane_core/lib/fastlane_core/analytics/analytics_session.rb
fastlane-2.128.0.beta.20190719200019 fastlane_core/lib/fastlane_core/analytics/analytics_session.rb
fastlane-2.128.0.beta.20190718200101 fastlane_core/lib/fastlane_core/analytics/analytics_session.rb
fastlane-2.128.0.beta.20190717200026 fastlane_core/lib/fastlane_core/analytics/analytics_session.rb
fastlane-2.128.0.beta.20190716200022 fastlane_core/lib/fastlane_core/analytics/analytics_session.rb
fastlane-2.128.0.beta.20190715200056 fastlane_core/lib/fastlane_core/analytics/analytics_session.rb
fastlane-2.128.0.beta.20190714200028 fastlane_core/lib/fastlane_core/analytics/analytics_session.rb
fastlane-2.128.0.beta.20190713200107 fastlane_core/lib/fastlane_core/analytics/analytics_session.rb