User Agent Strings

I would like help with Quicksight formula to parse through a user agent string. My field user_agent has strings in the format “Mozilla/5.0 (iPhone; CPU iPhone OS 11_0 like Mac OS X) AppleWebKit/604.1.38 (KHTML, like Gecko) Version/17.4 Mobile/15A372 Safari/604.1”. I am trying to extract the Browser from those in a created field in the dataset. Has anyone encountered this type of challenge before?

1 Like

Hello @Moca6lack, welcome to the QuickSight community!

If you know all of the browsers that you would want to check for in the field, you could use contains function to check which browser is mentioned and return values based on the conditional that returns true. It would look something like this:

ifelse(
contains({user_agent}, 'Mozilla', CASE_INSENSITIVE), 'Mozilla',
contains({user_agent}, 'Safari', CASE_INSENSITIVE), 'Safari',
contains({user_agent}, 'Chrome', CASE_INSENSITIVE), 'Chrome',
contains({user_agent}, 'Opra', CASE_INSENSITIVE), 'Opra',
NULL
)

This isn’t the most dynamic logic, but something like this would return the values you are looking for. Let me know if this helps!

Hello @Moca6lack, since we have not heard back from you, I will mark my previous response as the solution. Please let me know if you have any remaining questions on this topic and I can guide you further. Thank you!