Documentation

Electron SDK.

Windows, screens, taps, updates and crashes from your Electron app, one person across every window.

Electron

Install

One package for the main process, the preload and every page of an Electron app.

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

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-electron-0.1.0.tgz0.1.033c4499e0849aa28430c4cee50c75cb400fb1b774b2d07449502573155333607
gotmode-metrics-core-0.1.0.tgz0.1.0fac754c0bb498c57505735897073c09b2860044af54376c1a4611c095b9203c3
Electron

Start

The main process owns the queue and the person. Call init there before the app is ready.

javascript
import { app, autoUpdater } from 'electron';
import mode from '@gotmode/metrics-electron/main';

mode.init('YOUR_INGEST_KEY', {
  api_host: 'https://m.example.com',
  protocol: 'myapp',
  updater: autoUpdater,
});

Then expose the bridge in your preload script, which your bundler bundles with it.

javascript
import { exposeModeMetrics } from '@gotmode/metrics-electron/preload';
exposeModeMetrics();

Pages then call window.modeMetrics.capture('exported_report', { rows: 120 }) and the rest, and every call reaches the main process, so the app has one person and one session across all its windows. protocol is your app's own link scheme, and updater takes Electron's updater or electron-updater's.

Electron

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.

Electron

What is captured automatically

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

EventWhen
$app_installed, $app_updated, $app_openedThe first start, a new version, every start
$app_backgroundedNo window of the app has focus, and $app_opened when one has it again
$app_quitQuitting, once what is queued was sent
$window_opened, $window_closed, $window_focus, $window_blurEvery window
$screenEvery page a window loads and every route a single page app moves to
$click, $rage_clickClicks and taps on controls in every page with the preload
$deep_link_openedA link in your scheme opens the app
$system_suspend, $system_resume, $system_lock, $system_unlockThe computer sleeps, wakes, locks and unlocks
$update_available, $update_downloaded, $update_errorThe updater, with the version
$exceptionUncaught errors in the main process, crashed renderers and child processes, and every page's errors

A page loaded from a file is named by the file alone, never the folder it sits in. Window titles are scrubbed of emails and long numbers. Uncaught exceptions are watched and never swallowed, so your app behaves as it did. The platform is macOS, Windows or Linux, and every request names your app and its version.

Electron

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