Skip to content

armgit / macro

Public Imported from GitHub
0

Macro is a unified workspace for teams: email, chat, docs, tasks, agents, calls, and CRM — @-linked together with shared AI memory.

feat(analytics): track mobile-web signup as Meta Pixel Lead (#2710)

Evan Hutnik8f7519e8a86c
diff --git a/js/app/packages/app/component/interactive-onboarding/MobileWebSignupSent.tsx b/js/app/packages/app/component/interactive-onboarding/MobileWebSignupSent.tsx
index 6912e754cb..df3e466b9f 100644
--- a/js/app/packages/app/component/interactive-onboarding/MobileWebSignupSent.tsx
+++ b/js/app/packages/app/component/interactive-onboarding/MobileWebSignupSent.tsx
@@ -9,6 +9,7 @@ export default function MobileWebSignupSent() {
onMount(() => {
analytics.track('mobile_web_signup_sent_viewed');
+ analytics.trackMeta('Lead', { content_name: 'mobile_web_signup' });
});
return (
diff --git a/js/app/packages/app/component/interactive-onboarding/lessons/launch.tsx b/js/app/packages/app/component/interactive-onboarding/lessons/launch.tsx
index 71dea70616..49e00b9ac6 100644
--- a/js/app/packages/app/component/interactive-onboarding/lessons/launch.tsx
+++ b/js/app/packages/app/component/interactive-onboarding/lessons/launch.tsx
@@ -1,8 +1,22 @@
import { onMount } from 'solid-js';
+import { useSearchParams } from '@solidjs/router';
import type { LessonContentProps, LessonDefinition } from '../types';
+import { useAnalytics } from '@app/component/analytics-context';
function LaunchContent(props: LessonContentProps) {
- onMount(() => setTimeout(() => props.onComplete('Launch')));
+ const analytics = useAnalytics();
+ const [searchParams] = useSearchParams();
+
+ 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';
+ analytics.trackMeta('CompleteRegistration', {
+ content_name: 'onboarding_launch',
+ content_category: tier,
+ });
+ setTimeout(() => props.onComplete('Launch'));
+ });
return (
<div class="flex flex-col gap-3 onboarding-stagger">
diff --git a/js/app/packages/app/lib/analytics/analytics.ts b/js/app/packages/app/lib/analytics/analytics.ts
index 9a4d6d4382..e792318665 100644
--- a/js/app/packages/app/lib/analytics/analytics.ts
+++ b/js/app/packages/app/lib/analytics/analytics.ts
@@ -67,6 +67,35 @@ interface PageViewOptions {
const GA_ID = 'G-52HPEL3FTV';
+// Meta Pixel distinguishes standard events (fbq('track', ...)) from custom
+// events (fbq('trackCustom', ...)). Calling `track` with a non-standard name
+// works but triggers Pixel Helper warnings and may affect Ads Manager
+// categorization. https://developers.facebook.com/docs/meta-pixel/reference
+const META_STANDARD_EVENT_NAMES = [
+ 'AddPaymentInfo',
+ 'AddToCart',
+ 'AddToWishlist',
+ 'CompleteRegistration',
+ 'Contact',
+ 'CustomizeProduct',
+ 'Donate',
+ 'FindLocation',
+ 'InitiateCheckout',
+ 'Lead',
+ 'PageView',
+ 'Purchase',
+ 'Schedule',
+ 'Search',
+ 'StartTrial',
+ 'SubmitApplication',
+ 'Subscribe',
+ 'ViewContent',
+] as const;
+
+export type MetaStandardEvent = (typeof META_STANDARD_EVENT_NAMES)[number];
+
+const META_STANDARD_EVENTS: Set<string> = new Set(META_STANDARD_EVENT_NAMES);
+
const initializePosthog = (instance: PostHog) => {
const key = import.meta.env.VITE_POSTHOG_API_KEY;
if (!key) return;
@@ -120,7 +149,10 @@ export const createAnalytics = () => {
gtag('event', event, enriched);
})
.with('meta-pixel', () => {
- fbq('track', event, enriched);
+ const fbqMethod = META_STANDARD_EVENTS.has(event)
+ ? 'track'
+ : 'trackCustom';
+ fbq(fbqMethod, event, enriched);
})
.with('posthog', () => {
posthog.capture(event, enriched);
@@ -141,6 +173,31 @@ export const createAnalytics = () => {
}
};
+ /**
+ * Fires a Meta Pixel **standard** event via `fbq('track', ...)`. `event` is
+ * typed to `MetaStandardEvent` (Lead, Purchase, CompleteRegistration, etc.),
+ * so custom names and typos fail at compile time.
+ *
+ * Prefer this over `track(..., ['meta-pixel'])` for anything that maps to a
+ * standard event: Meta's optimization models are pre-trained on the standard
+ * taxonomy (faster learning-phase exit), standard events get priority slots
+ * in iOS 14.5+ Aggregated Event Measurement, and Ads Manager surfaces them
+ * natively in reports and conversion pickers.
+ *
+ * To split one standard event across multiple surfaces (e.g. two `Lead`
+ * funnels), attach a `content_name` in `data` and filter on it via a Custom
+ * Conversion in Ads Manager.
+ *
+ * For the rare event with no standard equivalent, fall back to
+ * `track(event, data, ['meta-pixel'])` — that path uses `trackCustom`.
+ */
+ const trackMeta = (
+ event: MetaStandardEvent,
+ data?: Record<string, unknown>
+ ) => {
+ sendEvent('meta-pixel', event, data);
+ };
+
const identify = (userID: string, info: Partial<UserIdentifyInfo>) => {
if (disabled) return;
@@ -213,6 +270,7 @@ export const createAnalytics = () => {
posthog,
initializeProviders,
track,
+ trackMeta,
identify,
reset,
pageView,
@@ -222,6 +280,7 @@ export const createAnalytics = () => {
export type AnalyticsInterface = {
posthog: PostHog;
track: TrackFn;
+ trackMeta: (event: MetaStandardEvent, data?: Record<string, unknown>) => void;
identify: (userID: string, info: Partial<UserIdentifyInfo>) => void;
reset: () => void;
pageView: (pageTitle: string, opts?: PageViewOptions) => void;