Skip to content
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
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.

5 changes: 3 additions & 2 deletions apps/api/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ async fn app() -> Router {
hypr_llm_proxy::LlmProxyConfig::new(&env.llm).with_analytics(analytics.clone());
let stt_config = hypr_transcribe_proxy::SttProxyConfig::new(&env.stt, &env.supabase)
.with_hyprnote_routing(hypr_transcribe_proxy::HyprnoteRoutingConfig::default())
.with_analytics(analytics);
.with_analytics(analytics.clone());

let stt_rate_limit = rate_limit::RateLimitState::builder()
.pro(
Expand Down Expand Up @@ -79,7 +79,8 @@ async fn app() -> Router {
);
let nango_connection_state = hypr_api_nango::NangoConnectionState::from_config(&nango_config);
let subscription_config =
hypr_api_subscription::SubscriptionConfig::new(&env.supabase, &env.stripe);
hypr_api_subscription::SubscriptionConfig::new(&env.supabase, &env.stripe)
.with_analytics(analytics.clone());
let support_config = hypr_api_support::SupportConfig::new(
&env.github_app,
&env.llm,
Expand Down
1 change: 1 addition & 0 deletions apps/desktop/src-tauri/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ tracing = { workspace = true }
hypr-host = { workspace = true }
hypr-supervisor = { workspace = true }

pico-args = { workspace = true }
ractor = { workspace = true }
tokio = { workspace = true, features = ["rt-multi-thread", "macros"] }

Expand Down
8 changes: 0 additions & 8 deletions apps/desktop/src/components/onboarding/login.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import { useEffect, useRef, useState } from "react";

import { startTrial } from "@hypr/api-client";
import { createClient } from "@hypr/api-client/client";
import { commands as analyticsCommands } from "@hypr/plugin-analytics";

import { useAuth } from "../../auth";
import { useBillingAccess } from "../../billing";
Expand Down Expand Up @@ -120,13 +119,6 @@ export function LoginSection({ onContinue }: { onContinue: () => void }) {

if (store) configureProSettings(store);

void analyticsCommands.event({ event: "trial_started", plan: "pro" });
const trialEndDate = new Date();
trialEndDate.setDate(trialEndDate.getDate() + 14);
void analyticsCommands.setProperties({
set: { plan: "pro", trial_end_date: trialEndDate.toISOString() },
});

setTrialPhase({ step: "done", result: "started" });
await auth.refreshSession();
await new Promise((r) => setTimeout(r, 3000));
Expand Down
14 changes: 0 additions & 14 deletions apps/desktop/src/components/settings/general/account.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -340,20 +340,6 @@ function BillingButton() {
await new Promise((resolve) => setTimeout(resolve, 3000));
},
onSuccess: async () => {
void analyticsCommands.event({
event: "trial_started",
plan: "pro",
});
const trialEndDate = new Date();
trialEndDate.setDate(trialEndDate.getDate() + 14);
void analyticsCommands.setProperties({
email: auth?.session?.user.email,
user_id: auth?.session?.user.id,
set: {
plan: "pro",
trial_end_date: trialEndDate.toISOString(),
},
});
if (store) {
configureProSettings(store);
}
Expand Down
41 changes: 41 additions & 0 deletions crates/analytics/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,14 @@ impl AnalyticsClient {
}
}

pub trait ToAnalyticsPayload {
fn to_analytics_payload(&self) -> AnalyticsPayload;

fn to_analytics_properties(&self) -> Option<PropertiesPayload> {
None
}
}

#[derive(Debug, serde::Serialize, serde::Deserialize, specta::Type)]
pub struct AnalyticsPayload {
pub event: String,
Expand All @@ -150,6 +158,39 @@ pub struct PropertiesPayload {
pub user_id: Option<String>,
}

#[derive(Default)]
pub struct PropertiesPayloadBuilder {
set: HashMap<String, serde_json::Value>,
set_once: HashMap<String, serde_json::Value>,
}

impl PropertiesPayload {
pub fn builder() -> PropertiesPayloadBuilder {
PropertiesPayloadBuilder::default()
}
}

impl PropertiesPayloadBuilder {
pub fn set(mut self, key: impl Into<String>, value: impl Into<serde_json::Value>) -> Self {
self.set.insert(key.into(), value.into());
self
}

pub fn set_once(mut self, key: impl Into<String>, value: impl Into<serde_json::Value>) -> Self {
self.set_once.insert(key.into(), value.into());
self
}

pub fn build(self) -> PropertiesPayload {
PropertiesPayload {
set: self.set,
set_once: self.set_once,
email: None,
user_id: None,
}
}
}

#[derive(Clone)]
pub struct AnalyticsPayloadBuilder {
event: Option<String>,
Expand Down
1 change: 1 addition & 0 deletions crates/api-subscription/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ version = "0.1.0"
edition = "2024"

[dependencies]
hypr-analytics = { workspace = true }
hypr-api-auth = { workspace = true }
hypr-api-env = { workspace = true }

Expand Down
11 changes: 11 additions & 0 deletions crates/api-subscription/src/config.rs
Original file line number Diff line number Diff line change
@@ -1,17 +1,28 @@
use std::sync::Arc;

use hypr_analytics::AnalyticsClient;

use crate::StripeEnv;
use hypr_api_env::SupabaseEnv;

#[derive(Clone)]
pub struct SubscriptionConfig {
pub supabase: SupabaseEnv,
pub stripe: StripeEnv,
pub analytics: Option<Arc<AnalyticsClient>>,
}

impl SubscriptionConfig {
pub fn new(supabase: &SupabaseEnv, stripe: &StripeEnv) -> Self {
Self {
supabase: supabase.clone(),
stripe: stripe.clone(),
analytics: None,
}
}

pub fn with_analytics(mut self, analytics: Arc<AnalyticsClient>) -> Self {
self.analytics = Some(analytics);
self
}
}
2 changes: 2 additions & 0 deletions crates/api-subscription/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ mod error;
mod openapi;
mod routes;
mod state;
mod stripe;
mod supabase;
mod trial;

pub use config::SubscriptionConfig;
pub use env::StripeEnv;
Expand Down
Loading
Loading