FrontEnd web
Published in

FrontEnd web

How to track bot in your next.js website
Photo by Brett Jordan on Unsplash

Nextjs + bot + short tips

How to track the bot on your next.js website?

Nowadays, bots are used everywhere on IoT. Bots help to manage tasks without human interfaces. Bots work 24*7 for business. You create a bot only once based on your requirements, and there manages lots of people daily.

For example, send an automatic notification with WhatsApp, email, and message.

A real-life example is lots of company use bots to handle a client query or chant bots.

The basics of a working bot divide into two categories. The first is a good bot, and the second is a bad bot.

Good bots always help grow your business—bots help automate specific tasks that are boring for humans and increase human productivity.

Other hands, bad bots create a lot of trouble for businesses or website owners. In my case, some people use bots to copy my articles and show them on our website, and the second big problem is some people use boots to increase website traffic. It is a big problem because you face a resource shortage problem.

Recently I faced a similar problem with my website. Someone used bad bots to send a lot of traffic to my website. I know traffic is good but over and fake traffic is not suitable for a website. So at the end of the month, I face many google cloud bills in my hand.

A similar problem was faced by one of my readers, and in this article, we discuss how to track good or bad bots in nextjs and try to protect the nextjs website and resources.

I give a small overview of bot detection in nextjs and tell you some websites that provide you with a bot detection service.

What are good and bad bots?

The base on the trust, we divided bots into two categories. Sometimes the trust point of view changes from person to person.


Good bots help our business without any harm that considers good bots. The common good bots example is Googlebot, Bingbot, DuckDuckBot, etc.


The bad bots do not help to grow our business and burn our resources. The ordinary bad bots are content scraping bots, spam bots, click fraud bots, etc.

Let's start

  1. Track good bots
  2. Track bad bots

Track good bots

Nextjs provide an inbuilt method to track good bot on the website. To track a good bot in nextjs, we use nextjs middleware. With the help of nextjs middleware in-built the isBot method, we track good bots.

Example of isBot in nextjs

// middleware.jsimport { NextResponse, userAgent } from 'next/server'export function middleware(request,_event) {// access isBot method
const {isBot} = userAgent(request)
// isBot return true

Nextjs isBot method checks the following bots like Googlebot, Media partners-Google, AdsBot-Google, google web light, Storebot-Google, GooglePageRenderer, Bingbot, BingPreview, Slurp, DuckDuckBot, Baidu spider, Yandex, Sogou, LinkedInBot, bitlybot, tumble, vkShare, quora link preview, facebook external hit, facebook catalogue, Twitterbot, apple bot, Reddit bot, Slackbot, Discordbot, WhatsApp, SkypeUriPreview, ia_archiver. All the bots checked by the isBot method are good, trustworthy, and created by big organizations.

Track bad bots

The nextjs track only good bots, but the nextjs do not track bad bots. Track the bad bots Detection provider helps to detect bots.

If you build a full-bots secure app, I recommend using one of the following and any service providers according to your requirement.

  1. Radware
  2. Datadome
  3. Fingerprint


You can build a startup website. I recommended using one bots protection service on your website. Building bots from scratch. It is such so difficult and time-consuming process. Bots detection services help protect the website from fake traffic and save resources I face on my website.

I provide an overview of the bots detection problems with nextjs or any other frontend framework that comes, and I tell you that some companies offer solutions to your website. However, make sure all service is not free and comes with a paid and free plan. Some websites give a free plan for one week or one month.

You can share and follow us on Twitter and Linkedin. If you like my work, please read more content on the officialrajdeepsingh. dev, frontend web, and sign up for a free newsletter on the frontend web.




Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Rajdeep singh

JavaScript || Reactjs || Nextjs || Python || Rust || Biotechnology || Bioinformatic || Front-end Developer || Writer ||