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.
| Setting | Value |
|---|---|
| Packages | Mode.Metrics.WinUI, Mode.Metrics.Wpf or Mode.Metrics.WinForms, library mode-windows |
| Host | Your project's tracking hostname, such as https://m.example.com, from Setup |
| Key | Your project's public ingest key (mpk_), safe to ship inside an app |
| Platforms | Windows 10 and 11. WPF and Windows Forms on .NET 8 and later, WinUI 3 on the Windows App SDK 1.6 and later |
| Delivery | A queue kept on disk, sent in batches of up to 50, retried with the same event ids so nothing is counted twice |
Install
Add Mode's package feed in a nuget.config next to your solution, then the package for your app's framework.
<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>
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.
| File | Version | SHA-256 |
|---|---|---|
mode.metrics.winui.0.1.0.nupkg | 0.1.0 | f13f3908ed1e88c17333ad861adc7f07ca45899f10aa43225176785917f82376 |
mode.metrics.wpf.0.1.0.nupkg | 0.1.0 | b8f33eab8fd128036453421a58095342917665b286a4fedf0561f5b440a4e822 |
mode.metrics.winforms.0.1.0.nupkg | 0.1.0 | 3f1d08cc8df7cc27c097a7e3f43642a08306a7bd1fd1619e9ce7b4429e148d6d |
mode.metrics.windows.0.1.0.nupkg | 0.1.0 | 78b519a4b77edf52318622e57c7890fc09fbeee7944c2c0fc214003e1542adc9 |
mode.metrics.0.2.0.nupkg | 0.2.0 | e6844e09cb6cd4dd5aacd7e2fb961f694a7cbe4b91e6658ef9febafe41a93565 |
Setup
Call Setup once with your app's id. Everything in What is captured automatically starts from that call.
// 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" }); }
// 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" });
// 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.
Events, people and groups
Capture what matters in your app, and name the person once they sign in.
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.
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.
| Event | When |
|---|---|
$app_installed, $app_updated, $app_opened | The first start, a new version, every start with its launch time |
$app_backgrounded | No window of the app has had focus for a second, and $app_opened when one has it again |
$app_quit | The app exits, then what is queued is sent, waiting at most 2 seconds |
$window_opened, $window_closed, $window_focus, $window_blur | Every window, named by its x:Name or its type |
$screen | WinUI and WPF Frame navigation, WPF NavigationWindow, and the window or form that gains focus |
$click, $rage_click | Clicks 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_opened | A link in your scheme starts the app, and in WinUI reaches it while running |
$system_suspend, $system_resume, $system_lock, $system_unlock | The computer sleeps, wakes, locks and unlocks |
$exception | Unhandled exceptions, exceptions on the UI thread, failed tasks no one awaited, and a run that ended without quitting, found on the next start |
| Framework | Clicks | Screens |
|---|---|---|
| WinUI 3 | Pointer and key presses on each window's content and open popups, read up to the control | Every Frame, by page type |
| WPF | Class handlers for every button, menu item, hyperlink, list, tree, grid, tab and slider in every window | Every Frame and NavigationWindow, by the page's title or type |
| Windows Forms | A message filter on mouse and Space or Enter presses, read to the control, the tool strip or menu item, or the tab | The 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.
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 ~\.
Consent and opt out
Start with consent pending, and nothing is written to disk or sent until the person answers.
new ModeOptions { Host = "https://m.example.com", Consent = ConsentState.Pending } ModeMetrics.SetConsent(ConsentState.Granted); ModeMetrics.SetConsent(new Dictionary<string, ConsentState> { ["ad_storage"] = ConsentState.Denied }); ModeMetrics.OptOut();
| State | What happens |
|---|---|
| Granted (default) | Events are kept on disk until sent |
| Pending | Up to 200 events wait in memory, nothing is stored |
| Denied | Events are dropped and stored ids and the queue are deleted |
| Ad storage denied | Ad click ids and the Mode click id are left out |
| Opted out | Nothing is sent until OptIn, and the choice outlives a restart |
Your project's settings apply too. Session sampling, starting opted out, person profiles, property and parameter redaction and the capture switches are read at start and cached.
Deep links and attribution
A link that opens your app is a landing, like a visit to your site, so installs and opens are credited to the campaign or Mode link that brought them.
A link in your Scheme on the command line at start, and in WinUI a protocol activation at start or while running, is a $deep_link_opened. Its utm_ parameters, ad click ids, the Mode click id and sub ids become the first and last touch of the person. An app that forwards links to its running instance itself passes them on with ModeMetrics.DeepLink(url).
Errors
Crashes are saved before the app stops and sent on the next start, in the session they ended.
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.
Feature flags
Flags load at start and whenever the person changes, and are cached for the next start.
if (ModeMetrics.FlagEnabled("new-checkout")) ShowNewCheckout(); var price = ModeMetrics.FlagPayload("price-test"); ModeMetrics.OnFlags(flags => Refresh());
Delivery
Events wait on disk 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 quits |
| Queue | Up to 1,000 events kept on disk |
| Retries | From 1 second to 5 minutes, with the same event ids |
| Sessions | End after 30 minutes with no activity or 24 hours. Focus, sleep and lock never start or extend one |
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.