Browser Analytics with the User Agent Parser API

Understanding which browsers, operating systems, and devices your users rely on helps you make informed decisions about compatibility, testing priorities, and feature support. Instead of adding a third-party analytics script to your frontend, you can parse User-Agent strings from your server logs with the Apixies User Agent Inspector API and build your own lightweight browser analytics dashboard.

Why Parse UA Strings Server-Side?

Client-side analytics (Google Analytics, Plausible, etc.) miss a surprising amount of traffic:

Scenario Client-Side Server-Side UA Parsing
Ad blockers enabled Missed Captured
JavaScript disabled Missed Captured
Bot traffic Partially tracked Fully classified
API consumers (no browser) Invisible Captured
Privacy-conscious users Often blocked Always available

Server-side UA parsing gives you complete coverage and lets you keep the data in your own infrastructure.

Building a Browser Analytics Pipeline

Step 1 -- Collect UA Strings from Logs

Most web servers log the User-Agent header. Extract the unique UA strings you want to analyze:

# Extract unique UA strings from an Nginx access log
awk -F'"' '{print $6}' /var/log/nginx/access.log | sort -u > unique_uas.txt

Step 2 -- Parse Each UA via the API

import requests
import os
from collections import Counter

api_key = os.environ["APIXIES_KEY"]

def parse_ua(ua_string):
    response = requests.get(
        "https://apixies.io/api/v1/inspect-user-agent",
        params={"user_agent": ua_string},
        headers={"X-API-Key": api_key},
    )
    response.raise_for_status()
    return response.json()["data"]

# Read UA strings from a file or database
with open("unique_uas.txt") as f:
    ua_strings = [line.strip() for line in f if line.strip()]

browsers = Counter()
os_families = Counter()
devices = Counter()
bot_count = 0

for ua in ua_strings:
    parsed = parse_ua(ua)

    if parsed["is_bot"]:
        bot_count += 1
        continue

    browsers[f"{parsed['browser']['family']} {parsed['browser']['major']}"] += 1
    os_families[parsed["os"]["family"]] += 1
    devices[parsed["device"]["family"]] += 1

print("Top Browsers:", browsers.most_common(10))
print("Top OS:", os_families.most_common(5))
print("Devices:", devices.most_common(5))
print(f"Bots filtered: {bot_count}")

Step 3 -- Real-Time Dashboard (Node.js + Express)

Parse UA strings on every request and aggregate the data:

const stats = {
  browsers: {},
  os: {},
  devices: {},
  bots: 0,
  total: 0,
};

app.use(async (req, res, next) => {
  stats.total++;

  const ua = req.headers["user-agent"] || "";
  try {
    const url = new URL("https://apixies.io/api/v1/inspect-user-agent");
    url.searchParams.set("user_agent", ua);

    const response = await fetch(url, {
      headers: { "X-API-Key": process.env.APIXIES_KEY },
    });
    const { data } = await response.json();

    if (data.is_bot) {
      stats.bots++;
    } else {
      const browser = `${data.browser.family} ${data.browser.major}`;
      stats.browsers[browser] = (stats.browsers[browser] || 0) + 1;
      stats.os[data.os.family] = (stats.os[data.os.family] || 0) + 1;
      stats.devices[data.device.family] =
        (stats.devices[data.device.family] || 0) + 1;
    }
  } catch {
    // Fail silently -- analytics shouldn't break the request
  }

  next();
});

// Expose stats as an internal API
app.get("/internal/analytics", (req, res) => {
  res.json(stats);
});

Step 4 -- Generate a Report

Turn the aggregated data into a summary:

def generate_report(browsers, os_families, devices, bot_count, total):
    print(f"\n{'='*50}")
    print(f"Browser Analytics Report")
    print(f"{'='*50}")
    print(f"Total requests: {total}")
    print(f"Bots filtered:  {bot_count} ({bot_count/total*100:.1f}%)")
    print(f"Human traffic:  {total - bot_count}")

    print(f"\n--- Top Browsers ---")
    for browser, count in browsers.most_common(10):
        pct = count / (total - bot_count) * 100
        bar = "█" * int(pct / 2)
        print(f"  {browser:30s} {count:6d} ({pct:5.1f}%) {bar}")

    print(f"\n--- Operating Systems ---")
    for os_name, count in os_families.most_common(5):
        pct = count / (total - bot_count) * 100
        print(f"  {os_name:30s} {count:6d} ({pct:5.1f}%)")

    print(f"\n--- Device Types ---")
    for device, count in devices.most_common(5):
        pct = count / (total - bot_count) * 100
        print(f"  {device:30s} {count:6d} ({pct:5.1f}%)")

Practical Insights from UA Analytics

Once you have browser and OS data, you can make concrete decisions:

  • Drop IE 11 support? Check if any traffic still comes from it.
  • Prioritize mobile? See the desktop/mobile/tablet split.
  • Safari testing? Know the exact Safari versions in your traffic.
  • Deprecate old APIs? See which client versions are still active.
  • Content negotiation -- Serve WebP to Chrome, AVIF where supported.

Next Steps

Get your free API key and start building your browser analytics dashboard.

Try the User Agent Inspector API

Free tier is for development & small projects. 75 requests/day with a registered account.

Getting Started

Explore

Resources

Get Started Free

Free for development and small projects.

Get Free API Key