This document provides instructions on how to use VisitorAPI in React to detect a user’s location, currencies, languages and device info. The information will be stored in states to be used in your React application.
Installing VisitorAPI with NPM
You can install VisitorAPI with NPM with the following command:
Calling VisitorAPI in React
The example code snippet below calls the API.
The VisitorAPI function parameters:
- Project ID: This is a string that refers to your project in your VisitorAPI projects.
- Success Handler: This is a function to handle the return data in JSON format when the API is called successfully. For details, please see Visitor Data.
- Error Handler: This is a function to handle errors.
Example: Use VisitorAPI to populate state variables
In this example, there are multiple state variables to store the returned data and you can use any of them in your code to control the logic