Macro is a unified workspace for teams: email, chat, docs, tasks, agents, calls, and CRM — @-linked together with shared AI memory.
TypeScript agentaiai-agentsall-in-onecrmcrm-systememaillinearmcpmessagingnotesnotionofficerustslackslack-alternativestartupstartup-toolstypescriptworkspace
feat(analytics): fire valued Lead on every conversion path (#2813)
Evan Hutnik3f7ec2b94ad5
diff --git a/.env-local.enc b/.env-local.encindex 8e72b10b70..4bcf48447e 100644--- a/.env-local.enc+++ b/.env-local.enc@@ -10,7 +10,7 @@ BACKFILL_QUEUE_MAX_MESSAGES=ENC[AES256_GCM,data:AUZs,iv:ST7hFsgaTX7UywBwkXSXy9lGBACKFILL_QUEUE_WORKERS=ENC[AES256_GCM,data:YhcxQg==,iv:Er4O0ADEgBRh3VO7piwpgfHEYxE3EDElhZumgXbmpeM=,tag:GMU00vKvkv3BxzDM6Kx21A==,type:str]BASE_URL=ENC[AES256_GCM,data:xDjxmXaorCF6bJrhDXR9iOa3o0EmeLo=,iv:Lykqt28CCm4R8904NuYVsjF85LimXDstKWBHDpkRlho=,tag:yVwo912yzgOtP6HOBR6V2A==,type:str]BULK_UPLOAD_REQUESTS_TABLE=ENC[AES256_GCM,data:cXp1qV7PPvB56zxE5w==,iv:xwGz3jX0XW10LMeHoyuASDjlKl+3cz+eh9URhjVF6aM=,tag:gaZJkg5hi3Syvj22YhHRlQ==,type:str]-CAL_EVENT_TYPE_CONTENT_NAMES_KEY=ENC[AES256_GCM,data:/fmIDA==,iv:rhQAneFAPQDg1/Wme1TOGh76WFNStTxCDNz12O9s/9I=,tag:uh0UUm20wHRRPe0WFsSFBw==,type:str]+CAL_EVENT_TYPE_CONTENT_NAMES_KEY=ENC[AES256_GCM,data:3X2J418naBZvxuS0MaK7TPDP6OTb/0HBS9a62qvtTXE4agBHJZza7xX+lDl05+nNZ3ADKDGW+sb+k+GUbcw5LYeTWGoxT0ujP+HYC92fxWE/h6zlnn6BUBb4wOvret6eZx24dnv/iuoICCmA9cvJIvdYpXQefs7LilE=,iv:gCpjl+/NVQKcve0ADthYBaaU/RckpSQ9X5lzz1jUJKY=,tag:JtFmhMLcpL3p23HGHHlOCQ==,type:str]CAL_WEBHOOK_SECRET_KEY=ENC[AES256_GCM,data:t2Hn2JoB,iv:ohQBFZv8wLSAq3rD+a2FiYiIIyVjl/41BI1FAHOvTKs=,tag:w7VwyNGh+elSnoYl3bdGnw==,type:str]CHAT_DELETE_QUEUE=ENC[AES256_GCM,data:Xm6XSh6Ge6NZxjcGPQVxEN7n1zOXWHh20Ox6Awq9NZN9B2Tt73eWqnHigAYPH9+j+m7k7IwTiRR3hOKy6zMA,iv:mWH/r2WYI1DOiE1BlpiuIJIv7q5behiMhvfiGDDEDgQ=,tag:tofQrMiWYeF2oPdvLydFZg==,type:str]CONNECTION_GATEWAY_TABLE=ENC[AES256_GCM,data:KqDjSn/o+AlZVOoz4eT9LjEyB0/SoNHS+S0=,iv:HixjrQocTF2TEhDv0amx2zvIJEHaEwLbHDNAqW2tm4U=,tag:jzFPSEvF5jF7Hy5XPGgXDA==,type:str]@@ -144,7 +144,7 @@ sops_kms__list_1__map_arn=arn:aws:kms:us-west-1:569036502058:key/mrk-cab29bf9480sops_kms__list_1__map_aws_profile=sops_kms__list_1__map_created_at=2026-03-03T19:32:07Zsops_kms__list_1__map_enc=AQICAHjuYcSMsjB0lKJtZ3DIAvxF8N3RNRn5KZaAN74Et6122wFUqf7u/HEfCUGv7j69Mb6YAAAAfjB8BgkqhkiG9w0BBwagbzBtAgEAMGgGCSqGSIb3DQEHATAeBglghkgBZQMEAS4wEQQMpcJQR1XeIAFFE7ebAgEQgDvYRYIWelwN8TuwA+6fZVaB34yKo9EQ5xPLr/3BU+ro1Mn2eBPCg3q8ie2LuE/3voim1X35P/cdtDqTZg==-sops_lastmodified=2026-04-23T16:07:14Z-sops_mac=ENC[AES256_GCM,data:GaGPjmolc5jpnTlWamosio+/LEbMBdT8uhMAJec/o4paqAunc1qN0HZpY+uNtcjLX1MvA9lVI93IVRxXHYd075NA7JJ6GJGT/kyJNaoR3P58T0POd5dYx2pBEsRWcdhg/oNVk/Kv75ekW+SDNqoAe0FMKNIyqtC7S+pBLdWEzvs=,iv:nSuMbbBUnzCdrqDOr+g0LfHhKynnKATD+yoJcMlDog8=,tag:+cKydl0OIxT2uORMZzQObw==,type:str]+sops_lastmodified=2026-04-23T20:35:38Z+sops_mac=ENC[AES256_GCM,data:yNXEM6s4tDn1T1aC8TILZeFY2CRMrg9a4Ih9Zt9V40E4mupjrGdlHS6BhYfQbBtgMzNbZYxfX24x64TrZBPY8nx4UQmekwGvBmv1EeUQdDmgaX9NJHCvOi+83VjAF+4VI4M/ir7hpRfD2C2WrkY8P23nFI8jRTwbURbx9AWh2TU=,iv:t1FJiXWUFuHdkE+fz/lz6+4gqDvMQV3b9yamh6UxUSg=,tag:h+3pVxcGII21dtXEiQepDw==,type:str]sops_unencrypted_suffix=_unencryptedsops_version=3.12.2diff --git a/.env-localdev.enc b/.env-localdev.encindex f0ebc9a9b3..5d6db6c660 100644--- a/.env-localdev.enc+++ b/.env-localdev.enc@@ -13,7 +13,7 @@ BACKFILL_QUEUE_MAX_MESSAGES=ENC[AES256_GCM,data:4ZYv,iv:d/BZ/me/FyfqzR4v1rmc49ClBACKFILL_QUEUE_WORKERS=ENC[AES256_GCM,data:lnNWVw==,iv:rYtkwNKXsUZ73JP+qqgjqkH6g4nWgswFPV3d4KydboA=,tag:5Tm6FxT+7deyI8WSudkR9A==,type:str]BASE_URL=ENC[AES256_GCM,data:LUu9CaC23oMzyP3UtbCl04Ik2cEtda4=,iv:M80Oc/NekFuyk40wd8QNr6ArJFrTYejEQtR1b3Gnngg=,tag:rndkoVL+O0jN5modansumQ==,type:str]BULK_UPLOAD_REQUESTS_TABLE=ENC[AES256_GCM,data:3mOP5vhUnGKANPie9wBPwq0=,iv:nTvJJ/p3cajOPR3Bf/r8dNg94284uR4GPZ8nf8W2G9U=,tag:LQd9kYAdk/e2GMA03WA4ag==,type:str]-CAL_EVENT_TYPE_CONTENT_NAMES_KEY=ENC[AES256_GCM,data:rrEGULoFkh0L1YPQbv9sTbX8ciSdH2Lvx/vpjlbw2/qCCx9m97Fkrk0TLPiDP8ojeyM3H9Pkc+ZvusuRK6r+Xw==,iv:0wnJVJz1IplqPVX09dUCw4nwcFi2mpqlH7upTQM23ug=,tag:Q55S5KphmWLcwMMim8utww==,type:str]+CAL_EVENT_TYPE_CONTENT_NAMES_KEY=ENC[AES256_GCM,data:nVdeT1juhQnDvDndFesSruDdlXRg/2pv2OnOyd+RpVAEqtYQl4hK0XYhLlEzezgRf87YXvgnSoQK6lG+DmlX5NvxnuCse2bqzD/5vCEg5HybOJW15wUx9TvmNOjgDUZ7Rws3YBMe8HbJB2V0SwCs/XZ3m3z6GlqQfpY=,iv:F3muN/NpQ05yHodIDTwrpBs2s1o7oxmMXJPiVU/QRes=,tag:BI5cqJtlYVD/PQNaswAhnA==,type:str]CAL_WEBHOOK_SECRET_KEY=ENC[AES256_GCM,data:KiYzyIfjxZpwBRB9uVe6khWJszW0eiW+RWmVbA==,iv:6nK8cmeiMvxoTeJrFBlj73PAhqCeuA94Zoiqdr4AGzc=,tag:Vsng1+XXC/bqoKVYhLARlg==,type:str]CHAT_DELETE_QUEUE=ENC[AES256_GCM,data:uMGn+VHelaylz73/j3TP3P9qCMKnS2QOKd/Qt8arDA==,iv:R8jOUuPJXhDB+zTfRRQAWXN3KYNfE/tTbO/HPjTY7Nk=,tag:K3/KGKkw4RV5boYoRSiVsg==,type:str]CONNECTION_GATEWAY_TABLE=ENC[AES256_GCM,data:UpVqapsnq/6JWBr8daSJ27UFb4ly/2XtwCQZ2KOZ7MgUlixRp78=,iv:U+qyhdIdhHdhpPVxj4kVmY3318QxyfvKCeLD0O3G2u0=,tag:CiB9VgW3/QZeiRsarCWxwQ==,type:str]@@ -149,7 +149,7 @@ sops_kms__list_1__map_arn=arn:aws:kms:us-west-1:569036502058:key/mrk-cab29bf9480sops_kms__list_1__map_aws_profile=sops_kms__list_1__map_created_at=2026-03-03T19:32:17Zsops_kms__list_1__map_enc=AQICAHjuYcSMsjB0lKJtZ3DIAvxF8N3RNRn5KZaAN74Et6122wHtcTS4UVhM79Eansn1/OmrAAAAfjB8BgkqhkiG9w0BBwagbzBtAgEAMGgGCSqGSIb3DQEHATAeBglghkgBZQMEAS4wEQQMRrFwSp99ZM2mPtJzAgEQgDvsIaiNifNz0/18C9OH77AG/LQLpmDiXiJYV46yLDv9vdyPL3PaLMvkAqgL3Xb2F4RcZOIUxkTS3u92xQ==-sops_lastmodified=2026-04-22T17:23:57Z-sops_mac=ENC[AES256_GCM,data:qQyalh9Zv1Ka2fUd9qcDAolppY7SVkyzmeEctoks7MOIPPP7OC7nJIlWG6Sp37iwHCXWLurT2cCptGQ0IjxraCpPQ+sPxlnrnW14wCQgNuB7iXZDVRtnb7Fi+Ul8CxUqTIUjGcnDPfyo2RFgnrpsshNuzudTTQKZNuUNx8/nYU4=,iv:xFx0W6lfwlztrq+I/BqVAzm2NnMY62utjizbhtX5sy0=,tag:sVdNixKv8TK7PLlaClS8Tw==,type:str]+sops_lastmodified=2026-04-23T19:41:19Z+sops_mac=ENC[AES256_GCM,data:AGdojRTopzs/jr2fQByy2h5f3tdRg6X/qkGX3PCdJ2l7KRQlGh7DQuCI5+GzkmsQ/3Jk/FjDWreSQVSEORjpdz0uQej/h6SDkQ6ZlAyCRsYVAK+iMkFyq4Xj1ZsNodKL9gh314hCZRM5ndQRLbafHOAQpVbGa8etrVSyc34QQBU=,iv:8xuEi6xGtVaYt6eHY8oc+Z4jGaiBqnkKiRILHRZLpSE=,tag:wdmbCq+qXnW+7uKy8cevDg==,type:str]sops_unencrypted_suffix=_unencryptedsops_version=3.12.2diff --git a/infra/stacks/cloud-storage-service/Pulumi.dev.yaml b/infra/stacks/cloud-storage-service/Pulumi.dev.yamlindex b70eaecdca..4d10700e0d 100644--- a/infra/stacks/cloud-storage-service/Pulumi.dev.yaml+++ b/infra/stacks/cloud-storage-service/Pulumi.dev.yaml@@ -24,6 +24,6 @@ config:cloud-storage-service:livekit_transcription_agent_name: macro-transcribercloud-storage-service:call_internal_secret: call-internal-secret-devcloud-storage-service:cal_webhook_secret_key: cal-webhook-secret-dev- cloud-storage-service:cal_event_type_content_names_key: cal-event-type-content-names-dev+ cloud-storage-service:cal_event_type_content_names_key: cal-event-metadata-devcloud-storage-service:meta_pixel_id: "639142540393286"cloud-storage-service:meta_access_token: meta-access-tokendiff --git a/infra/stacks/cloud-storage-service/Pulumi.prod.yaml b/infra/stacks/cloud-storage-service/Pulumi.prod.yamlindex a09b6e1dd6..e8437b3329 100644--- a/infra/stacks/cloud-storage-service/Pulumi.prod.yaml+++ b/infra/stacks/cloud-storage-service/Pulumi.prod.yaml@@ -24,6 +24,6 @@ config:cloud-storage-service:livekit_transcription_agent_name: macro-transcribercloud-storage-service:call_internal_secret: call-internal-secret-prodcloud-storage-service:cal_webhook_secret_key: cal-webhook-secret-prod- cloud-storage-service:cal_event_type_content_names_key: cal-event-type-content-names-prod+ cloud-storage-service:cal_event_type_content_names_key: cal-event-metadata-prodcloud-storage-service:meta_pixel_id: "639142540393286"cloud-storage-service:meta_access_token: meta-access-tokendiff --git a/js/app/packages/app/component/interactive-onboarding/MobileWebSignupSent.tsx b/js/app/packages/app/component/interactive-onboarding/MobileWebSignupSent.tsxindex df3e466b9f..ed638abe60 100644--- a/js/app/packages/app/component/interactive-onboarding/MobileWebSignupSent.tsx+++ b/js/app/packages/app/component/interactive-onboarding/MobileWebSignupSent.tsx@@ -3,13 +3,18 @@ import LogoIcon from '@macro-icons/macro-logo.svg';import { PcNoiseGrid } from '@core/component/PcNoiseGrid';import { useAnalytics } from '@app/component/analytics-context';import { getWebOrigin } from '@core/util/webOrigin';+import { MOBILE_WEB_SIGNUP_LEAD_VALUE } from '@app/lib/analytics/leadValues';export default function MobileWebSignupSent() {const analytics = useAnalytics();onMount(() => {analytics.track('mobile_web_signup_sent_viewed');- analytics.trackMeta('Lead', { content_name: 'mobile_web_signup' });+ analytics.trackMeta('Lead', {+ content_name: 'mobile_web_signup',+ value: MOBILE_WEB_SIGNUP_LEAD_VALUE,+ currency: 'USD',+ });});return (diff --git a/js/app/packages/app/component/interactive-onboarding/lessons/launch.tsx b/js/app/packages/app/component/interactive-onboarding/lessons/launch.tsxindex fbad2ef921..724bdbbd82 100644--- a/js/app/packages/app/component/interactive-onboarding/lessons/launch.tsx+++ b/js/app/packages/app/component/interactive-onboarding/lessons/launch.tsx@@ -4,6 +4,10 @@ import AppStoreQr from '@macro-icons/app-store.svg';import type { LessonContentProps, LessonDefinition } from '../types';import { useAnalytics } from '@app/component/analytics-context';import { ENABLE_APP_STORE_QR_CODE } from '@core/constant/featureFlags';+import {+ SIGNUP_LEAD_VALUE_BY_TIER,+ SIGNUP_LEAD_VALUE_DEFAULT,+} from '@app/lib/analytics/leadValues';function LaunchContent(props: LessonContentProps) {const analytics = useAnalytics();@@ -12,11 +16,18 @@ function LaunchContent(props: LessonContentProps) {onMount(() => {// `type` is set on the Stripe success redirect (see choose-plan.tsx). Free// users skip Stripe entirely so the param is absent — default to 'free'.- const tier = searchParams.type ?? 'free';+ const rawTier = searchParams.type;+ const tier = (Array.isArray(rawTier) ? rawTier[0] : rawTier) ?? 'free';analytics.trackMeta('CompleteRegistration', {content_name: 'onboarding_launch',content_category: tier,});+ analytics.trackMeta('Lead', {+ content_name: 'signup',+ content_category: tier,+ value: SIGNUP_LEAD_VALUE_BY_TIER[tier] ?? SIGNUP_LEAD_VALUE_DEFAULT,+ currency: 'USD',+ });setTimeout(() => props.onComplete('Launch'));});diff --git a/js/app/packages/app/lib/analytics/leadValues.ts b/js/app/packages/app/lib/analytics/leadValues.tsnew file mode 100644index 0000000000..cc716a5b99--- /dev/null+++ b/js/app/packages/app/lib/analytics/leadValues.ts@@ -0,0 +1,23 @@+/**+ * USD values attached to Meta `Lead` fires. Meta's Value Optimization weighs+ * each Lead by the `value` we declare, so these numbers directly shape which+ * audiences Meta favors. Tune here; both call sites read from this file.+ *+ * Corresponding server-side values (cal.com bookings) live in the+ * `CAL_EVENT_TYPE_CONTENT_NAMES_KEY` secret — keep the two in sync when+ * rebalancing.+ */++/** Mobile web email capture (user can't sign up on mobile; we email them). */+export const MOBILE_WEB_SIGNUP_LEAD_VALUE = 5;++/** Signup Lead value per subscription tier. */+export const SIGNUP_LEAD_VALUE_BY_TIER: Record<string, number> = {+ free: 20,+ haiku: 175,+ sonnet: 300,+ opus: 450,+};++/** Fallback used when the tier query param is unrecognized. */+export const SIGNUP_LEAD_VALUE_DEFAULT = SIGNUP_LEAD_VALUE_BY_TIER.free;diff --git a/rust/cloud-storage/cal/src/domain/ports.rs b/rust/cloud-storage/cal/src/domain/ports.rsindex d75e40a19e..c42f0555d8 100644--- a/rust/cloud-storage/cal/src/domain/ports.rs+++ b/rust/cloud-storage/cal/src/domain/ports.rs@@ -34,12 +34,15 @@ pub trait CalWebhookService: Send + Sync + 'static {pub trait AnalyticsSink: Send + Sync + 'static {/// Track a `BOOKING_CREATED` event.///- /// `content_name` is the Meta `content_name` attribute resolved from the- /// booking's `eventTypeId` by the service layer — see- /// [`crate::domain::service::CalConfig::event_type_content_names`].+ /// `content_name` and `value` are resolved from the booking's `eventTypeId`+ /// by the service layer — see+ /// [`crate::domain::service::CalConfig::event_type_meta`]. `value` is in+ /// USD and is emitted on the Meta Lead so Value Optimization can weigh+ /// different booking types differently.fn on_booking_created(&self,booking: &BookingCreated,content_name: &str,+ value: f64,) -> impl Future<Output = Result<(), Report>> + Send;}diff --git a/rust/cloud-storage/cal/src/domain/service.rs b/rust/cloud-storage/cal/src/domain/service.rsindex d7a9dc8b6e..c3e3b946ce 100644--- a/rust/cloud-storage/cal/src/domain/service.rs+++ b/rust/cloud-storage/cal/src/domain/service.rs@@ -3,6 +3,7 @@use std::collections::HashMap;use hmac::{Hmac, Mac};+use serde::Deserialize;use sha2::Sha256;use crate::domain::models::{@@ -12,18 +13,32 @@ use crate::domain::ports::{AnalyticsSink, CalWebhookService};type HmacSha256 = Hmac<Sha256>;+/// Per-event-type metadata looked up from [`CalConfig::event_type_meta`].+///+/// Meta Lead optimization weighs events by their declared `value`, so each+/// cal.com event type carries its own business value (e.g. a demo booking is+/// worth more than a generic intro call). Currency is fixed to USD at the+/// sink, matching the web pixel's convention.+#[derive(Debug, Clone, Deserialize)]+pub struct CalEventMeta {+ /// Meta `content_name` tag for this event type.+ pub content_name: String,+ /// Business value attributed to one booking of this event type, in USD.+ pub value: f64,+}+/// Configuration for the cal.com webhook service.#[derive(Debug, Clone)]pub struct CalConfig {/// Shared secret configured on the cal.com webhook. Used to verify the/// HMAC-SHA256 signature in `X-Cal-Signature-256`.pub webhook_secret: String,- /// Maps cal.com `eventTypeId` to the Meta `content_name` we fire for it.+ /// Maps cal.com `eventTypeId` to the Meta tags + value we fire for it.////// Bookings whose event type id is absent from this map are logged and/// skipped: we'd rather miss a Lead than fire an unlabeled one when/// someone adds a new event type in cal.com.- pub event_type_content_names: HashMap<u64, String>,+ pub event_type_meta: HashMap<u64, CalEventMeta>,}/// Concrete cal.com webhook service.@@ -87,8 +102,7 @@ impl<A: AnalyticsSink> CalWebhookService for CalWebhookServiceImpl<A> {return Ok(());};- let Some(content_name) = self.config.event_type_content_names.get(&event_type_id)- else {+ let Some(meta) = self.config.event_type_meta.get(&event_type_id) else {tracing::warn!(uid = %booking.uid,event_type_id,@@ -100,11 +114,12 @@ impl<A: AnalyticsSink> CalWebhookService for CalWebhookServiceImpl<A> {tracing::info!(uid = %booking.uid,event_type_id,- content_name = %content_name,+ content_name = %meta.content_name,+ value = meta.value,"processing cal BOOKING_CREATED",);self.analytics- .on_booking_created(booking, content_name)+ .on_booking_created(booking, &meta.content_name, meta.value).await?;Ok(())}diff --git a/rust/cloud-storage/cal/src/outbound/analytics_client.rs b/rust/cloud-storage/cal/src/outbound/analytics_client.rsindex b79ca3e603..1b6ce99919 100644--- a/rust/cloud-storage/cal/src/outbound/analytics_client.rs+++ b/rust/cloud-storage/cal/src/outbound/analytics_client.rs@@ -30,18 +30,21 @@ impl AnalyticsClientSink {struct LeadCustomData<'a> {content_name: &'a str,content_category: &'static str,+ value: f64,+ currency: &'static str,}impl AnalyticsSink for AnalyticsClientSink {#[tracing::instrument(err,skip(self, booking),- fields(uid = %booking.uid, content_name),+ fields(uid = %booking.uid, content_name, value),)]async fn on_booking_created(&self,booking: &BookingCreated,content_name: &str,+ value: f64,) -> Result<(), Report> {let attendee_email = booking.attendees.first().map(|a| a.email.as_str());@@ -72,6 +75,8 @@ impl AnalyticsSink for AnalyticsClientSink {let custom_data = LeadCustomData {content_name,content_category: "cal_booking",+ value,+ currency: "USD",};// Debug log so we can see whether cal.com's metadata passthrough isdiff --git a/rust/cloud-storage/document_storage_service/src/main.rs b/rust/cloud-storage/document_storage_service/src/main.rsindex 9aa913e5aa..f42a4180c0 100644--- a/rust/cloud-storage/document_storage_service/src/main.rs+++ b/rust/cloud-storage/document_storage_service/src/main.rs@@ -11,7 +11,7 @@ use crate::{use analytics_client::{AnalyticsClient, AnalyticsClientConfig, MetaConfig};use anyhow::Context;use cal::{- domain::service::{CalConfig, CalWebhookServiceImpl},+ domain::service::{CalConfig, CalEventMeta, CalWebhookServiceImpl},inbound::cal_webhook_router::CalWebhookRouterState,outbound::analytics_client::AnalyticsClientSink,};@@ -382,13 +382,13 @@ async fn main() -> anyhow::Result<()> {posthog: None,}));- let cal_event_type_content_names: std::collections::HashMap<u64, String> =+ let cal_event_type_meta: std::collections::HashMap<u64, CalEventMeta> =serde_json::from_str(cal_event_type_content_names_secret.as_ref())- .context("CalEventTypeContentNames secret must be a JSON object mapping eventTypeId (u64) to content_name")?;+ .context("CalEventTypeContentNames secret must be a JSON object mapping eventTypeId (u64) to { content_name: string, value: number (USD) }")?;let cal_webhook_service = CalWebhookServiceImpl::new(CalConfig {webhook_secret: cal_webhook_secret.as_ref().to_string(),- event_type_content_names: cal_event_type_content_names,+ event_type_meta: cal_event_type_meta,},AnalyticsClientSink::new(analytics_client.clone()),);