Skip to content

Open source Grok Bot alternative, Bring your own agent and subscription: message Claude Code, Codex, Gemini CLI, Cursor, Copilot and 40+ AI agents as bots on your own computer, from iPhone, Mac, Windows, Linux or terminal. Agent-agnostic and free. Also a Muse and Dots alternative. Built in Rust.

feat: link a phone's usage to its computer

leepokaide6a4673d07b
diff --git a/apps/ios/App/CodyncApp.swift b/apps/ios/App/CodyncApp.swift
index e17bd2e8..7eb1b295 100644
--- a/apps/ios/App/CodyncApp.swift
+++ b/apps/ios/App/CodyncApp.swift
@@ -218,7 +218,7 @@ final class AppStore {
func pair(_ pairing: Pairing) async throws -> Computer {
let computer = try await accounts.pair(pairing, deviceName: UIDevice.current.name, platform: "ios")
- Analytics.shared.capture(.computerPaired, ["via": "qr"])
+ Analytics.shared.capture(.computerPaired, ["via": "qr", "computer": Analytics.computerTag(computer.id)])
return computer
}
diff --git a/apps/ios/Kit/Sources/CodyncKit/Analytics/Analytics.swift b/apps/ios/Kit/Sources/CodyncKit/Analytics/Analytics.swift
index 0a4ada5f..eb0bc163 100644
--- a/apps/ios/Kit/Sources/CodyncKit/Analytics/Analytics.swift
+++ b/apps/ios/Kit/Sources/CodyncKit/Analytics/Analytics.swift
@@ -1,3 +1,4 @@
+import CryptoKit
import Foundation
/// What the iPhone reports. Bot and message events come from the computer's host instead.
@@ -97,6 +98,12 @@ public final class Analytics {
}
}
+ /// A computer's analytics key, the same hash its host sends: joins `computer_paired` with that
+ /// computer's events without revealing the id the relay knows it by.
+ public static func computerTag(_ id: ComputerID) -> String {
+ SHA256.hash(data: Data("codync-analytics:\(id)".utf8)).prefix(8).map { String(format: "%02x", $0) }.joined()
+ }
+
/// `app_opened` once per trip to the foreground (`.inactive` blips don't count).
public func becameActive() {
guard !foreground else { return }
diff --git a/apps/ios/Kit/Sources/CodyncUI/Store/AccountStore.swift b/apps/ios/Kit/Sources/CodyncUI/Store/AccountStore.swift
index 6168c5ab..f712f303 100644
--- a/apps/ios/Kit/Sources/CodyncUI/Store/AccountStore.swift
+++ b/apps/ios/Kit/Sources/CodyncUI/Store/AccountStore.swift
@@ -265,7 +265,7 @@ public final class AccountStore {
cloud: cloud.baseURL, device: target.device)
save(computer)
open(computer)
- Analytics.shared.capture(.computerPaired, ["via": "account"])
+ Analytics.shared.capture(.computerPaired, ["via": "account", "computer": Analytics.computerTag(computer.id)])
await refreshCloud()
return
case .denied, .expired, .cancelled:
diff --git a/apps/ios/Kit/Tests/CodyncKitTests/AnalyticsTests.swift b/apps/ios/Kit/Tests/CodyncKitTests/AnalyticsTests.swift
index 9661c9e4..101c8b02 100644
--- a/apps/ios/Kit/Tests/CodyncKitTests/AnalyticsTests.swift
+++ b/apps/ios/Kit/Tests/CodyncKitTests/AnalyticsTests.swift
@@ -37,6 +37,9 @@ import Testing
#expect(identify.properties["$anon_distinct_id"] == .string(anon.distinct_id))
#expect(analytics.pending[2].properties["$process_person_profile"] == .bool(true))
+ // The computer key matches the host's (host/src/analytics.rs `computer_tag_matches_the_iphone`).
+ #expect(Analytics.computerTag("AAECAwQFBgcICQoLDA0ODw") == "2d6878bee20aba04")
+
// Turning it off drops what wasn't sent.
analytics.setEnabled(false)
#expect(analytics.pending.isEmpty)
diff --git a/docs/features/analytics.md b/docs/features/analytics.md
index 491baa5d..68a52475 100644
--- a/docs/features/analytics.md
+++ b/docs/features/analytics.md
@@ -29,7 +29,7 @@ Settings anytime. The public promise lives in `web/app/privacy/page.tsx`: keep i
`clientNonce`, e.g. a phone replaying after a reconnect) is not counted again. Bot actors
report `turn_finished` when an agent's turn ends. `client` is `local` (desktop app, terminal UI)
or `remote` (phones). Each event carries its own `timestamp` and `uuid` (a resent batch counts
- once) and the computer's `host_id`; batches go to `/batch/` every 30 s and once more when the
+ once) and the computer's key (`computer`, a hash of its id); batches go to `/batch/` every 30 s and once more when the
host stops.
- **Desktop** reports app-level events through the loopback-only `track` method
(`app_opened`, `onboarding_completed` when the welcome screen is finished, `signed_in`,
@@ -54,15 +54,16 @@ Besides `env`, `app_version`, `$os`, `$lib`:
| `voice_call_finished` | `seconds` |
| `connector_installed` | `connector` (catalog name or `custom`) |
| `skill_installed` | `custom` |
-| `computer_paired` | `via` (`qr`/`account`) |
-| every host event | `client` (`local`/`remote`), `host_id`, `arch` |
+| `computer_paired` | `via` (`qr`/`account`), `computer` |
+| every host event | `client` (`local`/`remote`), `computer`, `arch` |
## Metrics
Shared filters: `env = 'main'`, internal accounts excluded, UTC days. A *user* is a PostHog
person: the account when signed in, otherwise one install, so an anonymous iPhone and an
anonymous computer are two users until both sign in. Messages are recorded by the computer,
-so an anonymous iPhone's chats count for its computer.
+so an anonymous iPhone's chats count for its computer. To count people rather than devices,
+join an iPhone's `computer_paired` to the computer's events on `computer` in SQL.
| Metric | Definition |
|---|---|
diff --git a/host/src/analytics.rs b/host/src/analytics.rs
index 38af12b4..6b51636d 100644
--- a/host/src/analytics.rs
+++ b/host/src/analytics.rs
@@ -278,7 +278,7 @@ fn queue(hub: &Hub, event: &str, distinct_id: &str, mut properties: Map<String,
("arch".into(), std::env::consts::ARCH.into()),
("$geoip_disable".into(), true.into()),
// Joins this computer's events across accounts and with its phones' `computer_paired`.
- ("host_id".into(), hub.host_id.clone().into()),
+ ("computer".into(), computer_tag(&hub.identity.computer_id()).into()),
]);
let _ = hub.analytics.tx.send(Msg::Event(json!({
"event": event,
@@ -290,6 +290,18 @@ fn queue(hub: &Hub, event: &str, distinct_id: &str, mut properties: Map<String,
})));
}
+/// A computer's analytics key: a hash of its id, so a phone's `computer_paired` joins the
+/// computer's events without revealing the id the relay knows it by.
+pub fn computer_tag(computer_id: &str) -> String {
+ use sha2::{Digest as _, Sha256};
+ use std::fmt::Write as _;
+ let hash = Sha256::digest(format!("codync-analytics:{computer_id}"));
+ hash[..8].iter().fold(String::new(), |mut s, b| {
+ let _ = write!(s, "{b:02x}");
+ s
+ })
+}
+
/// Sends queued events in batches every `FLUSH_EVERY`; until the owner answers they wait,
/// and a no drops them.
pub fn start(hub: &Arc<Hub>) {
@@ -393,6 +405,12 @@ mod tests {
std::fs::remove_dir_all(&dir).unwrap();
}
+ #[test]
+ fn computer_tag_matches_the_iphone() {
+ // Same vector as the iPhone's AnalyticsTests.
+ assert_eq!(computer_tag("AAECAwQFBgcICQoLDA0ODw"), "2d6878bee20aba04");
+ }
+
#[test]
fn only_app_events_can_be_tracked_directly() {
assert!(Event::deserialize(&json!("app_opened")).is_ok_and(Event::client_reported));