npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

page-traffic-tracker

v1.2.3

Published

**Page Traffic Tracker** simplifies website traffic tracking by providing easy-to-use hooks and components for React applications. With this package, users can effortlessly monitor the overall traffic on their website and obtain detailed statistics for in

Downloads

107

Readme

Page Traffic Tracker

Overview

Page Traffic Tracker simplifies website traffic tracking by providing easy-to-use hooks and components for React applications. With this package, users can effortlessly monitor the overall traffic on their website and obtain detailed statistics for individual URLs.

Key features of Page Traffic Tracker include:

  • URL Tracking Component: The TrackUrls component allows you to track the traffic for all URLs directly within your React components.
  • Overall Traffic Monitoring: Use the usePageTraffic hook to retrieve total views, today's views, and average views for the entire website.
  • URL-Specific Traffic Analysis: Use the useUrlTraffic hook to fetch traffic data for a specific URL, including total views, today's views, and average views.

Installation

To install Page Traffic Tracker, use npm:

Copy code

npm install page-traffic-tracker

Usage

1. Collect UUID

Before using Page Traffic Tracker, you need to collect a UUID (Universally Unique Identifier) from this website. This UUID will be used to track the traffic on your website.

url=https://ibb.co/T0hW2cb

2. Import Hooks

Import the necessary hooks from Page Traffic Tracker into your React components or custom hooks:

import { TrackUrls, usePageTraffic, useUrlTraffic } from "page-traffic-tracker";

3. Track URL

Use the TrackUrls component into the App.jsx to track the traffic for Urls. And also pass the generated secure id as a props into this component.

<TrackUrls id={id} />

4. Retrieve Overall Traffic Data

Use the usePageTraffic hook to retrieve overall traffic data for the website. And also pass the generated secure id as an argument, which allows the hook to retrieve data specific to that page or resource.

const { totalViews, todayViews, averageView, allUrls } = usePageTraffic(id);

Understanding the Data:

  • totalViews: This holds the total visits to the whole website.
  • todayViews: This holds the number of Visits to the same website on the current day.
  • averageView: This stores the average views per visit for that particular website.
  • allUrls: An array containing URLs associated with the retrieved data (linked URLs or different versions).

5. Retrieve URL-Specific Traffic Data

Use the useUrlTraffic hook to retrieve traffic data for a specific URL. And also pass the generated secure id and url as arguments into this hooks.

const { totalUrlViews, todayUrlViews, averageUrlView } = useUrlTraffic(id, url);

Understanding the Data:

  • totalUrlViews: This holds the total visits to the specific URL.
  • todayUrlViews: This holds the number of visits to the same URL on the current day.
  • averageUrlView: This stores the average views per visit for that specific URL.

Example

1. First initialize the TrackUrls component into the APP.jsx to track all the urls
import { TrackUrls } from "page-traffic-tracker";

function App() {
  const id = "Your generated secure user id from https://pageview-tracker.vercel.app/";

  return (
    <div className="w-screen h-auto flex flex-col  bg-shades-1">
      <Router>
        <Header />
        <Routes>
          <Route path="/" element={<Home />} />
          <Route path="/about" element={<About />} />
          <Route path="/projects" element={<Projects />} />
          <Route path="/contact" element={<Contact />} />
        </Routes>
        <TrackUrls id={id} />;
      </Router>
    </div>
  );
}
2. Then use those usePageTraffic and useUrlTraffic hooks to retrieve all traffic data.
import { usePageTraffic, useUrlTraffic } from "page-traffic-tracker";

const MyComponent = () => {
  const id = "Your generated secure user id from https://pageview-tracker.vercel.app/";
  const { totalViews, todayViews, averageView, allUrls } = usePageTraffic( id );

  const url = "/";
  const { totalUrlViews, todayUrlViews, averageUrlView } = useUrlTraffic( id, url );

  return (
    <div>
      <h2>Overall Traffic</h2>
      <p>Total Views: {totalViews}</p>
      <p>Today's Views: {todayViews}</p>
      <p>Average Views: {averageView}</p>
      <p>All urls: </p>
      <ul>
        {allUrls.map((url) => (
          <li key={url}>{url}</li>
        ))}
      </ul>

      <h2>URL-Specific Traffic</h2>
      <p>Total Views: {totalUrlViews}</p>
      <p>Today's Views: {todayUrlViews}</p>
      <p>Average Views: {averageUrlView}</p>
    </div>
  );
};

License

This project is licensed under the MIT License - see the LICENSE file for details.