diff --git a/server/bleep/src/webserver/config.rs b/server/bleep/src/webserver/config.rs index 254e73640c..339e1f68be 100644 --- a/server/bleep/src/webserver/config.rs +++ b/server/bleep/src/webserver/config.rs @@ -56,22 +56,6 @@ pub(super) async fn get( .and_then(|login| app.user_profiles.read(login, |_, v| v.clone())) .unwrap_or_default(); - if let Some(username) = user.login() { - app.with_analytics(|analytics| { - use rudderanalytics::message::{Identify, Message}; - analytics.send(Message::Identify(Identify { - user_id: Some(tracking_id.clone()), - traits: Some(serde_json::json!({ - "org_name": app.org_name(), - "device_id": analytics.device_id(), - "is_self_serve": app.env.is_cloud_instance(), - "github_username": username.to_string(), - })), - ..Default::default() - })); - }); - } - json(ConfigResponse { analytics_data_plane: app.config.analytics_data_plane.clone(), analytics_key_fe: app.config.analytics_key_fe.clone(), diff --git a/server/bleep/src/webserver/github.rs b/server/bleep/src/webserver/github.rs index deb908cfd9..e562fd8322 100644 --- a/server/bleep/src/webserver/github.rs +++ b/server/bleep/src/webserver/github.rs @@ -184,6 +184,37 @@ async fn poll_for_oauth_token(code: String, app: Application) { debug!("acquired credentials"); app.credentials.set_github(github::Auth::OAuth(auth)); + let username = app + .credentials + .github() + .unwrap() + .client() + .unwrap() + .current() + .user() + .await + .unwrap() + .login; + + let tracking_id = app + .analytics + .as_ref() + .map(|a| a.tracking_id(Some(&username))) + .unwrap_or_default(); + + app.with_analytics(|analytics| { + use rudderanalytics::message::{Identify, Message}; + analytics.send(Message::Identify(Identify { + user_id: Some(tracking_id.clone()), + traits: Some(serde_json::json!({ + "org_name": app.org_name(), + "device_id": analytics.device_id(), + "is_self_serve": app.env.is_cloud_instance(), + "github_username": username, + })), + ..Default::default() + })); + }); if let Err(err) = app.credentials.store() { error!(?err, "failed to save credentials to disk");