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

@starlawfirm/webpage-section-tracker-react

v1.2.0

Published

React hooks and components for webpage-section-tracker

Readme

@starlawfirm/webpage-section-tracker-react

React hooks and utilities for webpage-section-tracker.

🎊 Latest: v1.2.0

What's New

v1.2.0 (2025-10-05)

  • 🔄 Core 패키지 업데이트 (v1.2.0 호환)
  • 📦 타입 정의 개선

v1.1.0 (2025-10-02)

  • Event-based subscription: onChange API로 폴링 제거
  • 🔋 성능 10배 향상: CPU 사용률 감소, 리렌더 감소
  • 🚫 Breaking: useElementDwell 세 번째 파라미터 제거

Installation

npm install webpage-section-tracker @starlawfirm/webpage-section-tracker-react
# or
yarn add webpage-section-tracker @starlawfirm/webpage-section-tracker-react
# or
pnpm add webpage-section-tracker @starlawfirm/webpage-section-tracker-react

Quick Start

import { useTracker, useElementDwell } from '@starlawfirm/webpage-section-tracker-react';

function App() {
  // Initialize tracker
  const tracker = useTracker({
    endpoint: '/api/collect',
    appId: 'my-app',
    batchSize: 10
  });

  // Configure element tracking
  const configs = [
    {
      selector: '#hero',
      trigger: { 
        mode: 'immediate', 
        value: 0, 
        margin: '-100px' 
      },
      heartbeat: { enabled: true, intervalMs: 1000 }
    }
  ];

  // Get real-time snapshots
  const snapshots = useElementDwell(tracker, configs);

  return (
    <div>
      {snapshots.map(snapshot => (
        <div key={snapshot.selector}>
          <h3>{snapshot.selector}</h3>
          <p>Visible: {snapshot.visibleNow ? 'Yes' : 'No'}</p>
          <p>Coverage: {(snapshot.elementCoverage * 100).toFixed(0)}%</p>
          <p>Dwell Time: {snapshot.dwellMs}ms</p>
        </div>
      ))}
    </div>
  );
}

API

useTracker(options: TrackerOptions)

Creates and manages a tracker instance.

Parameters:

  • options: Tracker configuration (see core docs)

Returns:

  • Tracker | null: Tracker instance

Features:

  • Automatic cleanup on unmount
  • Singleton pattern per component

useElementDwell(tracker, configs)

Monitors element visibility and dwell time.

Parameters:

  • tracker: Tracker instance from useTracker
  • configs: Array of element configurations

Returns:

  • ElementDwellSnapshot[]: Real-time snapshots (updates every 100ms)

Features:

  • Automatic observer cleanup
  • Real-time state updates
  • TypeScript support

Examples

Basic Usage

import { useTracker, useElementDwell } from '@starlawfirm/webpage-section-tracker-react';

function ProductList() {
  const tracker = useTracker({
    endpoint: '/analytics',
    appId: 'shop'
  });

  const configs = [
    { selector: '.product-card', trigger: { mode: 'immediate', value: 0 } }
  ];

  const snapshots = useElementDwell(tracker, configs);

  return (
    <div>
      {snapshots.filter(s => s.visibleNow).map(s => (
        <div key={s.selector}>Product visible: {s.selector}</div>
      ))}
    </div>
  );
}

Advanced: Dynamic Configuration

function DynamicTracker() {
  const [mode, setMode] = useState<'immediate' | 'elementCoverage'>('immediate');
  
  const tracker = useTracker({ 
    endpoint: '/api/collect', 
    appId: 'test' 
  });

  const configs = useMemo(() => [
    {
      selector: '#target',
      trigger: { mode, value: mode === 'immediate' ? 0 : 0.5 }
    }
  ], [mode]);

  const snapshots = useElementDwell(tracker, configs);

  return (
    <div>
      <button onClick={() => setMode('immediate')}>Immediate</button>
      <button onClick={() => setMode('elementCoverage')}>Coverage</button>
      {/* ... */}
    </div>
  );
}

With TypeScript

import type { ElementDwellSnapshot } from '@starlawfirm/webpage-section-tracker-react';

interface TrackedElementProps {
  snapshot: ElementDwellSnapshot;
}

const TrackedElement: React.FC<TrackedElementProps> = ({ snapshot }) => {
  return (
    <div className={snapshot.visibleNow ? 'visible' : 'hidden'}>
      <h3>{snapshot.selector}</h3>
      <div>Coverage: {(snapshot.elementCoverage * 100).toFixed(1)}%</div>
      <div>Dwell: {snapshot.dwellMs}ms</div>
    </div>
  );
};

TypeScript

All hooks and types are fully typed:

import type {
  Tracker,
  TrackerOptionsV1,
  TrackerOptionsV2,
  ElementDwellConfig,
  ElementDwellSnapshot,
  DwellTriggerMode
} from '@starlawfirm/webpage-section-tracker-react';

Best Practices

1. Memoize Configs

const configs = useMemo(() => [
  { selector: '#hero', trigger: { mode: 'immediate', value: 0 } }
], [/* dependencies */]);

2. Conditional Tracking

const tracker = useTracker({
  endpoint: '/api/collect',
  appId: 'my-app',
  getConsent: () => userHasConsented
});

3. Cleanup

Hooks automatically handle cleanup, but you can also call destroy():

useEffect(() => {
  return () => {
    tracker?.destroy?.();
  };
}, [tracker]);

Performance

  • Snapshots update every 100ms (configurable in source)
  • Minimal re-renders using React refs
  • Automatic observer management
  • Tree-shakeable builds

License

MIT © STARLAWFIRM

Related