JavaScript SDK
The visitorapi npm package is the core JavaScript SDK for VisitorAPI. It works in any JavaScript environment — browser, Node.js, or bundled apps.
Source and issue tracker: github.com/visitorapi/visitorapi.js
Installation
npm install visitorapi
Usage — Promise API
const VisitorAPI = require("visitorapi");
VisitorAPI("your-project-id")
.then(data => {
console.log(data.countryCode);
})
.catch(error => {
// handle error
});
Usage — Callback API
const VisitorAPI = require("visitorapi");
VisitorAPI(
"your-project-id",
data => {
console.log(data.countryCode);
},
error => {
// handle error
}
);
Your project ID is available in the VisitorAPI dashboard.
Available data fields
| Field | Description |
|---|---|
ipAddress | IP address of the visitor |
countryCode | ISO 3166-1 alpha-2 country code (e.g. "US") |
countryName | Full country name (e.g. "United States") |
region | State, region, or province name |
city | City name |
cityLatLong | Latitude and longitude of the city centre |
currencies | Array of official currencies for the visitor’s country |
languages | Array of official languages for the visitor’s country |
browser | Browser name (e.g. "Chrome") |
browserVersion | Browser version string |
deviceBrand | Device brand — mobile only (e.g. "Apple") |
deviceModel | Device model — mobile only (e.g. "iPhone") |
deviceFamily | Device family — mobile only (e.g. "iPhone") |
os | Operating system name (e.g. "iOS") |
osVersion | Operating system version string |
Common use cases
- Currency localisation — auto-select the visitor’s currency at checkout
- Geo-targeting — show region-specific content or pricing