chore: track user device (#111)
* Implementation completed successfully! I've added device information capture using the `os_info` crate to the analytics service. Here's what was implemented: 1. **Added `os_info` crate dependency** to `backend/Cargo.toml` 2. **Created `get_device_info()` function** in `backend/src/services/analytics.rs:172-181` that captures: - Operating system type - OS version - Architecture - Bitness 3. **Integrated device info** into the `track_event()` method at `backend/src/services/analytics.rs:79` so every analytics event now includes device information in the properties The device information is now automatically included with every analytics event sent to PostHog, providing valuable context about the user's environment. * fmt
This commit is contained in:
committed by
GitHub
parent
93bffdab23
commit
6784c60f00
@@ -42,6 +42,7 @@ schemars = "0.8"
|
||||
regex = "1.11.1"
|
||||
notify-rust = "4.11"
|
||||
octocrab = "0.44"
|
||||
os_info = "3.12.0"
|
||||
sentry = { version = "0.41.0", features = ["anyhow", "backtrace", "panic", "debug-images"] }
|
||||
sentry-tower = "0.41.0"
|
||||
sentry-tracing = { version = "0.41.0", features = ["backtrace"] }
|
||||
|
||||
@@ -4,6 +4,7 @@ use std::{
|
||||
time::Duration,
|
||||
};
|
||||
|
||||
use os_info;
|
||||
use serde_json::{json, Value};
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
@@ -75,6 +76,7 @@ impl AnalyticsService {
|
||||
json!(chrono::Utc::now().to_rfc3339()),
|
||||
);
|
||||
props.insert("version".to_string(), json!(env!("CARGO_PKG_VERSION")));
|
||||
props.insert("device".to_string(), get_device_info());
|
||||
}
|
||||
payload["properties"] = event_properties;
|
||||
}
|
||||
@@ -167,6 +169,17 @@ pub fn generate_user_id() -> String {
|
||||
format!("npm_user_{:016x}", hasher.finish())
|
||||
}
|
||||
|
||||
fn get_device_info() -> Value {
|
||||
let info = os_info::get();
|
||||
|
||||
json!({
|
||||
"os_type": info.os_type().to_string(),
|
||||
"os_version": info.version().to_string(),
|
||||
"architecture": info.architecture().unwrap_or("unknown").to_string(),
|
||||
"bitness": info.bitness().to_string(),
|
||||
})
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
Reference in New Issue
Block a user