Sha256: 44ef9bf88565f42a04167fc31d642e9af97114d793cae179a20eb4fd4e3fb470

Contents?: true

Size: 995 Bytes

Versions: 44

Compression:

Stored size: 995 Bytes

Contents

require "user_agent_parser"

module ThinkFeelDoEngine
  module Reports
    # Scenario: a Participant accesses the site with a unique user agent.
    class UserAgent
      def self.columns
        %w( participant_id user_agent_family user_agent_version user_agent_os )
      end

      def self.all
        Participant.select(:id, :study_id).map do |participant|
          user_agents = EventCapture::Event
                        .where(participant_id: participant.id)
                        .map { |event| event.payload[:ua] }
                        .uniq

          user_agents.map do |agent|
            ua = UserAgentParser.parse(agent)
            next if ua.family == "Other" && ua.version.to_s == ""

            {
              participant_id: participant.study_id,
              user_agent_family: ua.family,
              user_agent_version: ua.version.to_s,
              user_agent_os: ua.os.to_s
            }
          end
        end.flatten.compact
      end
    end
  end
end

Version data entries

44 entries across 44 versions & 1 rubygems

Version Path
think_feel_do_engine-3.10.9 app/models/think_feel_do_engine/reports/user_agent.rb
think_feel_do_engine-3.10.8 app/models/think_feel_do_engine/reports/user_agent.rb
think_feel_do_engine-3.10.7 app/models/think_feel_do_engine/reports/user_agent.rb
think_feel_do_engine-3.10.6 app/models/think_feel_do_engine/reports/user_agent.rb