Skip to content

:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.

feat(desktop): capture os_platform and os_arch on analytics events (#83094)

Alessandro Pogliaghia4ec3300cdca
diff --git a/products/desktop/apps/code/src/main/platform-adapters/posthog-analytics.ts b/products/desktop/apps/code/src/main/platform-adapters/posthog-analytics.ts
index 27ef9c0e00f2..1f09f3a73191 100644
--- a/products/desktop/apps/code/src/main/platform-adapters/posthog-analytics.ts
+++ b/products/desktop/apps/code/src/main/platform-adapters/posthog-analytics.ts
@@ -60,6 +60,8 @@ export class PosthogNodeAnalytics implements IAnalytics {
team: "posthog-code",
...properties,
app_version: getAppVersion(),
+ os_platform: process.platform,
+ os_arch: process.arch,
$process_person_profile: !!this.currentUserId,
},
});
@@ -96,6 +98,8 @@ export class PosthogNodeAnalytics implements IAnalytics {
...additionalProperties,
...(this.sessionId ? { $session_id: this.sessionId } : {}),
app_version: getAppVersion(),
+ os_platform: process.platform,
+ os_arch: process.arch,
});
}
diff --git a/products/desktop/apps/code/src/renderer/contributions/app-boot.contributions.ts b/products/desktop/apps/code/src/renderer/contributions/app-boot.contributions.ts
index d3ef4a3f0c75..7ccb31aaaf3e 100644
--- a/products/desktop/apps/code/src/renderer/contributions/app-boot.contributions.ts
+++ b/products/desktop/apps/code/src/renderer/contributions/app-boot.contributions.ts
@@ -2,6 +2,7 @@ import type { Contribution } from "@posthog/di/contribution";
import {
initializePostHog,
registerAppVersion,
+ registerHostInfo,
} from "@posthog/ui/shell/posthogAnalyticsImpl";
import { trpcClient } from "@renderer/trpc/client";
import { logger } from "@utils/logger";
@@ -22,12 +23,16 @@ export class AnalyticsBootContribution implements Contribution {
}
initializePostHog(sessionId);
}
- trpcClient.os.getAppVersion
- .query()
- .then(registerAppVersion)
- .catch((error) => {
- log.warn("Failed to register app version super property", { error });
- });
+ try {
+ registerAppVersion(await trpcClient.os.getAppVersion.query());
+ } catch (error) {
+ log.warn("Failed to register app version super property", { error });
+ }
+ try {
+ registerHostInfo(await trpcClient.os.getHostInfo.query());
+ } catch (error) {
+ log.warn("Failed to register host info super properties", { error });
+ }
})();
}
}
diff --git a/products/desktop/packages/host-router/src/routers/os.router.ts b/products/desktop/packages/host-router/src/routers/os.router.ts
index 2f8e660fa054..74a5ed4cf1b3 100644
--- a/products/desktop/packages/host-router/src/routers/os.router.ts
+++ b/products/desktop/packages/host-router/src/routers/os.router.ts
@@ -9,6 +9,7 @@ import {
checkWriteAccessInput,
claudePermissionsOutput,
downscaleImageFileInput,
+ hostInfoOutput,
openExternalInput,
readFileAsDataUrlInput,
saveClipboardFileInput,
@@ -84,6 +85,10 @@ export const osRouter = router({
ctx.container.get<OsService>(OS_SERVICE).getAppVersion(),
),
+ getHostInfo: publicProcedure
+ .output(hostInfoOutput)
+ .query(({ ctx }) => ctx.container.get<OsService>(OS_SERVICE).getHostInfo()),
+
getWorktreeLocation: publicProcedure.query(({ ctx }) =>
ctx.container.get<OsService>(OS_SERVICE).getWorktreeLocation(),
),
diff --git a/products/desktop/packages/ui/src/shell/posthogAnalyticsImpl.ts b/products/desktop/packages/ui/src/shell/posthogAnalyticsImpl.ts
index bbdcc88aea6c..eb353fefb3bb 100644
--- a/products/desktop/packages/ui/src/shell/posthogAnalyticsImpl.ts
+++ b/products/desktop/packages/ui/src/shell/posthogAnalyticsImpl.ts
@@ -29,10 +29,13 @@ const log = logger.scope("analytics");
// posthog's frontend/src/scenes/inbox/inboxAnalytics.ts.
const INBOX_CLIENT = "code" as const;
+export type HostInfoProperties = { platform: string; arch: string };
+
let isInitialized = false;
// Cached so it can be re-applied after posthog.reset() clears super properties.
let registeredAppVersion: string | null = null;
+let registeredHostInfo: HostInfoProperties | null = null;
// posthog.reset() wipes super properties, so these are re-registered after each reset.
function registerPersistentSuperProperties() {
@@ -41,9 +44,19 @@ function registerPersistentSuperProperties() {
...(registeredAppVersion !== null
? { app_version: registeredAppVersion }
: {}),
+ ...(registeredHostInfo !== null
+ ? hostInfoProperties(registeredHostInfo)
+ : {}),
});
}
+function hostInfoProperties({ platform, arch }: HostInfoProperties): {
+ os_platform: string;
+ os_arch: string;
+} {
+ return { os_platform: platform, os_arch: arch };
+}
+
type PendingFlagListener = {
callback: () => void;
unsubscribe: (() => void) | null;
@@ -178,6 +191,16 @@ export function registerAppVersion(appVersion: string) {
posthog.register({ app_version: appVersion });
}
+export function registerHostInfo(hostInfo: HostInfoProperties) {
+ registeredHostInfo = hostInfo;
+
+ if (!isInitialized) {
+ return;
+ }
+
+ posthog.register(hostInfoProperties(hostInfo));
+}
+
export function identifyUser(
userId: string,
properties?: UserIdentifyProperties,
diff --git a/products/desktop/packages/workspace-server/src/services/os/os.ts b/products/desktop/packages/workspace-server/src/services/os/os.ts
index 159062045552..8251a3aec518 100644
--- a/products/desktop/packages/workspace-server/src/services/os/os.ts
+++ b/products/desktop/packages/workspace-server/src/services/os/os.ts
@@ -32,6 +32,7 @@ import {
import { inject, injectable } from "inversify";
import type {
ClaudePermissions,
+ HostInfo,
ImageAttachment,
MessageBoxOptions,
SavedAttachment,
@@ -470,6 +471,10 @@ export class OsService {
return this.appMeta.version;
}
+ getHostInfo(): HostInfo {
+ return { platform: this.appMeta.platform, arch: this.appMeta.arch };
+ }
+
getWorktreeLocation(): string {
return this.workspaceSettings.getWorktreeLocation();
}
diff --git a/products/desktop/packages/workspace-server/src/services/os/schemas.ts b/products/desktop/packages/workspace-server/src/services/os/schemas.ts
index c11546665427..c50196f1bb74 100644
--- a/products/desktop/packages/workspace-server/src/services/os/schemas.ts
+++ b/products/desktop/packages/workspace-server/src/services/os/schemas.ts
@@ -100,6 +100,12 @@ export const saveClipboardFileInput = z.object({
originalName: z.string().optional(),
});
+export const hostInfoOutput = z.object({
+ platform: z.string(),
+ arch: z.string(),
+});
+export type HostInfo = z.infer<typeof hostInfoOutput>;
+
export interface SavedAttachment {
path: string;
name: string;