react-siteviews
v2.0.5
Published
Track page views and gather visitor information effortlessly using [`react-siteviews`](https://www.npmjs.com/package/react-siteviews). Supports both **React** βοΈ and **Next.js** β‘ β with **zero backend setup** and full support for **JavaScript** π¨ and
Readme
π React SiteViews Integration (React & Next.js)
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 π¦!
π¦ Installation π
Install the package using your favorite package manager:
npm install react-siteviewsβοΈ React Setup (Vite / CRA / Others)
β Step-by-step:
π 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;β‘ Next.js Setup
π§ Note: Since
react-siteviewsrelies on browser APIs, it must be rendered on the client side only.
β Step-by-step:
π 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.
π Output Example
446βοΈ Displays the total number of visits.
βοΈ Additional visitor data is available via the getData callback.
π§° Available Props
| π·οΈ 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. |
π‘Mostly Use Cases
- π§βπΌ Portfolio visit counters
- π Landing page or marketing page metrics
π Tips & Tricks
- Use
refresh="10"to auto-update visit count every 10 seconds β±οΈ - Combine
getDatawith your app's state for dynamic dashboards π - Set unique
projectNamevalues for each route/page if needed π£οΈ - Fully supports JavaScript π¨ and TypeScript π¦ environments out of the box!
π License
Licensed under the MIT License.
Built for simplicity. Track with ease π β and stay informed π.
