Skip to content

YC (S26) | Open Computer History | Continuously record your company computer work, map your workflows, help you find work worth automating, and power your agents' context

feat(analytics): tag engine telemetry with distribution (app/cli/source)

Louis Beaumontdde2f8ad2f31
diff --git a/apps/screenpipe-app-tauri/src-tauri/src/server_core.rs b/apps/screenpipe-app-tauri/src-tauri/src/server_core.rs
index b4605aeb3..65da17403 100644
--- a/apps/screenpipe-app-tauri/src-tauri/src/server_core.rs
+++ b/apps/screenpipe-app-tauri/src-tauri/src/server_core.rs
@@ -83,6 +83,11 @@ impl ServerCore {
if !config.analytics_id.is_empty() {
std::env::set_var("SCREENPIPE_ANALYTICS_ID", &config.analytics_id);
}
+ // Tag engine telemetry as the desktop app (vs cli / source) so WAU can be
+ // split by distribution. Respect an explicit override (e.g. enterprise embeds).
+ if std::env::var("SCREENPIPE_DISTRIBUTION").is_err() {
+ std::env::set_var("SCREENPIPE_DISTRIBUTION", "desktop-app");
+ }
analytics::init(config.analytics_enabled);
if config.use_chinese_mirror {
diff --git a/crates/screenpipe-engine/src/telemetry_context.rs b/crates/screenpipe-engine/src/telemetry_context.rs
index f034face2..8dbb51c57 100644
--- a/crates/screenpipe-engine/src/telemetry_context.rs
+++ b/crates/screenpipe-engine/src/telemetry_context.rs
@@ -32,6 +32,23 @@ const EMBEDDER_VERSION_ENV_VARS: &[&str] = &[
"SCREENPIPE_HOST_VERSION",
"SCREENPIPE_TELEMETRY_HOST_VERSION",
];
+const DISTRIBUTION_ENV_VARS: &[&str] = &["SCREENPIPE_DISTRIBUTION", "SCREENPIPE_DIST"];
+
+/// How this engine was launched: "desktop-app" (Tauri app), "cli" (npm/bunx),
+/// or "source"/"source-dev" (built locally). The app and CLI set
+/// `SCREENPIPE_DISTRIBUTION` explicitly; without it we infer a source build
+/// (debug = dev). Lets analytics split the free OSS engine WAU from the signed
+/// app and paying users.
+pub fn resolve_distribution() -> String {
+ if let Some(value) = first_env(DISTRIBUTION_ENV_VARS) {
+ return value;
+ }
+ if cfg!(debug_assertions) {
+ "source-dev".to_string()
+ } else {
+ "source".to_string()
+ }
+}
#[derive(Debug, Clone, Default, PartialEq, Eq)]
pub struct TelemetryContext {
@@ -83,21 +100,31 @@ impl TelemetryContext {
}
pub fn insert_posthog_properties(&self, properties: &mut Map<String, Value>) {
- let pairs = self.pairs();
- if pairs.is_empty() {
- return;
- }
+ // Distribution channel (desktop-app / cli / source) is ALWAYS tagged —
+ // even with no enterprise context — so every engine event and person can
+ // be split by how screenpipe was installed (separates the free OSS engine
+ // WAU from the signed app + paid users).
+ let distribution = resolve_distribution();
+ properties.insert(
+ "screenpipe_distribution".to_string(),
+ json!(distribution.clone()),
+ );
- for (key, value) in &pairs {
- properties.insert((*key).to_string(), json!(value));
- }
+ let pairs = self.pairs();
+ // Mirror onto $set so the PERSON is tagged (sticky, segmentable like
+ // subscription_plan), including distribution and any enterprise context.
let set = properties.entry("$set").or_insert_with(|| json!({}));
if let Some(set_obj) = set.as_object_mut() {
- for (key, value) in pairs {
- set_obj.insert(key.to_string(), json!(value));
+ set_obj.insert("screenpipe_distribution".to_string(), json!(distribution));
+ for (key, value) in &pairs {
+ set_obj.insert((*key).to_string(), json!(value));
}
}
+
+ for (key, value) in &pairs {
+ properties.insert((*key).to_string(), json!(value));
+ }
}
}
@@ -142,6 +169,8 @@ mod tests {
"SCREENPIPE_EMBEDDER_VERSION",
"SCREENPIPE_HOST_VERSION",
"SCREENPIPE_TELEMETRY_HOST_VERSION",
+ "SCREENPIPE_DISTRIBUTION",
+ "SCREENPIPE_DIST",
];
fn with_env<T>(pairs: &[(&str, &str)], test: impl FnOnce() -> T) -> T {
@@ -233,4 +262,36 @@ mod tests {
},
);
}
+
+ #[test]
+ fn distribution_prefers_env_then_falls_back_to_source() {
+ with_env(&[("SCREENPIPE_DISTRIBUTION", "desktop-app")], || {
+ assert_eq!(resolve_distribution(), "desktop-app");
+ });
+ with_env(&[], || {
+ // no launcher env -> inferred source build (dev under `cargo test`)
+ assert!(resolve_distribution().starts_with("source"));
+ });
+ }
+
+ #[test]
+ fn distribution_always_tagged_even_without_context() {
+ with_env(&[("SCREENPIPE_DISTRIBUTION", "cli")], || {
+ let context = TelemetryContext::from_env();
+ assert!(context.is_empty(), "no enterprise context expected");
+
+ let mut properties = Map::new();
+ context.insert_posthog_properties(&mut properties);
+
+ assert_eq!(
+ properties.get("screenpipe_distribution"),
+ Some(&json!("cli"))
+ );
+ let set = properties.get("$set").and_then(|value| value.as_object());
+ assert_eq!(
+ set.and_then(|value| value.get("screenpipe_distribution")),
+ Some(&json!("cli"))
+ );
+ });
+ }
}
diff --git a/packages/cli/screenpipe/lib/cli.js b/packages/cli/screenpipe/lib/cli.js
index 48244ce3c..2b6354a97 100755
--- a/packages/cli/screenpipe/lib/cli.js
+++ b/packages/cli/screenpipe/lib/cli.js
@@ -21,7 +21,12 @@ if (!bin) {
process.exit(1);
}
-const child = spawn(bin, process.argv.slice(2), { stdio: "inherit" });
+// Tag engine telemetry as the npm/bunx CLI (vs desktop-app / source) so WAU can
+// be split by distribution. Respect an explicit override if one is already set.
+const child = spawn(bin, process.argv.slice(2), {
+ stdio: "inherit",
+ env: { ...process.env, SCREENPIPE_DISTRIBUTION: process.env.SCREENPIPE_DISTRIBUTION || "cli" },
+});
let forwardingSignal = null;
child.on("error", (error) => {