Documentation

Windows SDK.

Windows, screens, clicks, opens, links and crashes from your WinUI, WPF or Windows Forms app, linked to the same people as your site.

Windows

How the Windows SDK works

One setup call in a WinUI 3, WPF or Windows Forms app captures its windows, screens, clicks, opens, links and crashes. It sends the same events, people and sessions as your site's snippet, so an app and a site land in the same reports.

SettingValue
PackagesMode.Metrics.WinUI, Mode.Metrics.Wpf or Mode.Metrics.WinForms, library mode-windows
HostYour project's tracking hostname, such as https://m.example.com, from Setup
KeyYour project's public ingest key (mpk_), safe to ship inside an app
PlatformsWindows 10 and 11. WPF and Windows Forms on .NET 8 and later, WinUI 3 on the Windows App SDK 1.6 and later
DeliveryA queue kept on disk, sent in batches of up to 50, retried with the same event ids so nothing is counted twice
Windows

Install

Add Mode's package feed in a nuget.config next to your solution, then the package for your app's framework.

xml
<configuration>
  <packageSources>
    <add key="nuget.org" value="https://api.nuget.org/v3/index.json" />
    <add key="mode" value="https://gotmode.com/sdk/nuget/index.json" />
  </packageSources>
  <packageSourceMapping>
    <packageSource key="mode"><package pattern="Mode.Metrics" /><package pattern="Mode.Metrics.*" /></packageSource>
    <packageSource key="nuget.org"><package pattern="*" /></packageSource>
  </packageSourceMapping>
</configuration>
shell
dotnet add package Mode.Metrics.WinUI    # or Mode.Metrics.Wpf, or Mode.Metrics.WinForms

The source mapping takes the Mode packages only from Mode and every other package from nuget.org as before. Each package brings Mode.Metrics.Windows, the app client, and Mode.Metrics, the queue and transport the server SDK uses. WPF and Windows Forms add no other package. WinUI also brings the Windows App SDK your app already uses and Microsoft.Win32.SystemEvents.

FileVersionSHA-256
mode.metrics.winui.0.1.0.nupkg0.1.0f13f3908ed1e88c17333ad861adc7f07ca45899f10aa43225176785917f82376
mode.metrics.wpf.0.1.0.nupkg0.1.0b8f33eab8fd128036453421a58095342917665b286a4fedf0561f5b440a4e822
mode.metrics.winforms.0.1.0.nupkg0.1.03f1d08cc8df7cc27c097a7e3f43642a08306a7bd1fd1619e9ce7b4429e148d6d
mode.metrics.windows.0.1.0.nupkg0.1.078b519a4b77edf52318622e57c7890fc09fbeee7944c2c0fc214003e1542adc9
mode.metrics.0.2.0.nupkg0.2.0e6844e09cb6cd4dd5aacd7e2fb961f694a7cbe4b91e6658ef9febafe41a93565
Windows

Setup

Call Setup once with your app's id. Everything in What is captured automatically starts from that call.

csharp
// WinUI 3, in the App constructor
using Mode.Metrics.Windows;
using Mode.Metrics.WinUI;

public App()
{
    InitializeComponent();
    ModeMetrics.Setup("com.example.shop", "YOUR_INGEST_KEY", new ModeOptions { Host = "https://m.example.com", Scheme = "shop" });
}
csharp
// WPF, in the App constructor or OnStartup
using Mode.Metrics.Windows;
using Mode.Metrics.Wpf;

ModeMetrics.Setup("com.example.shop", "YOUR_INGEST_KEY", new ModeOptions { Host = "https://m.example.com" });
csharp
// Windows Forms, in Main before Application.Run
using Mode.Metrics.Windows;
using Mode.Metrics.WinForms;

ApplicationConfiguration.Initialize();
ModeMetrics.Setup("com.example.shop", "YOUR_INGEST_KEY", new ModeOptions { Host = "https://m.example.com" });
Application.Run(new MainForm());

The app id names the data folder, %LOCALAPPDATA%\Mode\Metrics\{app id}. The version and build come from your app's entry assembly unless you set AppVersion and AppBuild. Scheme is your app's own link scheme. Without a valid host and public key the SDK does nothing. A secret key never ships in an app and is refused.

Windows

Events, people and groups

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

csharp
ModeMetrics.Capture("order_placed", new { total = 49 });
ModeMetrics.Screen("Checkout");
ModeMetrics.Identify("user_42", set: new { plan = "pro" });  // after sign in
ModeMetrics.Group("company", "acme", new { seats = 12 });
ModeMetrics.Register(new { edition = "pro" });           // on every event
ModeMetrics.Reset();                                       // on sign out

Also Alias, SetPersonProperties, UnsetPersonProperties, RegisterOnce, RegisterForSession, Unregister, GetDistinctId and FlushAsync. A different user signing in on the same computer becomes a new person, never a merge. Person properties set before sign in are sent with the next Identify. An empty id or a placeholder such as null or anonymous is dropped.

Windows

What is captured automatically

Every event below arrives with no code beyond Setup. Turn a family off with DisabledAutocapture, all of them with Autocapture = false, or from your project's settings.

EventWhen
$app_installed, $app_updated, $app_openedThe first start, a new version, every start with its launch time
$app_backgroundedNo window of the app has had focus for a second, and $app_opened when one has it again
$app_quitThe app exits, then what is queued is sent, waiting at most 2 seconds
$window_opened, $window_closed, $window_focus, $window_blurEvery window, named by its x:Name or its type
$screenWinUI and WPF Frame navigation, WPF NavigationWindow, and the window or form that gains focus
$click, $rage_clickClicks on buttons, toggles, menu items, links, tabs, list items and other controls, with the control's type, text, path, name, automation name and role
$deep_link_openedA link in your scheme starts the app, and in WinUI reaches it while running
$system_suspend, $system_resume, $system_lock, $system_unlockThe computer sleeps, wakes, locks and unlocks
$exceptionUnhandled exceptions, exceptions on the UI thread, failed tasks no one awaited, and a run that ended without quitting, found on the next start
FrameworkClicksScreens
WinUI 3Pointer and key presses on each window's content and open popups, read up to the controlEvery Frame, by page type
WPFClass handlers for every button, menu item, hyperlink, list, tree, grid, tab and slider in every windowEvery Frame and NavigationWindow, by the page's title or type
Windows FormsA message filter on mouse and Space or Enter presses, read to the control, the tool strip or menu item, or the tabThe form that gains focus

The first event of each session carries the device (Windows version, pixel ratio, dark mode, text size, reduced motion, high contrast, runtime, languages, memory and cores), never a device name, user name or hardware id. Exceptions are watched and never marked handled, so your app behaves as it did, and a fatal one is written to disk before the process ends.

Windows

Text and privacy

A clicked control's caption is scrubbed of emails and long numbers and cut to 80 characters. A text field never sends its text.

A click on a text or password field is a $click with role textbox and nothing typed. Set MaskText = true to leave every caption out. Window titles are scrubbed the same way. A link that opens the app loses sign in tokens, codes, passwords, keys and signatures, and an email address becomes [email]. Error messages lose emails and long numbers, and a home folder such as C:\Users\name\ becomes ~\.

Windows

Errors

Crashes are saved before the app stops and sent on the next start, in the session they ended.

csharp
catch (Exception error) { ModeMetrics.CaptureException(error, new { step = "payment" }); }

Each error carries its type, message, stack, whether it was handled or fatal, the release and the last 20 events before it, and appears in Errors. The same error is sent at most once a minute with a repeat count. Windows Forms keeps one UI thread error handler, so the SDK calls the one it replaced, or shows the dialog Windows Forms shows when there is none.

Windows

Feature flags

Flags load at start and whenever the person changes, and are cached for the next start.

csharp
if (ModeMetrics.FlagEnabled("new-checkout")) ShowNewCheckout();
var price = ModeMetrics.FlagPayload("price-test");
ModeMetrics.OnFlags(flags => Refresh());
Windows

Delivery

Events wait on disk 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 quits
QueueUp to 1,000 events kept on disk
RetriesFrom 1 second to 5 minutes, with the same event ids
SessionsEnd after 30 minutes with no activity or 24 hours. Focus, sleep and lock never start or extend one
Windows

Limits

What each framework does not tell an SDK.

WinUI 3 has no list of windows, so the SDK finds each window through focus and the window your App class holds. A window held elsewhere still sends its opens, closes and clicks, but not its loss of focus, and $app_quit is sent when the last window it knows closes. A click in a WinUI popup is seen once something in the popup has had focus. Windows Forms has no navigation, so its screens are its forms, and a MessageBox is not seen.

Let AI run your marketing.

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

Get early access