mirror of
https://github.com/multica-ai/multica.git
synced 2026-07-22 17:49:48 +02:00
* chore(analytics): retire redundant PostHog tracking (MUL-4127) PostHog had become a chaotic, largely-unused second copy of data we already query from the DB and Grafana. Remove the redundant instrumentation. Server: every product event (signup, workspace_created, issue_created, issue_executed, chat_message_sent, team_invite_*, onboarding_*, agent_created, cloud_waitlist_joined, feedback_submitted, contact_sales_submitted, squad_created, autopilot_created) is now in metricsOnlyEvents, so metrics.RecordEvent still increments the Prometheus/Grafana counter but no longer ships to PostHog. DB rows remain the source of truth. Runtime/autopilot/ agent_task lifecycle were already Prometheus-only. Frontend: delete the PostHog-only funnel instrumentation — $pageview (+ web and desktop trackers), download_intent_expressed/page_viewed/initiated, the onboarding_started mirror, onboarding_runtime_path_selected/detected, feedback_opened, and source_backfill_*. The source-backfill modal itself stays (it PATCHes the questionnaire to the DB). Kept on PostHog (frontend only): $exception autocapture and the client_crash / client_unresponsive stability telemetry (no DB equivalent), plus $identify/$set. captureSignupSource (attribution cookie) stays — it still feeds the signup_source Prometheus label. Verified: pnpm typecheck, pnpm lint (0 errors), vitest (core/views/web/desktop), go test ./internal/analytics/... ./internal/metrics/... Co-authored-by: multica-agent <github@multica.ai> * docs(analytics): fix stale PostHog references after MUL-4127 (review follow-up) Addresses review of #4996 — three spots still described server events as active PostHog signals after they became metrics-only: - docs/analytics.md: issue_executed is no longer a PostHog success signal; it is Prometheus-only (multica_issue_executed_total) + issue.first_executed_at, in both the event contract and the Reconciliation section. - docs/analytics.md: the signup $set_once person properties (email, signup_source) are no longer emitted — signup is Prometheus-only; only the bucketed signup_source survives as the multica_signup_total label. - server/internal/metrics/business_events.go: RecordEvent doc comment no longer claims it ships product events to PostHog / "PostHog is reserved for user/product-behaviour events" — every server event is now metrics-only. Co-authored-by: multica-agent <github@multica.ai> --------- Co-authored-by: J <j@multica.ai> Co-authored-by: multica-agent <github@multica.ai>
88 lines
3.3 KiB
TypeScript
88 lines
3.3 KiB
TypeScript
"use client";
|
|
|
|
import { useMemo } from "react";
|
|
import { CoreProvider } from "@multica/core/platform";
|
|
import { createBrowserCookieLocaleAdapter } from "@multica/core/i18n/browser";
|
|
import type { LocaleResources, SupportedLocale } from "@multica/core/i18n";
|
|
import { useWelcomeStore } from "@multica/core/onboarding";
|
|
import packageJson from "../package.json";
|
|
import { WebNavigationProvider } from "@/platform/navigation";
|
|
import {
|
|
setLoggedInCookie,
|
|
clearLoggedInCookie,
|
|
} from "@/features/auth/auth-cookie";
|
|
|
|
// Legacy token in localStorage → keep this session in token mode so users who
|
|
// logged in before the cookie-auth migration stay authed. They migrate to
|
|
// cookie mode on their next logout/login cycle (logout clears multica_token).
|
|
// Sunset: once telemetry shows <1% of sessions still carry multica_token,
|
|
// delete this branch and hard-code `cookieAuth` — the localStorage token is
|
|
// XSS-exposed and is the exact thing the cookie migration exists to remove.
|
|
function hasLegacyToken(): boolean {
|
|
if (typeof window === "undefined") return false;
|
|
try {
|
|
return Boolean(window.localStorage.getItem("multica_token"));
|
|
} catch {
|
|
return false;
|
|
}
|
|
}
|
|
|
|
// Derive WebSocket URL from the page origin so self-hosted / LAN deployments
|
|
// work without explicit NEXT_PUBLIC_WS_URL. The Next.js rewrite rule
|
|
// (/ws → backend) handles proxying.
|
|
function deriveWsUrl(): string | undefined {
|
|
if (process.env.NEXT_PUBLIC_WS_URL) return process.env.NEXT_PUBLIC_WS_URL;
|
|
if (typeof window === "undefined") return undefined;
|
|
const proto = window.location.protocol === "https:" ? "wss:" : "ws:";
|
|
return `${proto}//${window.location.host}/ws`;
|
|
}
|
|
|
|
// Build-time version preferred (CI sets NEXT_PUBLIC_APP_VERSION to a git tag
|
|
// or sha so different deploys are distinguishable in server logs); fall back
|
|
// to the package.json version so local dev still reports something useful.
|
|
const WEB_VERSION =
|
|
process.env.NEXT_PUBLIC_APP_VERSION || packageJson.version || "dev";
|
|
|
|
export function WebProviders({
|
|
children,
|
|
locale,
|
|
resources,
|
|
}: {
|
|
children: React.ReactNode;
|
|
locale: SupportedLocale;
|
|
resources: Record<string, LocaleResources>;
|
|
}) {
|
|
const cookieAuth = !hasLegacyToken();
|
|
// Stable identity reference so downstream effects keyed on it don't see a
|
|
// new object on every parent render.
|
|
const identity = useMemo(
|
|
() => ({ platform: "web", version: WEB_VERSION }),
|
|
[],
|
|
);
|
|
const localeAdapter = useMemo(() => createBrowserCookieLocaleAdapter(), []);
|
|
return (
|
|
<CoreProvider
|
|
apiBaseUrl={process.env.NEXT_PUBLIC_API_URL}
|
|
wsUrl={deriveWsUrl()}
|
|
cookieAuth={cookieAuth}
|
|
onLogin={setLoggedInCookie}
|
|
onLogout={() => {
|
|
// welcome-store holds the transient post-onboarding signal. Must
|
|
// clear on logout so user B logging into the same browser doesn't
|
|
// inherit user A's signal and have <WelcomeAfterOnboarding /> fire
|
|
// listAgents / createIssue against a workspace user B doesn't even
|
|
// belong to. The store's own docstring promises this reset; this
|
|
// is where it gets wired.
|
|
useWelcomeStore.getState().reset();
|
|
clearLoggedInCookie();
|
|
}}
|
|
identity={identity}
|
|
locale={locale}
|
|
resources={resources}
|
|
localeAdapter={localeAdapter}
|
|
>
|
|
<WebNavigationProvider>{children}</WebNavigationProvider>
|
|
</CoreProvider>
|
|
);
|
|
}
|