Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: Use Posthog instead of Mixpanel to collect stats on new projects creation #227

Merged
merged 4 commits into from
Oct 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions cargo-near/src/commands/new/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down Expand Up @@ -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")
Expand Down
2 changes: 1 addition & 1 deletion cargo-near/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
use base64::{engine::general_purpose, Engine as _};
use reqwest::{header::HeaderMap, Client};
use serde::Serialize;
use std::{env, str};
Expand All @@ -7,43 +6,45 @@ use tracing::debug;
const SEND_TRACKING_REQUEST_ERROR: &str = "Can't send tracking usage event";

#[derive(Debug, Serialize)]
struct MixpanelProperties {
token: String,
struct PosthogProperties {
language: String,
pkg_version: 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(),
let properties = PosthogProperties {
language: "rs".to_string(),
pkg_version: env!("CARGO_PKG_VERSION").to_string(),
os: env::consts::OS.to_string(),
};
let tracking_data = TrackingData {
event: "CNN".to_string(),
api_key: "phc_95PGQnbyatmj2TBRPWYfhbHfqB6wgZj5QRL8WY9gW20".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(),
)
Expand Down
Loading