irongit

Git hosting and a container registry in one Rust binary (axum + Astro)

Analytics: omit user_id for anonymous server-side events

huncholanehuncholaneauthored
parent 77024a6commit 96dacb2f070dcf11bd9072f47d0c89876b2e1e3aBrowse files

1 file changed, +5 -2

+5-2backend/src/analytics.rs
@@ -13,16 +13,19 @@ pub fn track(state: &AppState, event: &str, user: Option<&str>, path: &str, prop
1313 };
1414 let http = state.http.clone();
1515 let hostname = state.config.public_url.host_str().unwrap_or("localhost").to_string();
16- let body = json!({
16+ let mut body = json!({
1717 "type": "custom_event",
1818 "site_id": rybbit.site_id,
1919 "event_name": event,
2020 "properties": properties.to_string(),
2121 "hostname": hostname,
2222 "pathname": path,
23- "user_id": user,
2423 "user_agent": "irongit-server",
2524 });
25+ // The tracker rejects `user_id: null`; anonymous events leave it out.
26+ if let Some(user) = user {
27+ body["user_id"] = json!(user);
28+ }
2629 let event = event.to_string();
2730 tokio::spawn(async move {
2831 let mut url = format!("{}/api/track", rybbit.host.trim_end_matches('/'));