Skip to content

WXT

WXT is a framework for browser extensions. Its @wxt-dev/analytics package includes a Moderok provider so you can send events to the same Moderok project without wiring @moderok/sdk by hand.

This path is optional. If you are not using WXT, follow the rest of this guide as usual.

Install

bash
npm install @wxt-dev/analytics

Register the module

In wxt.config.ts, add the analytics module:

ts
export default defineConfig({
  modules: ["@wxt-dev/analytics/module"],
});

The module adds the storage permission to the generated manifest if it is not already there.

Configure Moderok

Put your app key in .env (see WXT’s environment-variable docs):

dotenv
WXT_MODEROK_APP_KEY=mk_your_app_key

In <srcDir>/app.config.ts, register the Moderok provider:

ts
import { moderok } from "@wxt-dev/analytics/providers/moderok";

export default defineAppConfig({
  analytics: {
    debug: false,
    providers: [
      moderok({
        appKey: import.meta.env.WXT_MODEROK_APP_KEY,
        endpoint: import.meta.env.WXT_MODEROK_ENDPOINT, // optional override
        trackLifecycle: true,
        trackUninstalls: false,
        uninstallUrl: undefined,
        trackErrors: true,
        captureConsoleErrors: false,
      }),
    ],
  },
});
OptionDefaultWhat it does
appKey(required)Your mk_… key from the Moderok app
endpointhttps://api.moderok.dev/v1/eventsOverride for local or self-hosted APIs
trackLifecycletrue__install, __update, and __daily_ping
trackUninstallsfalseRegisters an uninstall URL (same idea as the SDK)
uninstallUrl-Optional redirect after the uninstall ping
trackErrorstrueAutomatic __error events (see below)
captureConsoleErrorsfalseMirror console.error into __error (noisy)

Send events

WXT exposes a #analytics import. Use it from the background, popup, options, content scripts, and other entry points:

ts
import { analytics } from "#analytics";

await analytics.track("button_clicked", { surface: "popup" });
await analytics.page();

Events are delivered to the background and forwarded to Moderok (and any other providers you configured). You do not call Moderok.init() yourself when using this integration.

Note

The WXT Moderok provider is not the same bundle as @moderok/sdk. It is a separate implementation built for WXT’s provider model. The ingestion API and dashboard accept both.

Automatic error tracking (important)

Background only

The Moderok provider’s automatic __error capture runs where WXT initializes the provider: the background / service worker. WXT does not install global error listeners in popups, options, side panels, or content scripts for the provider, so uncaught errors in those contexts are not automatically reported as __error. That is a limitation of how WXT’s analytics module is scoped, not something the Moderok API can change.

trackErrors: false turns off automatic capture in the background. captureConsoleErrors: true only affects console.error in that same background context.

For the same per-context error coverage as @moderok/sdk, add the SDK to the entry files where you need it and call Moderok.init({ appKey: "…" }) there, or handle errors manually (for example chrome.runtime.sendMessage to the background).

Compared to @moderok/sdk

WXT provider@moderok/sdk
Setupapp.config.ts + #analyticsModerok.init() per context you track from
Custom eventsanalytics.track()Moderok.track()
Automatic __error in every UI surfaceNo (background only)Yes, if you init() in each context
Batching / offline queueFire-and-forget from WXTSDK queue + persistence

Choose WXT when you already use @wxt-dev/analytics and want Moderok alongside other providers. Choose the SDK when you want the smallest, fully controlled integration or full error coverage everywhere.

See also

Moderok: analytics for browser extensions