Skip to content

Commit 9071d48

Browse files
authored
Add analytics for show_main_window (#812)
1 parent d40cd82 commit 9071d48

File tree

6 files changed

+38
-9
lines changed

6 files changed

+38
-9
lines changed

Cargo.lock

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

apps/desktop/src-tauri/src/ext.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ impl<R: tauri::Runtime, T: tauri::Manager<R>> AppExt<R> for T {
116116
.build();
117117

118118
if let Err(e) = self.event(e).await {
119-
tracing::error!("failed_to_track_user_creation: {}", e);
119+
tracing::error!("failed_to_send_analytics: {}", e);
120120
}
121121
}
122122

crates/analytics/src/lib.rs

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,15 @@ impl AnalyticsClient {
2828

2929
let inner_event = posthog_core::event::InnerEvent::new(e, self.api_key.clone());
3030

31-
let _ = self
32-
.client
33-
.post("https://us.i.posthog.com/capture/")
34-
.json(&inner_event)
35-
.send()
36-
.await?
37-
.error_for_status()?;
31+
if !cfg!(debug_assertions) {
32+
let _ = self
33+
.client
34+
.post("https://us.i.posthog.com/capture/")
35+
.json(&inner_event)
36+
.send()
37+
.await?
38+
.error_for_status()?;
39+
}
3840

3941
Ok(())
4042
}

plugins/windows/Cargo.toml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,11 @@ specta = { workspace = true }
1919
strum = { workspace = true, features = ["derive"] }
2020

2121
tauri = { workspace = true, features = ["test"] }
22-
tauri-plugin-decorum = { workspace = true }
2322
tauri-specta = { workspace = true, features = ["derive", "typescript"] }
2423

24+
tauri-plugin-analytics = { workspace = true }
25+
tauri-plugin-auth = { workspace = true }
26+
tauri-plugin-decorum = { workspace = true }
27+
2528
thiserror = { workspace = true }
2629
tracing = { workspace = true }

plugins/windows/src/errors.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ use serde::{ser::Serializer, Serialize};
44
pub enum Error {
55
#[error(transparent)]
66
TauriError(#[from] tauri::Error),
7+
#[error(transparent)]
8+
AuthError(#[from] tauri_plugin_auth::Error),
79
#[error("monitor not found")]
810
MonitorNotFound,
911
}

plugins/windows/src/ext.rs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -246,6 +246,26 @@ impl HyprWindow {
246246
}
247247

248248
pub fn show(&self, app: &AppHandle<tauri::Wry>) -> Result<WebviewWindow, crate::Error> {
249+
if self == &Self::Main {
250+
use tauri_plugin_analytics::{hypr_analytics::AnalyticsPayload, AnalyticsPluginExt};
251+
use tauri_plugin_auth::{AuthPluginExt, StoreKey};
252+
253+
let user_id = app
254+
.get_from_store(StoreKey::UserId)?
255+
.unwrap_or("UNKNOWN".into());
256+
257+
let e = AnalyticsPayload::for_user(user_id)
258+
.event("show_main_window")
259+
.build();
260+
261+
let app_clone = app.clone();
262+
tauri::async_runtime::spawn(async move {
263+
if let Err(e) = app_clone.event(e).await {
264+
tracing::error!("failed_to_send_analytics: {:?}", e);
265+
}
266+
});
267+
}
268+
249269
let (window, created) = match self.get(app) {
250270
Some(window) => (window, false),
251271
None => {

0 commit comments

Comments
 (0)