react-siteviews
TypeScript icon, indicating that this package has built-in type declarations

2.0.3Β β€’Β PublicΒ β€’Β Published

πŸ“Š 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-siteviews relies 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 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!

πŸ“„ License

Licensed under the MIT License.


Built for simplicity. Track with ease πŸ’– β€” and stay informed πŸš€.

Readme

Keywords

none

Package Sidebar

Install

npm i react-siteviews

Weekly Downloads

1

Version

2.0.3

License

ISC

Unpacked Size

48 kB

Total Files

7

Last publish

Collaborators

  • devababil