Set Up Viewing Analytics
Follow the steps below to add lightweight analytics tracking to your web pages using view-analytics-js.
- Step 1: Install the
view-analytics-js
library via npm. Run the following command in your terminal:npm install view-analytics-js
- 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";
- Step 3: Initialize the analytics by adding the following code snippet to your application:
import { initializeAnalytics } from "view-analytics-js";
- 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!