Set Up Viewing Analytics

Follow the steps below to add lightweight analytics tracking to your web pages using view-analytics-js.

  1. Step 1: Install the view-analytics-js library via npm. Run the following command in your terminal:
    npm install view-analytics-js
  2. Step 2: Import the library into your layout.tsx or a global component where you want analytics tracking. Add the following line to the top of your file:
    import "view-analytics-js";
  3. Step 3: Initialize the analytics by adding the following code snippet to your application:
    import { initializeAnalytics } from "view-analytics-js";
  4. Step 4: Start tracking page views by adding the following code to the root of your application:
    import { trackPageView } from "view-analytics-js";
    
    // Call this function on each page load
    trackPageView(window.location.pathname);

Once you've completed these steps, your website will be ready to track and log viewing analytics seamlessly!

NextJSAnalytics

Your go-to solution for lightweight, privacy-focused analytics. Built for modern web applications.

Contact Us

Email: support@nextjsanalytics.com

Follow Us

© 2025 NextJSAnalytics. All rights reserved.