Track page views and gather visitor information effortlessly using react-siteviews
.
Supports both React βοΈ and Next.js β‘ β with zero backend setup and full support for JavaScript π¨ and TypeScript π¦!
Install the package using your favorite package manager:
npm install react-siteviews
π App.jsx
or App.tsx
import SiteViews from "react-siteviews";
const App = () => {
return (
<SiteViews
projectName="site views documentation"
visited={() => {
alert("Website visited π");
}}
getData={(value) => {
console.log(value); // π₯ Array of visitor data
}}
refresh="10" // π Auto-refresh every 10s
suppressLogs // π Hide logs
style={{ color: "red" }}
>
Loading...
</SiteViews>
);
};
export default App;
π§ Note: Since
react-siteviews
relies on browser APIs, it must be rendered on the client side only.
π components/ViewsCounter.jsx
or ViewsCounter.tsx
"use client";
import dynamic from "next/dynamic";
const SiteViews = dynamic(() => import("react-siteviews"), { ssr: false });
const ViewsCounter = () => {
return (
<SiteViews
projectName="site views documentation"
visited={() => {
alert("Website visited π");
}}
getData={(value) => {
console.log(value); // π₯ Array of visitor data
}}
refresh="10" // π Auto-refresh every 10s
suppressLogs // π Hide logs
style={{ color: "red" }}
>
Loading...
</SiteViews>
);
};
export default ViewsCounter;
π§© Use <ViewsCounter />
inside any page or layout to start tracking visits instantly.
446
βοΈ Displays the total number of visits.
βοΈ Additional visitor data is available via the getData
callback.
π·οΈ Prop | π¬ Description |
---|---|
projectName |
β Required β Unique name for your site or page. |
visited |
π₯ Optional β Callback executed after a visit is successfully recorded. |
getData |
π Optional β Retrieves an array of detailed visitor info. |
refresh |
π Optional β Auto-refresh interval (in seconds). |
className |
π¨ Optional β Add custom class names. |
style |
π Optional β Apply inline styles. |
suppressLogs |
π Optional β Mute all console logs/warnings from SiteViews. |
- π§βπΌ Portfolio visit counters
- π Landing page or marketing page metrics
- Use
refresh="10"
to auto-update visit count every 10 seconds β±οΈ - Combine
getData
with your app's state for dynamic dashboards π - Set unique
projectName
values for each route/page if needed π£οΈ - Fully supports JavaScript π¨ and TypeScript π¦ environments out of the box!
Licensed under the MIT License.
Built for simplicity. Track with ease π β and stay informed π.