Skip to content

How to Track AI Visit

Not every request to your site comes from a person using a browser. Some web requests are generated by automated clients, including AI-related traffic. They may fetch pages, read content, collect data, train on published material from your site, or summarize it for their users somewhere else.

These clients usually identify themselves through the user-agent string. UAParser.js helps you parse these user-agent strings into structured data using a maintained rule set, it also provides helper functions to classify known automated clients. This makes it possible to distinguish AI-related traffic from regular browsers and other types of bots.

Code Example

js
import { isAICrawler, isAIAssistant } from 'ua-parser-js/bot-detection';

const ua = req.headers['user-agent'];

if (isAICrawler(ua)) {
    console.log('Hello, AI Crawler!');
} 

if (isAIAssistant(ua)) {
    console.log('Hello, AI Assistant!');
}

LIMITATION

This detection method relies on the declared user-agent string. It works only when clients clearly identify themselves, but it can't reliably detect clients that impersonate regular browsers.

References:

UAParser.js v2 is licensed under AGPLv3 or PRO licenses.