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 🙏

© 2026 – Pkg Stats / Ryan Hefner

gunma-behavioral-tracking-nextjs

v1.0.0

Published

Behavioral tracking SDK for Next.js E-commerce and POS applications

Readme

Gunma Behavioral Tracking SDK for Next.js

Professional-grade behavioral tracking for Next.js E-commerce and POS applications.

Installation

From npm (if published)

npm install @gunma/behavioral-tracking-nextjs

From local SDK folder

# Copy the SDK folder to your project
cp -r public/sdk/nextjs path/to/your/nextjs-project/sdk

# Install dependencies
cd path/to/your/nextjs-project/sdk/nextjs
npm install

# Build the SDK
npm run build

Use directly in your project

# In your Next.js project
npm install axios js-cookie ua-parser-js

Then copy the source files from src/ to your project.

Quick Start

1. Add TrackingProvider to your root layout

// app/layout.tsx
import { TrackingProvider } from '@/sdk/nextjs/src/context';
import { ConsentBanner } from '@/sdk/nextjs/src/components/ConsentBanner';

export default function RootLayout({ children }: { children: React.ReactNode }) {
  return (
    <html>
      <body>
        <TrackingProvider>
          {children}
          <ConsentBanner />
        </TrackingProvider>
      </body>
    </html>
  );
}

2. Configure environment variables

# .env.local
NEXT_PUBLIC_API_URL=http://localhost:8000
NEXT_PUBLIC_TRACKING_ENABLED=true
NEXT_PUBLIC_TRACKING_CONSENT_REQUIRED=true

3. Use the tracking hook

'use client';

import { useBehavioralTracking } from '@/sdk/nextjs/src/hooks/useBehavioralTracking';

export function ProductCard({ product }) {
  const { trackProductView, trackAddToCart } = useBehavioralTracking();
  
  return (
    <div onClick={() => trackProductView(product.id, product.price)}>
      <h3>{product.name}</h3>
      <p>${product.price}</p>
      <button onClick={() => trackAddToCart(product.id, 1, product.price)}>
        Add to Cart
      </button>
    </div>
  );
}

API Reference

useBehavioralTracking()

Main tracking hook with all tracking methods.

const {
  trackEvent,
  trackProductView,
  trackAddToCart,
  trackRemoveFromCart,
  trackSearch,
  trackOrderPlaced,
  trackCheckoutInitiated,
  trackAddToWishlist,
  trackRemoveFromWishlist,
} = useBehavioralTracking();

Methods:

  • trackProductView(productId: number, price?: number) - Track product page views
  • trackAddToCart(productId: number, quantity: number, price: number) - Track add to cart
  • trackRemoveFromCart(productId: number) - Track remove from cart
  • trackSearch(query: string, resultsCount: number) - Track search queries
  • trackOrderPlaced(orderId: number) - Track completed orders
  • trackCheckoutInitiated() - Track checkout start
  • trackAddToWishlist(productId: number) - Track wishlist additions
  • trackRemoveFromWishlist(productId: number) - Track wishlist removals
  • trackEvent(eventType: string, data?: Partial<BehavioralEvent>) - Track custom events

useTracking()

Consent management hook.

const { hasConsent, grantConsent, revokeConsent, isLoading } = useTracking();

useAnalytics()

Analytics data fetching hook.

const { getDashboard, getProductAffinity, getConversionFunnel } = useAnalytics();

Features

Auto-tracking - Automatically tracks scroll depth, time spent, page views ✅ GDPR Compliant - Built-in consent management ✅ TypeScript - Full type safety ✅ Queue-based - No performance impact ✅ Product Recommendations - Get product affinity data ✅ Analytics Dashboard - Complete analytics API client ✅ Device Detection - Auto-detects device, browser, platform ✅ UTM Tracking - Automatically captures campaign parameters

Auto-Tracked Events

The SDK automatically tracks:

  • Page Views - On component mount
  • Scroll Depth - At 25%, 50%, 75%, 100%
  • Time Spent - On page unload (using sendBeacon)
  • Interactions - Click counts

Manual Tracking Examples

E-commerce

// Product page
useEffect(() => {
  trackProductView(product.id, product.price);
}, [product.id]);

// Add to cart button
<button onClick={() => trackAddToCart(product.id, 1, product.price)}>
  Add to Cart
</button>

// Search page
const handleSearch = async (query: string) => {
  const results = await searchProducts(query);
  trackSearch(query, results.length);
};

// Checkout page
useEffect(() => {
  trackCheckoutInitiated();
}, []);

// Order confirmation
useEffect(() => {
  if (order) {
    trackOrderPlaced(order.id);
  }
}, [order]);

POS System

// Barcode scanner
const handleScan = async (barcode: string) => {
  const product = await fetchProduct(barcode);
  await trackProductView(product.id, product.price);
  await trackAddToCart(product.id, 1, product.price);
  addToCart(product);
};

Analytics Examples

import { useAnalytics } from '@/sdk/nextjs/src/hooks/useAnalytics';

function DashboardPage() {
  const { getDashboard } = useAnalytics();
  const [data, setData] = useState(null);
  
  useEffect(() => {
    getDashboard({ start_date: '2025-01-01', end_date: '2025-12-31' })
      .then(response => setData(response.data));
  }, []);
  
  return (
    <div>
      <h1>Total Events: {data?.total_events}</h1>
      <h2>Cart Abandonment: {data?.cart_abandonment?.abandonment_rate}%</h2>
    </div>
  );
}

Advanced Configuration

import { behavioralTracker } from '@/sdk/nextjs/src/tracker';

// Custom configuration
behavioralTracker.setConfig({
  enabled: true,
  consentRequired: false, // Disable consent requirement
  debugMode: true, // Enable debug logging
});

// Check consent
if (behavioralTracker.hasConsent()) {
  // Track event
}

// Grant consent programmatically
behavioralTracker.grantConsent();

// Revoke consent
behavioralTracker.revokeConsent();

Troubleshooting

Events not tracking:

  1. Check queue worker is running: php artisan queue:work redis
  2. Check browser console for errors
  3. Verify API URL in .env.local
  4. Check user has granted consent

CORS errors:

  • Add your Next.js URL to backend config/cors.php
  • Restart Laravel server

Support

For issues, see the complete integration guide in:

  • FRONTEND_INTEGRATION_GUIDE.md
  • FRONTEND_QUICK_START.md

License

MIT