add desktop/mobile/tablet badges to events log

This commit is contained in:
Alex Turchyn
2025-10-22 14:11:17 +03:00
committed by Pete Matsyburka
parent 7ec3282b56
commit c8fe36a2b6
6 changed files with 74 additions and 3 deletions
+25
View File
@@ -0,0 +1,25 @@
# frozen_string_literal: true
module DetectBrowserDevice
module_function
# rubocop:disable Metrics/LineLength
MOBILE_USER_AGENT_REGEXP = /iPhone|iPod|Android.*Mobile|Opera Mini|Opera Mobi|webOS|IEMobile|Windows Phone|BlackBerry|BB10|Mobile/i
TABLET_USER_AGENT_REGEXP = /iPad|Android(?!.*Mobile)|Tablet|Kindle|PlayBook|Silk/i
# rubocop:enable Metrics/LineLength
def call(user_agent)
return :mobile if mobile?(user_agent)
return :tablet if tablet?(user_agent)
:desktop
end
def mobile?(user_agent)
user_agent.to_s =~ MOBILE_USER_AGENT_REGEXP
end
def tablet?(user_agent)
user_agent.to_s =~ TABLET_USER_AGENT_REGEXP
end
end