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

@wxt-dev/analytics

v0.5.1

Published

Add analytics to your web extension

Readme

WXT Analytics

Report analytics events from your web extension extension.

Supported Analytics Providers

Install With WXT

  1. Install the NPM package:

    pnpm i @wxt-dev/analytics
  2. In your wxt.config.ts, add the WXT module:

    export default defineConfig({
      modules: ['@wxt-dev/analytics/module'],
    });
  3. In your <srcDir>/app.config.ts, add a provider:

    // <srcDir>/app.config.ts
    import { umami } from '@wxt-dev/analytics/providers/umami';
    
    export default defineAppConfig({
      analytics: {
        debug: true,
        providers: [
          // ...
        ],
      },
    });
  4. Then use the #analytics module to report events:

    import { analytics } from '#analytics';
    
    await analytics.track('some-event');
    await analytics.page();
    await analytics.identify('some-user-id');
    analytics.autoTrack(document.body);

Install Without WXT

  1. Install the NPM package:

    pnpm i @wxt-dev/analytics
  2. Create an analytics instance:

    // utils/analytics.ts
    import { createAnalytics } from '@wxt-dev/analytics';
    
    export const analytics = createAnalytics({
      providers: [
        // ...
      ],
    });
  3. Import your analytics module in the background to initialize the message listener:

    // background.ts
    import './utils/analytics';
  4. Then use your analytics instance to report events:

    import { analytics } from './utils/analytics';
    
    await analytics.track('some-event');
    await analytics.page();
    await analytics.identify('some-user-id');
    analytics.autoTrack(document.body);

Providers

Google Analytics 4 (Measurement Protocol)

The Measurement Protocol is an alternative to GTag for reporting events to Google Analytics for MV3 extensions.

Why use the Measurement Protocol instead of GTag?

Follow Google's documentation to obtain your credentials and put them in your .env file:

WXT_GA_API_SECRET='...'

Then add the googleAnalytics4 provider to your <srcDir>/app.config.ts file:

import { googleAnalytics4 } from '@wxt-dev/analytics/providers/google-analytics-4';

export default defineAppConfig({
  analytics: {
    providers: [
      googleAnalytics4({
        apiSecret: import.meta.env.WXT_GA_API_SECRET,
        measurementId: '...',
      }),
    ],
  },
});

Umami

Umami is a privacy-first, open source analytics platform.

In Umami's dashboard, create a new website. The website's name and domain can be anything. Obviously, an extension doesn't have a domain, so make one up if you don't have one.

After the website has been created, save the website ID and domain to your .env file:

WXT_UMAMI_WEBSITE_ID='...'
WXT_UMAMI_DOMAIN='...'

Then add the umami provider to your <srcDir>/app.config.ts file:

import { umami } from '@wxt-dev/analytics/providers/umami';

export default defineAppConfig({
  analytics: {
    providers: [
      umami({
        apiUrl: 'https://<your-umami-instance>/api',
        websiteId: import.meta.env.WXT_UMAMI_WEBSITE_ID,
        domain: import.meta.env.WXT_UMAMI_DOMAIN,
      }),
    ],
  },
});

Custom Provider

If your analytics platform is not supported, you can provide an implementation of the AnalyticsProvider type in your app.config.ts instead:

import { defineAnalyticsProvider } from '@wxt-dev/analytics/client';

interface CustomAnalyticsOptions {
  // ...
}

const customAnalytics = defineAnalyticsProvider<CustomAnalyticsOptions>(
  (analytics, analyticsConfig, providerOptions) => {
    // ...
  },
);

export default defineAppConfig({
  analytics: {
    providers: [
      customAnalytics({
        // ...
      }),
    ],
  },
});

Example AnalyticsProvider implementations can be found at ./modules/analytics/providers.

User Properties

User ID and properties are stored in browser.storage.local. To change this or customize where these values are stored, use the userId and userProperties config:

// app.config.ts
import { storage } from 'wxt/storage';

export default defineAppConfig({
  analytics: {
    userId: storage.defineItem('local:custom-user-id-key'),
    userProperties: storage.defineItem('local:custom-user-properties-key'),
  },
});

To set the values at runtime, use the identify function:

await analytics.identify(userId, userProperties);

Alternatively, a common pattern is to use a random string as the user ID. This keeps the actual user information private, while still providing useful metrics in your analytics platform. This can be done very easily using WXT's storage API:

// app.config.ts
import { storage } from 'wxt/storage';

export default defineAppConfig({
  analytics: {
    userId: storage.defineItem('local:custom-user-id-key', {
      init: () => crypto.randomUUID(),
    }),
  },
});

If you aren't using wxt or @wxt-dev/storage, you can define custom implementations for the userId and userProperties config:

const analytics = createAnalytics({
  userId: {
    getValue: () => ...,
    setValue: (userId) => ...,
  }
})

Auto-track UI events

Call analytics.autoTrack(container) to automatically track UI events so you don't have to manually add them. Currently it:

  • Tracks clicks to elements inside the container

In your extension's HTML pages, you'll want to call it with document:

analytics.autoTrack(document);

But in content scripts, you usually only care about interactions with your own UI:

const ui = createIntegratedUi({
  // ...
  onMount(container) {
    analytics.autoTrack(container);
  },
});
ui.mount();

Enabling/Disabling

By default, analytics is disabled. You can configure how the value is stored (and change the default value) via the enabled config:

// app.config.ts
import { storage } from 'wxt/storage';

export default defineAppConfig({
  analytics: {
    enabled: storage.defineItem('local:analytics-enabled', {
      fallback: true,
    }),
  },
});

At runtime, you can call setEnabled to change the value:

analytics.setEnabled(true);