This package was built to manage recurrent functionalities during development of interfaces. The idea is to allow a developer collect these user data and use as appropriately say built a dashboard to manage the data and subesequently make informed decisions. E.g. these data can be collected and sent to the server for analytics purposes. So, a developer can quickly :
- get a user Location (Country and City) by using the
useGetUserLocation
Hook. - get the type of Device (mobile/desktop) a user is using to access the application by using the
useUserDevice
Hook. - get a user current navigation page by using the
useUserNavigation
Hook. - check if a is a unique visitor or otherwise by using the
useIsUserUnique
Hook.
NB: useIsUserUnique
is just client side and that clearing the localstorage invaidates someone as a unique user and that server implementation is recommended.
Install this library:
npm i @todak2000/react-user-analytics
# or
yarn add @todak2000/react-user-analytics
Then, import and use any of the functionalities you might require:
...
import {
useGetUserLocation,
useUserDevice,
useIsUserUnique,
useUserNavigation,
} from '@todak2000/react-user-analytics';
function SampleApp() {
const {country, city} = useGetUserLocation();
const uniqueUser:boolean = useIsUserUnique();
const nav: string = useUserNavigation();
const device: string = useUserDevice();
return (
<div >
<header >
<p>You are currently in {city}, {country}</p>
{JSON.stringify(uniqueUser) === "true" ?
<p>You are new User</p>
:
<p>You are a regular user</p>
}
<p>You are currently on this page: {nav}</p>
<p>Your Device is: {device}</p>
</header>
</div>
);
}
export default SampleApp;