Skip to content

parse_user_agent

parse_user_agent(user_agent_string)

Description

Parses User Agent strings into several components

Usage

Call or Deploy parse_user_agent ?
Call parse_user_agent directly

The easiest way to use bigfunctions

  • parse_user_agent function is deployed in 39 public datasets for all of the 39 BigQuery regions.
  • It can be called by anyone. Just copy / paste examples below in your BigQuery console. It just works!
  • (You need to use the dataset in the same region as your datasets otherwise you may have a function not found error)

Public BigFunctions Datasets

Region Dataset
eu bigfunctions.eu
us bigfunctions.us
europe-west1 bigfunctions.europe_west1
asia-east1 bigfunctions.asia_east1
... ...
Deploy parse_user_agent in your project

Why deploy?

  • You may prefer to deploy parse_user_agent in your own project to build and manage your own catalog of functions.
  • This is particularly useful if you want to create private functions (for example calling your internal APIs).
  • Get started by reading the framework page

Deployment

parse_user_agent function can be deployed with:

pip install bigfunctions
bigfun get parse_user_agent
bigfun deploy parse_user_agent

Examples

Mobile User Agent

select bigfunctions.eu.parse_user_agent("Mozilla/5.0 (Linux; Android 12; SM-S906N Build/QP1A.190711.020; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/80.0.3987.119 Mobile Safari/537.36")
select bigfunctions.us.parse_user_agent("Mozilla/5.0 (Linux; Android 12; SM-S906N Build/QP1A.190711.020; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/80.0.3987.119 Mobile Safari/537.36")
select bigfunctions.europe_west1.parse_user_agent("Mozilla/5.0 (Linux; Android 12; SM-S906N Build/QP1A.190711.020; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/80.0.3987.119 Mobile Safari/537.36")
+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| parsed_user_agent                                                                                                                                                                                                                                                                                           |
+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| STRUCT<STRUCT<'Chrome WebView' as name, '80.0.3987.119' as version, '80' as major> as browser, STRUCT<'Blink' as name, '80.0.3987.119' as version> as engine, STRUCT<'Android' as name, '12' as version> as os, STRUCT<'Samsung' as vendor, 'SM-S906N' as model, 'mobile' as type> as device, null as arch> |
+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+

Use cases

A website analytics team could use the parse_user_agent function to analyze website traffic and user behavior. Here's a breakdown of how they might use it:

Scenario: The team wants to understand which browsers are most popular among their users, identify trends in mobile device usage, and optimize the website experience for different operating systems. They have a BigQuery table containing website access logs, including a column with user agent strings.

Use Case with BigQuery SQL:

SELECT
    parsed_user_agent.browser.name AS browser_name,
    parsed_user_agent.browser.version AS browser_version,
    parsed_user_agent.os.name AS os_name,
    parsed_user_agent.os.version AS os_version,
    parsed_user_agent.device.model AS device_model,
    parsed_user_agent.device.type AS device_type,
    COUNT(*) AS access_count
  FROM
    `your_project.your_dataset.website_access_logs`,
    UNTABLE(bigfunctions.your_region.parse_user_agent(user_agent) AS parsed_user_agent)
  GROUP BY 1, 2, 3, 4, 5, 6
  ORDER BY access_count DESC;
(Replace your_project.your_dataset.website_access_logs and your_region with your actual values.)

Benefits:

  • Browser Statistics: By aggregating results by browser_name and browser_version, the team can determine the market share of different browsers accessing their website. This helps in prioritizing browser compatibility testing and ensuring a consistent user experience.

  • Mobile Device Insights: Grouping by device_model and device_type reveals which mobile devices are commonly used to visit the site. This information is valuable for responsive design and mobile optimization efforts.

  • Operating System Analysis: Analyzing data based on os_name and os_version allows the team to identify potential compatibility issues or optimize the website for specific operating systems.

  • Targeted Improvements: By understanding the breakdown of user agents, the team can make data-driven decisions about website improvements. For example, if a significant portion of users are on older versions of a specific browser, they might choose to display a message encouraging them to update for better performance and security.

  • Troubleshooting: If there's a sudden spike in errors from a specific browser or device, the parsed user agent data helps pinpoint the problem quickly.

This use case demonstrates how the parse_user_agent function empowers the analytics team to gain valuable insights from raw user agent data within BigQuery, leading to informed decisions about website development and optimization.


Need help or Found a bug?
Get help using parse_user_agent

The community can help! Engage the conversation on Slack

We also provide professional suppport.

Report a bug about parse_user_agent

If the function does not work as expected, please

  • report a bug so that it can be improved.
  • or open the discussion with the community on Slack.

We also provide professional suppport.


Show your ❤ by adding a ⭐ on