How the Linux SDK works
One setup call in a GTK or Qt 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 |
|---|---|
| Libraries | mode_gtk4, mode_gtk3 or mode_qt on the Mode C core, library mode-linux |
| 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 |
| Toolkits | GTK 4 and GTK 3, Qt 6 and Qt 5, Qt Widgets and QML |
| 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
Download the C core and the layer for your toolkit from Mode, and add both to your CMake build.
curl -fsSLO https://gotmode.com/sdk/c/0.2.0/mode-metrics-c-0.2.0.zip curl -fsSLO https://gotmode.com/sdk/c/0.1.0/mode-metrics-gtk-0.1.0.zip # or mode-metrics-qt-0.1.0.zip for Qt echo "a8206287778d87d14fe34ae4303b5b19eb7db322909b56589b6c72a37f191f59 mode-metrics-c-0.2.0.zip 0fdd7df96730d66e2dcf12ceb549dd6924c59698a632953c05823687b137ad34 mode-metrics-gtk-0.1.0.zip" | shasum -a 256 -c unzip mode-metrics-c-0.2.0.zip && unzip mode-metrics-gtk-0.1.0.zip
add_subdirectory(path/to/mode-metrics-c-0.2.0) # the core add_subdirectory(path/to/mode-metrics-gtk-0.1.0) # or mode-metrics-qt-0.1.0 target_link_libraries(myapp PRIVATE mode_gtk4) # mode_gtk3 or mode_qt
For Qt 5, set MODE_QT_MAJOR to 5 before adding the Qt layer. Each layer is a package of its own on the core, so an app builds only its toolkit.
| File | Version | SHA-256 |
|---|---|---|
mode-metrics-c-0.2.0.zip | 0.2.0 | a8206287778d87d14fe34ae4303b5b19eb7db322909b56589b6c72a37f191f59 |
mode-metrics-gtk-0.1.0.zip | 0.1.0 | 0fdd7df96730d66e2dcf12ceb549dd6924c59698a632953c05823687b137ad34 |
mode-metrics-qt-0.1.0.zip | 0.1.0 | 940c946c4b3089d7b7262bf7c82197d55ce9e3605fdba71386b5cba42812550f |
The GTK layer needs GLib, GIO and GTK, which your app already has. The Qt layer needs QtCore, QtGui and QtWidgets, and uses QtQuick and QtDBus when they are installed. With libcurl the SDK sends on a thread of its own and compresses with zlib.
Setup
Call the setup once. Everything in What is captured automatically starts from that call.
/* GTK, in your GApplication's startup handler */ #include "mode_gtk.h" static void on_startup(GApplication *app, gpointer data) { mode_gtk_options o; mode_gtk_options_defaults(&o); o.key = "YOUR_INGEST_KEY"; o.host = "https://m.example.com"; o.app_version = "2.3.0"; o.scheme = "myapp"; mode_gtk_setup(GTK_APPLICATION(app), &o); }
// Qt, once the QApplication or QGuiApplication exists #include "ModeMetrics.h" QApplication app(argc, argv); ModeMetrics::Options o; o.appVersion = "2.3.0"; o.scheme = "myapp"; ModeMetrics::setup("YOUR_INGEST_KEY", "https://m.example.com", o);
A GTK app without a GtkApplication passes NULL. The app id names the data folder, ~/.local/state/mode-metrics/{app id}. GTK reads it from the application, Qt from the desktop file name or the organization domain and application name, unless you set it. scheme is your app's own link scheme.
Events, people and groups
The setup returns the client, and every call of the C core works on it. Properties are JSON text.
mode_client *mode = mode_gtk_client(); /* ModeMetrics::client() in Qt */ mode_capture(mode, "order_placed", "{\"total\":49}"); mode_identify(mode, "user_42", "{\"plan\":\"pro\"}", NULL); /* after sign in */ mode_group(mode, "company", "acme", NULL); mode_register(mode, "{\"edition\":\"pro\"}"); /* on every event */ mode_reset(mode); /* on sign out */
Also mode_alias, mode_set_person_properties, mode_unset_person_properties, mode_register_once, mode_register_for_session, mode_unregister and mode_flush. Every call is safe from any thread and none waits on the network. A different user signing in on the same computer becomes a new person, never a merge. 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 the setup. Turn a part off with the autocapture bits, or from your project's settings.
| Event | When |
|---|---|
$app_installed, $app_updated, $app_opened | The first start, a new version, the first window shown 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 quits, then what is queued is sent, waiting at most 2 seconds |
$window_opened, $window_closed, $window_focus, $window_blur | Every window, named by its widget or object name or its type |
$screen | GTK stack and notebook pages, Qt stacked widget and tab widget pages, QML StackView items, and the window when nothing in it names a page |
$click, $rage_click | Clicks and key presses on buttons, toggles, check and radio buttons, switches, menus, tabs, combo boxes, sliders, lists and text fields, and in QML the control under the pointer, with its type, text, path, name, accessible name and role |
$deep_link_opened | A link in your scheme starts the app, or reaches a running GTK app |
$system_suspend, $system_resume, $system_lock, $system_unlock | The computer sleeps, wakes, locks and unlocks, read from logind and the screensaver |
$exception | A fatal signal, a run that ended without quitting, and in Qt an uncaught C++ exception and qFatal, sent on the next start in the session they ended |
The first event of each session carries the device (kernel release, pixel ratio, dark mode, reduced motion, toolkit and version, languages, memory and cores), never a host name, user name or machine id. Every crash handler hands the signal on to the one installed before it, so KDE's crash handler, breakpad and your own keep working.
Text and privacy
A clicked control's text is scrubbed of emails and long numbers and cut to 80 characters. A text field never sends its text.
A click on an entry, text view, spin button or password field is a $click with role textbox and nothing typed. Set mask_text (maskText in Qt) to leave every control's text 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].
Consent and opt out
Start with consent pending, and nothing is written to disk or sent until the person answers.
o.consent = MODE_CONSENT_PENDING; mode_set_consent(mode_gtk_client(), 1, 0); /* analytics granted, ads denied */ mode_opt_out(mode_gtk_client());
| 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 |
| Ad storage denied | Ad click ids and the Mode click id are left out |
| Opted out | Nothing is sent until mode_opt_in, 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, and the first send waits up to 3 seconds for them.
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, as your desktop file's Exec=myapp %u passes it, and a GTK application's open, 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. A link the SDK cannot see, such as one a single instance app forwards to itself, goes through mode_deep_link(mode, url, 0).
Feature flags
Flags load at start and whenever the person changes.
if (mode_is_feature_enabled(mode, "new-checkout")) show_new_checkout(); char *price = mode_get_flag_payload(mode, "price-test"); mode_free(price);
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, when the app goes to the background and when it 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 |