Get Started

Visitor API is REST API that delivers website visitor’s IP address, location, currencies, languages, and device information for the website’s JavaScript to use the data to personalize the user experience.

Load Visitor API

Copy and paste the following code snippet to your web pages which requires the visitor data:

var VisitorAPI=function(t,e,a){var s=new XMLHttpRequest;s.onreadystatechange=function(){var t;s.readyState===XMLHttpRequest.DONE&&(200===(t=JSON.parse(s.responseText)).status?e(t.data):a(t.status,t.result))},s.open("GET","https://api.visitorapi.com/api/?pid="+t),s.send(null)};

Call Visitor API

You can then call Visitor API with the syntax below:

new VisitorAPI(projectID, successHandler, errorHandler);

The function accepts three parameters:

ParameterDescriptionExample Value
projectIDUnique identifier of the project created in VisitorAPI interface“om61tWZOjuBBPxTdDlpy”
successHandlerFunction to process visitor data on successful API callfunction(data){console.log(data)}
errorHandlerFunction to handle error code and message on API call failurefunction(errorCode, errorMessage){console.log(errorCode, errorMessage)}

Below is a full example of loading VisitoAPI and calling the API to output the visitor data in the console when the API call is successful, or to output the error code and error message when the API call returns an error:

var VisitorAPI=function(t,e,a){var s=new XMLHttpRequest;s.onreadystatechange=function(){var t;s.readyState===XMLHttpRequest.DONE&&(200===(t=JSON.parse(s.responseText)).status?e(t.data):a(t.status,t.result))},s.open("GET","https://api.visitorapi.com/api/?pid="+t),s.send(null)};

VisitorAPI(
    "om61tWZOjuBBPxTdDlpy",
    function(data){console.log(data)},
    function(errorCode, errorMessage){console.log(errorCode, errorMessage)}
);