Documentation

Browser extension SDK.

Installs, updates, uninstalls and every page of your browser extension, in the same project as your site.

Browser extensions

Install

One package for Manifest V3 extensions on Chrome, Edge, Firefox and Safari.

shell
echo "@gotmode:registry=https://gotmode.com/sdk/npm/" >> .npmrc
npm install @gotmode/metrics-extension

The .npmrc line sends every @gotmode package to Mode, so commit it with the project. pnpm, Yarn 1 and Bun read it too.

Mode serves its SDKs itself, not from a public package registry. A published version never changes, and every file and its SHA-256 is listed in SHA256SUMS.

FileVersionSHA-256
gotmode-metrics-extension-0.1.0.tgz0.1.0109724d4467c7c96d1d5b024c6602499ab96101c4f736c8930904668c183d33b
gotmode-metrics-core-0.1.0.tgz0.1.0fac754c0bb498c57505735897073c09b2860044af54376c1a4611c095b9203c3

The manifest needs storage in permissions and your tracking hostname in host_permissions, for example https://m.example.com/*.

Browser extensions

Start

The background owns the queue and the person. Call init in your service worker, or your background page on Firefox.

javascript
import mode from '@gotmode/metrics-extension';

mode.init('YOUR_INGEST_KEY', {
  api_host: 'https://m.example.com',
  uninstall_url: 'https://go.example.com/bye',
});

In your popup, side panel and options pages, start the page helper. It reports the page opening, its taps and its errors, and sends every call to the background.

javascript
import { initPage } from '@gotmode/metrics-extension/page';

const mode = initPage();
mode.capture('saved_item');
Browser extensions

Events and people

Capture what matters in your app, and name the person once they sign in.

javascript
mode.capture('added_to_cart', { sku: 'tee-black-m', price: 24 });
mode.identify('user_42', { plan: 'pro' });
mode.group('company', 'acme', { seats: 25 });
mode.register({ app_theme: 'dark' });
mode.reset(); // on logout

A different user than the one stored starts a new person. Person properties set before identify wait for it. An empty id, one over 200 bytes, or a placeholder such as null or guest is never sent. alias, set_person_properties, unset_person_properties, register_once, register_for_session, unregister, flags (flag, flag_enabled, flag_payload) and capture_exception work as on the web.

Browser extensions

What is captured automatically

Every event below arrives with no code beyond init and the page helper.

EventWhen
$extension_installed, $extension_updated, $browser_updatedThe extension is installed or updated, or the browser updates
$extension_startedThe browser starts with the extension
$extension_page_opened, $screenA popup, side panel or options page opens
$clickClicks on controls in those pages
$exceptionErrors in the background and the pages
$tab_activated, $tab_updatedWith tabs: true and the tabs permission, by host only, never the address
Browser extensions

Uninstalls

A browser runs no code when an extension is removed, so it opens a page instead.

With uninstall_url the browser opens that page on removal, with mode_distinct_id and mode_version added. Make it a Mode short link to a survey, and each uninstall is a click of the person who left, in the same project.

Browser extensions

Privacy

The background takes calls only from your extension's own pages, never from a web page or another extension.

Field values are never read, and password, card and hidden fields produce nothing. Tab events carry the host alone. The browser's own user agent names the browser and the system, and the platform is extension, so your extension's numbers stay apart from your site's.

Browser extensions

Delivery

Events wait on the device and are sent in batches, so nothing is lost offline and nothing is counted twice.

SettingValue
BatchesA second after an event, at once at 50 events, and when the app goes to the background
QueueUp to 1,000 events stored on the device
RetriesFrom 1 second to 5 minutes, with the same event ids
Shutdownmode.shutdown() sends what is queued and removes every listener

Let AI run your marketing.

Mode Agent does the daily work. You approve the spend.

Get early access