Skip to content
Draft
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
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,15 @@ const ALL_SOURCE_PRODUCTS: (keyof SignalSourceValues)[] = [
"conversations",
];

// Sources powered by PostHog itself (no external integration required). These
// are auto-enabled the first time a project reaches the onboarding signals step
// so the inbox is opt-out, not opt-in.
const POSTHOG_INTERNAL_SOURCES: (keyof SignalSourceValues)[] = [
"error_tracking",
"conversations",
"session_replay",
];

function computeValues(
configs: SignalSourceConfig[] | undefined,
): SignalSourceValues {
Expand Down Expand Up @@ -378,6 +387,22 @@ export function useSignalSourceManager() {
],
);

// Create configs (enabled) for any PostHog-internal source that has none.
// Sources with an existing config (enabled or disabled) are left alone so we
// never override an explicit user choice.
const autoEnableInternalSources = useCallback(async () => {
if (!client || !projectId || !configs) return;

const missing = POSTHOG_INTERNAL_SOURCES.filter(
(product) => !configs.some((c) => c.source_product === product),
);
if (missing.length === 0) return;

for (const product of missing) {
void handleToggle(product, true);
}
}, [client, projectId, configs, handleToggle]);

const handleSetupComplete = useCallback(async () => {
const completedSource = setupSource;
setSetupSource(null);
Expand Down Expand Up @@ -476,6 +501,7 @@ export function useSignalSourceManager() {
handleSetup,
handleSetupComplete,
handleSetupCancel,
autoEnableInternalSources,
evaluations: displayEvaluations,
evaluationsUrl,
handleToggleEvaluation,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { Button, Flex, Text } from "@radix-ui/themes";
import detectiveHog from "@renderer/assets/images/hedgehogs/detective-hog.png";
import { useQueryClient } from "@tanstack/react-query";
import { motion } from "framer-motion";
import { useEffect, useRef } from "react";
import { OnboardingHogTip } from "./OnboardingHogTip";
import { StepActions } from "./StepActions";

Expand All @@ -27,10 +28,21 @@ export function SignalsStep({ onNext, onBack }: SignalsStepProps) {
handleSetupComplete,
handleSetupCancel,
evaluationsUrl,
autoEnableInternalSources,
} = useSignalSourceManager();
const { data: me } = useMeQuery();
const isStaff = me?.is_staff ?? false;

// Auto-enable PostHog-internal sources on first load so the inbox is opt-out
// during onboarding. The manager skips any source that already has a config.
const autoEnabledRef = useRef(false);
useEffect(() => {
if (autoEnabledRef.current) return;
if (isLoading) return;
autoEnabledRef.current = true;
void autoEnableInternalSources();
}, [isLoading, autoEnableInternalSources]);

const anyEnabled =
displayValues.session_replay ||
displayValues.error_tracking ||
Expand Down
Loading