Skip to content

The VS Code of video editing, built for agents.

TypeScript

Enhance analytics tracking in desktop and web applications

konstantin-paulus3e376ca95f85
diff --git a/apps/desktop/src/analytics.ts b/apps/desktop/src/analytics.ts
index ff536c64..ad52d07f 100644
--- a/apps/desktop/src/analytics.ts
+++ b/apps/desktop/src/analytics.ts
@@ -8,6 +8,7 @@ import { join } from "node:path";
import { stat, writeFile } from "node:fs/promises";
import type { ClientEventName, TrackedEvent, TrackProps } from "@diffusionstudio/api-contract";
+import type { WindowHost } from "./window-host";
const enabled = app.isPackaged || process.env.DIFFUSION_ANALYTICS === "1";
@@ -57,14 +58,15 @@ export function countCodeChange(path: string): void {
}
/**
- * Starts the flush timer and records the launch. The first launch of an
+ * Starts the flush and usage timers and records the launch. The first launch of an
* install is recorded once, guarded by a marker file in `userData`; its age
* goes on every `app_opened`, so install-to-sign-up time needs no device id.
*/
-export async function startAnalytics(): Promise<void> {
+export async function startAnalytics(windows: WindowHost): Promise<void> {
if (!enabled) return;
setInterval(flush, FLUSH_INTERVAL_MS);
+ setInterval(() => (windows.current() && track("app_used")), 60_000);
const marker = join(app.getPath("userData"), "install-tracked");
const installedAt = await stat(marker).then((info) => info.birthtimeMs, () => null);
diff --git a/apps/desktop/src/main.ts b/apps/desktop/src/main.ts
index bba51fa8..4354e0dc 100644
--- a/apps/desktop/src/main.ts
+++ b/apps/desktop/src/main.ts
@@ -511,7 +511,7 @@ if (squirrelLaunch) {
);
refreshCliShim();
healMcpRegistrations();
- startAnalytics();
+ startAnalytics(windows);
tray.start();
// Opened by a person (Finder, Dock, Start menu): show the editor
diff --git a/apps/web/src/lib/analytics.ts b/apps/web/src/lib/analytics.ts
index f70acec0..88588c3f 100644
--- a/apps/web/src/lib/analytics.ts
+++ b/apps/web/src/lib/analytics.ts
@@ -20,6 +20,12 @@ export function initAnalytics(): void {
// The desktop app's launch is recorded by main: once per launch, not per window.
if (!window.desktop) {
track("app_opened");
+
+ setInterval(() => {
+ if (document.visibilityState === "visible") {
+ track("app_used");
+ }
+ }, 60_000);
}
setInterval(() => {