← Back
Track Pageviews With the Node.js SDK
Step 1: Install the NPM Package
Download and include the package via NPM:
npm install @knownagents/sdk
Step 2: Initialize the Client
In your code, create an instance of KnownAgents with your project's access token.
import { KnownAgents } from "@knownagents/sdk"
const knownAgents = new KnownAgents("YOUR_ACCESS_TOKEN")
- Navigate to the Known Agents Projects page and open your project
- Copy your access token from the Settings page
- Back in your code, swap in your access token where it says
YOUR_ACCESS_TOKEN
Step 3: Track Pageviews
Call trackVisit with the incoming request and outgoing response. If you can, do this in middleware.
knownAgents.trackVisit(request, response)
Step 4: Test Your Integration
- Navigate to the Projects page
- Select your project
- Click Settings
- Click Send a Test Visit
- Click Realtime
If your website is correctly connected, you should see visits from a test agent in the realtime timeline within a few seconds.