Skip to content

Commit

Permalink
Better user agents for some special cases
Browse files Browse the repository at this point in the history
  • Loading branch information
ujh committed Jan 7, 2025
1 parent 2d58cae commit e26efea
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
10 changes: 9 additions & 1 deletion app/controllers/application_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,18 @@ def set_time_zone
end
end

USER_AGENT_PARSER =
UserAgentParser::Parser.new(
patterns_paths: [
UserAgentParser::DefaultPatternsPath,
Rails.root.join("config/user_agents.yml")
]
)

def save_user_agent
user_agent = request.user_agent
UserAgent.create(
name: UserAgentParser.parse(user_agent).family,
name: USER_AGENT_PARSER.parse(user_agent).family,
raw_name: user_agent,
day: Date.current
)
Expand Down
10 changes: 10 additions & 0 deletions config/user_agents.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
user_agent_parsers:
- regex: "Consul Health Check"
family_replacement: "Consul Health Check"
- regex: "Honeybadger Uptime Check"
family_replacement: "Honeybadger Uptime Check"
- regex: "Reeder"
family_replacement: "Reeder"

os_parsers: []
device_parsers: []

0 comments on commit e26efea

Please sign in to comment.