Overview
This tutorial walks through implementing Fingerprint to prevent web scraping, where bots attempt to extract proprietary or sensitive data from your website automatically. You’ll begin with a starter app that includes a mock flight search page and a basic querying flow. From there, you’ll add the Fingerprint JavaScript agent to identify each visitor and use server-side logic with Fingerprint data to detect and block automated scraping attempts. By the end, you’ll have a sample app that blocks bot-driven data scraping and can be customized to fit your use case and access control policies. This tutorial uses just plain JavaScript and a Node server with SQLite on the back end. For language- or framework-specific setups, see our quickstarts.Estimated time: < 15 minutes
This tutorial requires the Bot Detection Smart Signal, which is only available
on paid plans.
Prerequisites
Before you begin, make sure you have the following:- A copy of the starter repository (clone with Git or download as a ZIP)
- Node.js (v20 or later) and npm installed
- Your favorite code editor
- Basic knowledge of JavaScript
1. Create a Fingerprint account and get your API keys
- Sign up for a free Fingerprint trial, or log in if you already have an account.
- After signing in, go to the API keys page in the dashboard.
- Save your public API key, which you’ll use to initialize the Fingerprint JavaScript agent.
- Create and securely store a secret API key for your server. Never expose it on the client side. You’ll use this key on the backend to retrieve full visitor information through the Fingerprint Server API.
2. Set up your project
- Clone or download the starter repository and open it in your editor.
Terminal
- This tutorial will be using the
web-scrapingfolder. The project is organized as follows:
Project structure
- Install dependencies:
Terminal
- Copy or rename
.env.exampleto.env, then add your Fingerprint API keys:
Terminal
- Start the server:
Terminal
- Visit http://localhost:3000 to view the mock flight search page from the starter app. Try a sample query (for example, SFO to MIA) and click Search.
- Then try to search for flights using the included headless bot test script
test-bot.js. While the app is running, executenode test-bot.jsand observe that the automated search request returns all results. By default, the server does not distinguish between bots and real users.
Terminal
3. Add Fingerprint to the front end
In this step, you’ll load the Fingerprint client when the page loads and trigger identification when the user clicks Search. The client returns arequestId associated with the identification request. You’ll send the requestId to your server along with the search inputs. Your server will then call the Fingerprint Events API to securely retrieve the full identification details, including bot detection and other signals.
- At the top of
public/index.js, load the Fingerprint JavaScript agent:
public/index.js
- Make sure to change
regionto match your workspace region (e.g.,eufor Europe,apfor Asia,usfor Global (default)). - Near the bottom of
public/index.js, the Search button already has an event handler for submitting the query. Inside this handler, request visitor identification usingget()and include the returnedrequestIdwhen sending the search request to the server:
public/index.js
get() method sends signals collected from the browser to Fingerprint servers, where they are analyzed to identify the visitor and determine if they are a bot. The returned requestId acts as a reference to this specific identification event, which your server can later use to fetch the full visitor details.
For lower latency in production, check out our documentation on using Sealed Client Results to return full identification details as an encrypted payload from the get() method.
4. Receive and use the request ID to get visitor insights
Next, pass therequestId through to your flight search logic, initialize the Fingerprint Server API client, and fetch the full visitor identification event so you can access the Bot Detection Smart Signal.
- In the back end, the
server/server.jsfile already defines API routes for the app. Notice that the/api/fetch-flightsroute simply passes the request body to afetchFlightsfunction that is defined in theserver/flights.jsfile.
server/server.js
- The
server/flights.jsfile contains the logic for handling flight searches. Start by importing and initializing the Fingerprint Server API client there, and load your environment variables withdotenv.
server/flights.js
- Make sure to change
regionto match your workspace region (e.g.,EUfor Europe,APfor Asia,Globalfor Global (default)). - Update the
fetchFlightsfunction to accept therequestIdand use it to fetch the full identification event details from Fingerprint:
server/flights.js
requestId, the Fingerprint server client will retrieve the full data for the visitor identification request. The returned object will contain the visitor ID, IP address, device, and browser details, as well as Smart Signals, including bot detection, browser tampering detection, VPN detection, and more.
You can see a full example of the event structure and test it with your own device in our demo playground.
For additional checks to ensure the validity of the data coming from your front end, view how to protect from client-side tampering and replay attacks in our documentation.
5. Block content scraping bots
Web scraping relies on automated requests, so rejecting bots outright helps protect proprietary data. Fingerprint returnsnotDetected if no bot activity is found, good for known bots, like search engines, and bad for other automation tools. Any visitor identification that does not return notDetected can be blocked from retrieving flight data.
- Continuing in the
fetchFlightsfunction inserver/flights.js, check the bot signal returned in theeventobject and block bots:
server/flights.js
- Below the bot detection check, add a condition that reads the Suspect Score from the
eventobject and blocks the search if it exceeds a chosen threshold (for example, 20):
server/flights.js
This is a minimal example to show how to implement Fingerprint. In a real
application, make sure to implement proper security practices, error handling,
and access controls that align with your production standards.
7. Test your implementation
Now that everything is wired up, you can test the full protected search flow.- Start your server if it isn’t already running and open http://localhost:3000:
Terminal
- Try a normal search (for example, SFO to JFK). You should get matching flights returned.
- Next, run the included headless bot test script. While the app is running, execute
node test-bot.jsand observe that the automated search requests do not return any results and the bot’s access is blocked.
Terminal
Terminal