or run

npx @tessl/cli init
Log in

Version

Files

tile.json

task.mdevals/scenario-10/

Traffic Analyzer

Build a traffic analyzer utility that identifies and categorizes automated bots and crawlers from website traffic logs.

Requirements

Your utility should process User-Agent strings from HTTP requests and distinguish between human users and automated traffic. The system needs to:

  1. Identify bot traffic: Determine if a given User-Agent string represents a bot or crawler
  2. Extract bot information: When a bot is detected, extract its vendor/owner information
  3. Categorize traffic: Classify requests into human traffic vs bot traffic
  4. Generate statistics: Count how many requests come from bots versus regular browsers

Implementation

@generates

Create a module that exports the following functions:

API

/**
 * Analyzes a User-Agent string to determine if it represents a bot or crawler.
 *
 * @param {string} userAgent - The User-Agent string to analyze
 * @returns {boolean} true if the User-Agent represents a bot, false otherwise
 */
function isBot(userAgent) {
  // IMPLEMENTATION HERE
}

/**
 * Extracts bot vendor information from a User-Agent string.
 * Returns null if the User-Agent is not from a bot.
 *
 * @param {string} userAgent - The User-Agent string to analyze
 * @returns {string|null} The bot vendor name, or null if not a bot
 */
function getBotVendor(userAgent) {
  // IMPLEMENTATION HERE
}

/**
 * Analyzes an array of User-Agent strings and returns statistics
 * about bot vs human traffic.
 *
 * @param {string[]} userAgents - Array of User-Agent strings
 * @returns {Object} Statistics with botCount, humanCount, and totalCount
 */
function analyzeTraffic(userAgents) {
  // IMPLEMENTATION HERE
}

module.exports = {
  isBot,
  getBotVendor,
  analyzeTraffic,
};

Tests

  • It correctly identifies Googlebot as a bot @test
  • It correctly identifies a regular Chrome browser as not a bot @test
  • It extracts the vendor for a known bot @test
  • It returns null vendor for non-bot User-Agents @test
  • It correctly counts bot and human traffic in a mixed set @test

Dependencies { .dependencies }

bowser { .dependency }

Provides browser and bot detection capabilities from User-Agent strings.