#[cfg(feature = "analytics")]
mod event;
use crate::AppEnvironment;
use crate::StartupOptions;
pub struct ViewerAnalytics {
#[cfg(feature = "analytics")]
app_env: AppEnvironment,
#[cfg(feature = "analytics")]
analytics: Option<re_analytics::Analytics>,
}
impl ViewerAnalytics {
#[allow(unused_mut, clippy::let_and_return)]
pub fn new(startup_options: &StartupOptions, app_env: AppEnvironment) -> Self {
re_tracing::profile_function!();
#[cfg(feature = "analytics")]
{
let analytics = {
if startup_options.is_in_notebook {
None
} else {
match re_analytics::Analytics::new(std::time::Duration::from_secs(2)) {
Ok(analytics) => Some(analytics),
Err(err) => {
re_log::error!(%err, "failed to initialize analytics SDK");
None
}
}
}
};
Self { app_env, analytics }
}
#[cfg(not(feature = "analytics"))]
{
let _ = (startup_options, app_env);
Self {}
}
}
pub fn on_viewer_started(&self, build_info: re_build_info::BuildInfo) {
re_tracing::profile_function!();
#[cfg(feature = "analytics")]
{
let Some(analytics) = self.analytics.as_ref() else {
return;
};
analytics.record(event::identify(
analytics.config(),
build_info,
&self.app_env,
));
analytics.record(event::viewer_started(&self.app_env));
}
#[cfg(not(feature = "analytics"))]
let _ = build_info;
}
pub fn on_open_recording(&self, entity_db: &re_entity_db::EntityDb) {
#[cfg(feature = "analytics")]
{
if entity_db.store_kind() != re_log_types::StoreKind::Recording {
return;
}
let Some(analytics) = self.analytics.as_ref() else {
return;
};
analytics.record(event::open_recording(&self.app_env, entity_db));
}
#[cfg(not(feature = "analytics"))]
let _ = entity_db;
}
}