Skip to content

Commit

Permalink
fix tracking
Browse files Browse the repository at this point in the history
  • Loading branch information
garikbesson committed Sep 19, 2024
1 parent f05c58f commit 47ff389
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 5 deletions.
2 changes: 2 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions cargo-near/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ tracing-subscriber = { version = "0.3", features = ["env-filter"] }
tokio = { version = "1.0", default-features = false, features = [
"rt-multi-thread",
] }
serde_json = "1.0.128"
base64 = "0.22.1"

[dev-dependencies]
tracing-test = "0.2.5"
Expand Down
19 changes: 14 additions & 5 deletions cargo-near/src/mixpanel_tracking.rs
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
use reqwest::Client;
use base64::{engine::general_purpose, Engine as _};
use reqwest::{header::HeaderMap, Client};
use serde::Serialize;
use std::{env, str};
use tracing::debug;

const SEND_TRACKING_REQUEST_ERROR: &str = "Can't send tracking usage event";

#[derive(Debug, serde::Serialize)]
#[derive(Debug, Serialize)]
struct MixpanelProperties {
token: String,
pkg_version: String,
os: String,
}

#[derive(Debug, serde::Serialize)]
#[derive(Debug, Serialize)]
struct TrackingData {
event: String,
properties: MixpanelProperties,
Expand All @@ -27,15 +29,22 @@ pub(crate) fn track_usage() {
event: "CNN".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
.post("https://api.mixpanel.com/track")
.json(&tracking_data)
.get("https://api.mixpanel.com/track")
.query(&[("data", base64_encoded_data)])
.headers(headers)
.send(),
)
.is_err()
Expand Down

0 comments on commit 47ff389

Please sign in to comment.