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

runatics

v0.3.1

Published

A simple Google analyticscomponent for Svelte Runes project

Readme

Runatics

A lightweight Google Analytics 4 component for Svelte 5 (Runes). Drop it into any SvelteKit project and GA starts tracking — no boilerplate required.

Documentation · Issues

Features

  • Single component, zero configuration beyond your Measurement ID
  • Duplicate-init guard — safe across hot reloads and multiple mounts
  • SSR-safe: scripts injected via <svelte:head> so they appear in server-rendered HTML
  • Dev-mode protection: GA is skipped in development by default
  • Built-in debug logging and invalid-ID warnings

Installation

pnpm add runatics      # pnpm
npm install runatics   # npm

Quick start

<script>
  import { Runatics } from 'runatics';
</script>

<Runatics analyticsId="G-XXXXXXXXXX" />

That's it. Two scripts are injected into <head>: the external gtag/js loader and the inline initializer.

Props

| Prop | Type | Default | Description | | --------------------- | --------- | ------- | ----------------------------------------------------------- | | analyticsId | string | — | Required. Your GA4 Measurement ID, e.g. G-XXXXXXXXXX | | debug | boolean | false | Log init messages and show error UI for missing/invalid IDs | | enableInDevelopment | boolean | false | Load GA even when import.meta.env.DEV is true |

Usage examples

Production setup (recommended)

<!-- src/routes/+layout.svelte -->
<script>
  import { Runatics } from 'runatics';
</script>

<Runatics analyticsId="G-XXXXXXXXXX" />

GA is automatically skipped in development and loaded in production.

Enable in development for testing

<Runatics analyticsId="G-XXXXXXXXXX" enableInDevelopment={true} />

Debug mode

Shows console logs and renders an error UI when the ID is missing or malformed:

<Runatics analyticsId="G-XXXXXXXXXX" debug={true} />

Environment variable (SvelteKit)

<script>
  import { Runatics } from 'runatics';
  import { PUBLIC_GA_ID } from '$env/static/public';
</script>

<Runatics analyticsId={PUBLIC_GA_ID} />

Add PUBLIC_GA_ID=G-XXXXXXXXXX to your .env file.

How it works

When analyticsId is valid and shouldLoad is true, Runatics injects two scripts into <svelte:head>:

<script async src="https://www.googletagmanager.com/gtag/js?id=G-XXXXXXXXXX"></script>
<script>
  window.dataLayer = window.dataLayer || [];
  function gtag() {
    dataLayer.push(arguments);
  }
  window.__runaticsInitialized = window.__runaticsInitialized || {};
  if (!window.__runaticsInitialized['G-XXXXXXXXXX']) {
    window.__runaticsInitialized['G-XXXXXXXXXX'] = true;
    gtag('js', new Date());
    gtag('config', 'G-XXXXXXXXXX');
  }
</script>

The __runaticsInitialized guard ensures gtag('config', ...) is called exactly once per Measurement ID, even if the component mounts multiple times (e.g. during SvelteKit navigation or HMR).

Measurement ID format

IDs must match G-[A-Z0-9]+. Examples of valid IDs:

G-XXXXXXXXXX
G-1234567890
G-ABC123DEF4

If the ID is missing or malformed, Runatics logs a console.warn and skips script injection. With debug={true} it also renders a visible error block.

Development vs production

| Condition | Scripts injected? | | ------------------------------------------------------------- | ----------------- | | import.meta.env.DEV === true (default) | No | | import.meta.env.DEV === true + enableInDevelopment={true} | Yes | | Production build | Yes |

Requirements

  • Svelte 5 (Runes mode)
  • SvelteKit (any adapter)

License

MIT © Shinichi Okada