Open Source NPM Library
● Active & Maintained
Dec 2024 - Present

React Next Google Tools

Lightweight, zero-boilerplate Google Analytics library for React & Next.js.

npmNPM↗GitHub↗
Role: Author & Maintainer
React Next Google Tools Preview

Key Metrics & Impact

Highlight 1

Version 1.1.0 active on NPM registry

Highlight 2

Universal App Router & Pages Router & React support

Highlight 3

Zero external dependencies outside peer React/Next

Highlight 4

Sub-kilobyte footprint with tree-shakeable ESM/CJS exports

⚠ The Problem

Pain Point & Friction

Official Google Analytics setups in Next.js require manual script tags, custom hooks for pathname changes, and separate workarounds for Pages Router vs App Router, frequently damaging Core Web Vitals (LCP/INP) and causing tracking drops.

✓ The Solution

Engineered Approach

Built an optimized library using Rollup and TypeScript. Detects Next.js runtime to use 'next/script' with lazy loading, while gracefully falling back to native script loading in standard React/Vite environments. Automatically binds to History API and router events for 100% accurate pageview attribution.

⚡ Core Features

  • ✓Single component drop-in: <GoogleAnalytics id="G-XXXXXXXXXX" />
  • ✓Automatic client-side navigation and pageview tracking
  • ✓Dual runtime support: optimized next/script or native HTML <script>
  • ✓Comprehensive TypeScript type definitions included out of the box
  • ✓Production-safe toggle to prevent test analytics contamination

⚙ Architecture & Engineering

  • →Rollup build pipeline with @rollup/plugin-typescript and terser minification
  • →Dual ESM (dist/index.js) and CommonJS (dist/index.cjs.js) distribution
  • →Strict semantic versioning with MIT open-source license
  • →CI/CD release workflow for zero-friction npm publishing

Technologies & Infrastructure

React
Next.js
TypeScript
Rollup
NPM
Open Source