From 59a8672b1f6523e7bd4d25f287fec7d32d28273d Mon Sep 17 00:00:00 2001 From: garikbesson Date: Thu, 26 Sep 2024 19:30:26 +0200 Subject: [PATCH 1/4] migrated tracking --- Cargo.lock | 1 + cargo-near/Cargo.toml | 1 + cargo-near/src/commands/new/mod.rs | 4 +-- cargo-near/src/lib.rs | 2 +- ...xpanel_tracking.rs => posthog_tracking.rs} | 28 ++++++++++--------- 5 files changed, 20 insertions(+), 16 deletions(-) rename cargo-near/src/{mixpanel_tracking.rs => posthog_tracking.rs} (64%) diff --git a/Cargo.lock b/Cargo.lock index d736e6db..4b700957 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -466,6 +466,7 @@ dependencies = [ "names", "near-cli-rs", "reqwest", + "rustc_version", "serde", "serde_json", "shell-words", diff --git a/cargo-near/Cargo.toml b/cargo-near/Cargo.toml index 83ee0a3c..f70d1ca3 100644 --- a/cargo-near/Cargo.toml +++ b/cargo-near/Cargo.toml @@ -53,6 +53,7 @@ tokio = { version = "1.0", default-features = false, features = [ ] } serde_json = "1.0.128" base64 = "0.22.1" +rustc_version = "0.4.1" [dev-dependencies] tracing-test = "0.2.5" diff --git a/cargo-near/src/commands/new/mod.rs b/cargo-near/src/commands/new/mod.rs index 69c9f36b..c0da2f26 100644 --- a/cargo-near/src/commands/new/mod.rs +++ b/cargo-near/src/commands/new/mod.rs @@ -2,7 +2,7 @@ use std::process::Stdio; use color_eyre::eyre::{ContextCompat, WrapErr}; -use crate::mixpanel_tracking; +use crate::posthog_tracking; #[derive(Debug, Clone, interactive_clap::InteractiveClap)] #[interactive_clap(input_context = near_cli_rs::GlobalContext)] @@ -54,7 +54,7 @@ impl NewContext { } let _detached_thread_handle = std::thread::Builder::new() - .spawn(mixpanel_tracking::track_usage) + .spawn(posthog_tracking::track_usage) .unwrap(); let status = std::process::Command::new("git") diff --git a/cargo-near/src/lib.rs b/cargo-near/src/lib.rs index 5e920648..19397bc8 100644 --- a/cargo-near/src/lib.rs +++ b/cargo-near/src/lib.rs @@ -6,7 +6,7 @@ use strum::{EnumDiscriminants, EnumIter, EnumMessage}; pub mod commands; pub mod types; -pub(crate) mod mixpanel_tracking; +pub(crate) mod posthog_tracking; #[derive(Debug, Clone, interactive_clap::InteractiveClap)] #[interactive_clap(context = near_cli_rs::GlobalContext)] diff --git a/cargo-near/src/mixpanel_tracking.rs b/cargo-near/src/posthog_tracking.rs similarity index 64% rename from cargo-near/src/mixpanel_tracking.rs rename to cargo-near/src/posthog_tracking.rs index 93302e64..8789bf94 100644 --- a/cargo-near/src/mixpanel_tracking.rs +++ b/cargo-near/src/posthog_tracking.rs @@ -1,49 +1,51 @@ -use base64::{engine::general_purpose, Engine as _}; use reqwest::{header::HeaderMap, Client}; use serde::Serialize; use std::{env, str}; use tracing::debug; +use rustc_version::version; const SEND_TRACKING_REQUEST_ERROR: &str = "Can't send tracking usage event"; #[derive(Debug, Serialize)] -struct MixpanelProperties { - token: String, - pkg_version: String, +struct PosthogProperties { + language: String, + engine: String, os: String, } #[derive(Debug, Serialize)] struct TrackingData { + api_key: String, event: String, - properties: MixpanelProperties, + distinct_id: String, + properties: PosthogProperties, } pub(crate) fn track_usage() { - let properties = MixpanelProperties { - token: "24177ef1ec09ffea5cb6f68909c66a61".to_string(), - pkg_version: env!("CARGO_PKG_VERSION").to_string(), + let properties = PosthogProperties { + language: "rust".to_string(), + engine: version().unwrap().to_string(), os: env::consts::OS.to_string(), }; let tracking_data = TrackingData { - event: "CNN".to_string(), + api_key: "phc_bMxqEAiInwlq3FMyZvuFPZ8qdYuVwh9L5YfqRpeFk0I".to_string(), + distinct_id: "cargo-near".to_string(), + event: "contract".to_string(), properties, }; let serialized_data = serde_json::to_vec(&tracking_data).unwrap(); - let base64_encoded_data = general_purpose::STANDARD.encode(&serialized_data); let client = Client::new(); let mut headers = HeaderMap::new(); - headers.insert("accept", "text/plain".parse().unwrap()); headers.insert("content-type", "application/json".parse().unwrap()); if tokio::runtime::Runtime::new() .unwrap() .block_on( client - .get("https://api.mixpanel.com/track") - .query(&[("data", base64_encoded_data)]) + .post("https://eu.i.posthog.com/capture") + .body(serialized_data) .headers(headers) .send(), ) From ef9b5c13ab6e64622bb15cc27a472b9fa5226013 Mon Sep 17 00:00:00 2001 From: garikbesson Date: Fri, 27 Sep 2024 18:26:47 +0200 Subject: [PATCH 2/4] rename language value (rust -> rs) --- cargo-near/src/posthog_tracking.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cargo-near/src/posthog_tracking.rs b/cargo-near/src/posthog_tracking.rs index 8789bf94..a578cc6a 100644 --- a/cargo-near/src/posthog_tracking.rs +++ b/cargo-near/src/posthog_tracking.rs @@ -23,7 +23,7 @@ struct TrackingData { pub(crate) fn track_usage() { let properties = PosthogProperties { - language: "rust".to_string(), + language: "rs".to_string(), engine: version().unwrap().to_string(), os: env::consts::OS.to_string(), }; From e763c22ec9e8a60e271045a959a1bea3f09a0038 Mon Sep 17 00:00:00 2001 From: garikbesson Date: Fri, 27 Sep 2024 18:32:28 +0200 Subject: [PATCH 3/4] changed posthog tracking api key --- cargo-near/src/posthog_tracking.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cargo-near/src/posthog_tracking.rs b/cargo-near/src/posthog_tracking.rs index a578cc6a..75a1a476 100644 --- a/cargo-near/src/posthog_tracking.rs +++ b/cargo-near/src/posthog_tracking.rs @@ -28,7 +28,7 @@ pub(crate) fn track_usage() { os: env::consts::OS.to_string(), }; let tracking_data = TrackingData { - api_key: "phc_bMxqEAiInwlq3FMyZvuFPZ8qdYuVwh9L5YfqRpeFk0I".to_string(), + api_key: "phc_95PGQnbyatmj2TBRPWYfhbHfqB6wgZj5QRL8WY9gW20".to_string(), distinct_id: "cargo-near".to_string(), event: "contract".to_string(), properties, From 8bc4461abee73edd9e3bb7be137b404887f4e6b4 Mon Sep 17 00:00:00 2001 From: garikbesson Date: Wed, 9 Oct 2024 12:44:09 +0200 Subject: [PATCH 4/4] revert tracking pkg_version (instead of rustc) --- Cargo.lock | 1 - cargo-near/Cargo.toml | 1 - cargo-near/src/posthog_tracking.rs | 5 ++--- 3 files changed, 2 insertions(+), 5 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 4b700957..d736e6db 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -466,7 +466,6 @@ dependencies = [ "names", "near-cli-rs", "reqwest", - "rustc_version", "serde", "serde_json", "shell-words", diff --git a/cargo-near/Cargo.toml b/cargo-near/Cargo.toml index f70d1ca3..83ee0a3c 100644 --- a/cargo-near/Cargo.toml +++ b/cargo-near/Cargo.toml @@ -53,7 +53,6 @@ tokio = { version = "1.0", default-features = false, features = [ ] } serde_json = "1.0.128" base64 = "0.22.1" -rustc_version = "0.4.1" [dev-dependencies] tracing-test = "0.2.5" diff --git a/cargo-near/src/posthog_tracking.rs b/cargo-near/src/posthog_tracking.rs index 75a1a476..678fb7eb 100644 --- a/cargo-near/src/posthog_tracking.rs +++ b/cargo-near/src/posthog_tracking.rs @@ -2,14 +2,13 @@ use reqwest::{header::HeaderMap, Client}; use serde::Serialize; use std::{env, str}; use tracing::debug; -use rustc_version::version; const SEND_TRACKING_REQUEST_ERROR: &str = "Can't send tracking usage event"; #[derive(Debug, Serialize)] struct PosthogProperties { language: String, - engine: String, + pkg_version: String, os: String, } @@ -24,7 +23,7 @@ struct TrackingData { pub(crate) fn track_usage() { let properties = PosthogProperties { language: "rs".to_string(), - engine: version().unwrap().to_string(), + pkg_version: env!("CARGO_PKG_VERSION").to_string(), os: env::consts::OS.to_string(), }; let tracking_data = TrackingData {