Install
One package for Capacitor and Ionic apps (Angular, React and Vue) on iOS, Android and the web.
echo "@gotmode:registry=https://gotmode.com/sdk/npm/" >> .npmrc npm install @gotmode/metrics-capacitor @capacitor/app @capacitor/device @capacitor/preferences
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.
| File | Version | SHA-256 |
|---|---|---|
gotmode-metrics-capacitor-0.1.0.tgz | 0.1.0 | 7c3c7e2d1711951e29427f444b5e4e1e524103d5b675dee93a8b785fe66c4176 |
gotmode-metrics-core-0.1.0.tgz | 0.1.0 | fac754c0bb498c57505735897073c09b2860044af54376c1a4611c095b9203c3 |
Start
Call init once, at the top of your app's entry file, with your public key and your tracking hostname.
import mode from '@gotmode/metrics-capacitor';
mode.init('YOUR_INGEST_KEY', { api_host: 'https://m.example.com' });The SDK finds the app, device, preferences and push notification plugins your app has installed on its own, and never takes from the app a tap, a token or a launch link the plugin keeps for the app's first listener. Every plugin is optional. Without App the SDK follows the page's visibility, without Preferences it keeps its state in the web view's storage, without Device device facts come from the web view.
Events and people
Capture what matters in your app, and name the person once they sign in.
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 logoutA 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.
What is captured automatically
Every event below arrives with no code beyond init.
| Event | When |
|---|---|
$app_installed, $app_updated, $app_opened, $app_backgrounded | Launches, new versions, the foreground and the background |
$screen | Every route your router moves to, by path or hash route, never the query |
$deep_link_opened | The launch link and every link the app is opened with |
$click, $rage_click | Taps on buttons, links and fields |
$push_received, $push_opened, $push_registered | With the push notifications plugin installed. The message id, campaign, iOS category and thread, never the title or the body. The tap that opened the app marks that open. capture_push: false turns it off |
$exception | Uncaught errors and unhandled rejections |
The platform is iOS, Android or the web, as Capacitor reports it, and the web view's own user agent names the device. A link loses its secret parameters and emails before anything is kept, and its campaign parameters, ad click ids and Mode click id become the person's touch.
Taps and privacy
A tapped control is described by its tag, id, role, label and visible text, never by a field's value.
Password, card, one time code and hidden fields produce nothing. data-mode-ignore keeps part of a page out, data-mode-mask hides its text, data-mode-track names a control.
Session recordings
The app's web view recorded like a page, played in Recordings.
Recordings will mask every text, image, and field value until you turn it on in the source's recording settings, never send a password, and record nothing before consent where it is required or after an opt out.
Consent and opt out
Start with consent pending, and nothing is written to the device or sent until the person answers.
mode.init('YOUR_INGEST_KEY', { api_host: 'https://m.example.com', consent: 'pending' });
mode.set_consent('granted');
mode.set_consent({ ad_storage: 'denied' });
mode.opt_out();Pending holds up to 200 events in memory. Denied drops events and deletes what was stored. Without ad storage consent, ad click ids and the Mode click id are left out. An opt out is remembered on the device and stops every send until mode.opt_in().
Delivery
Events wait on the device and are sent in batches, so nothing is lost offline and nothing is counted twice.
| Setting | Value |
|---|---|
| Batches | A second after an event, at once at 50 events, and when the app goes to the background |
| Queue | Up to 1,000 events stored on the device |
| Retries | From 1 second to 5 minutes, with the same event ids |
| Shutdown | mode.shutdown() sends what is queued and removes every listener |