Skip to main content

CommonLibrary/Telemetry/
CaptureEvent.rs

1#![allow(non_snake_case)]
2
3//! Emit a named PostHog event. Stamps the calling `Tier` plus the
4//! standard Land identity (`$app`, `$app_version`, `$build_mode`,
5//! `$component`, `$tier`) so dashboards can pivot by tier without
6//! caller changes.
7
8use crate::Telemetry::{Client, DistinctId, IsAllowed};
9
10pub fn Fn(EventName:&str, Properties:Option<Vec<(&str, &str)>>) {
11	if !IsAllowed::PostHog() {
12		return;
13	}
14
15	let Some(C) = Client::CLIENT.get() else { return };
16
17	let TierStr = Client::TIER.get().map(|T| T.AsStr()).unwrap_or("common");
18
19	let mut Event = posthog_rs::Event::new(EventName, &DistinctId::Fn());
20
21	let _ = Event.insert_prop("$app", "land-editor");
22	let _ = Event.insert_prop("$app_version", "0.0.1");
23	let _ = Event.insert_prop("$build_mode", "debug");
24	let _ = Event.insert_prop("$component", TierStr);
25	let _ = Event.insert_prop("$tier", TierStr);
26	let _ = Event.insert_prop("$lib", "land-common-telemetry");
27
28	if let Some(Props) = Properties {
29		for (Key, Value) in Props {
30			let _ = Event.insert_prop(Key, Value);
31		}
32	}
33
34	let _ = C.capture(Event);
35}