AutoGPT is the vision of accessible AI for everyone, to use and to build on. Our mission is to provide the tools, so that you can focus on what matters.
fix(frontend): DataFast waits for consent on /tour and stops sending workflow names (#15752)
Krzysztof Czerwinski10ad8bd3b7fb
diff --git a/autogpt_platform/frontend/src/app/(platform)/build/components/BuilderActions/components/CronSchedulerDialog/useCronSchedulerDialog.ts b/autogpt_platform/frontend/src/app/(platform)/build/components/BuilderActions/components/CronSchedulerDialog/useCronSchedulerDialog.tsindex 9c313153d8..1c7fbfb2f9 100644--- a/autogpt_platform/frontend/src/app/(platform)/build/components/BuilderActions/components/CronSchedulerDialog/useCronSchedulerDialog.ts+++ b/autogpt_platform/frontend/src/app/(platform)/build/components/BuilderActions/components/CronSchedulerDialog/useCronSchedulerDialog.ts@@ -47,7 +47,7 @@ export function useCronSchedulerDialog({title: "Schedule created",description: "Schedule created successfully",});- if (flowID) trackScheduleCreatedGoal({ id: flowID }, "builder");+ if (flowID) trackScheduleCreatedGoal(flowID, "builder");invalidateAllScheduleQueries(queryClient, flowID ?? undefined);}},diff --git a/autogpt_platform/frontend/src/app/(platform)/build/components/BuilderActions/components/RunGraph/useRunGraph.test.tsx b/autogpt_platform/frontend/src/app/(platform)/build/components/BuilderActions/components/RunGraph/useRunGraph.test.tsxindex 00c609c296..696b6d32a7 100644--- a/autogpt_platform/frontend/src/app/(platform)/build/components/BuilderActions/components/RunGraph/useRunGraph.test.tsx+++ b/autogpt_platform/frontend/src/app/(platform)/build/components/BuilderActions/components/RunGraph/useRunGraph.test.tsx@@ -167,7 +167,6 @@ describe("useRunGraph", () => {expect(mockSendDatafastEvent).toHaveBeenCalledExactlyOnceWith("run_agent", {id: "graph-1",- name: "",surface: "builder",});});diff --git a/autogpt_platform/frontend/src/app/(platform)/build/components/BuilderActions/components/RunGraph/useRunGraph.ts b/autogpt_platform/frontend/src/app/(platform)/build/components/BuilderActions/components/RunGraph/useRunGraph.tsindex 19b3846b21..5eced161bc 100644--- a/autogpt_platform/frontend/src/app/(platform)/build/components/BuilderActions/components/RunGraph/useRunGraph.ts+++ b/autogpt_platform/frontend/src/app/(platform)/build/components/BuilderActions/components/RunGraph/useRunGraph.ts@@ -87,7 +87,7 @@ export const useRunGraph = () => {// Simulate goes through the same mutation as Run; only a real run// is an activation.if (!variables.data.dry_run) {- trackAgentRunGoal({ id: graph_id }, "builder");+ trackAgentRunGoal(graph_id, "builder");}},onError: (error: any) => {diff --git a/autogpt_platform/frontend/src/app/(platform)/build/components/BuilderActions/components/RunInputDialog/useRunInputDialog.test.tsx b/autogpt_platform/frontend/src/app/(platform)/build/components/BuilderActions/components/RunInputDialog/useRunInputDialog.test.tsxindex a302cd54af..90ceaadf24 100644--- a/autogpt_platform/frontend/src/app/(platform)/build/components/BuilderActions/components/RunInputDialog/useRunInputDialog.test.tsx+++ b/autogpt_platform/frontend/src/app/(platform)/build/components/BuilderActions/components/RunInputDialog/useRunInputDialog.test.tsx@@ -142,7 +142,6 @@ describe("useRunInputDialog", () => {expect(mockSendDatafastEvent).toHaveBeenCalledExactlyOnceWith("run_agent", {id: "graph-1",- name: "",surface: "builder",});});diff --git a/autogpt_platform/frontend/src/app/(platform)/build/components/BuilderActions/components/RunInputDialog/useRunInputDialog.ts b/autogpt_platform/frontend/src/app/(platform)/build/components/BuilderActions/components/RunInputDialog/useRunInputDialog.tsindex 26daafa85f..32e3da84a3 100644--- a/autogpt_platform/frontend/src/app/(platform)/build/components/BuilderActions/components/RunInputDialog/useRunInputDialog.ts+++ b/autogpt_platform/frontend/src/app/(platform)/build/components/BuilderActions/components/RunInputDialog/useRunInputDialog.ts@@ -49,7 +49,7 @@ export const useRunInputDialog = ({setQueryStates({flowExecutionID: id,});- trackAgentRunGoal({ id: graph_id }, "builder");+ trackAgentRunGoal(graph_id, "builder");},onError: (error) => {if (error instanceof ApiError && error.isGraphValidationError()) {diff --git a/autogpt_platform/frontend/src/app/(platform)/library/agents/[id]/components/NewAgentLibraryView/components/modals/RunAgentModal/useAgentRunModal.test.tsx b/autogpt_platform/frontend/src/app/(platform)/library/agents/[id]/components/NewAgentLibraryView/components/modals/RunAgentModal/useAgentRunModal.test.tsxindex 15282c8f8b..8ac5eec440 100644--- a/autogpt_platform/frontend/src/app/(platform)/library/agents/[id]/components/NewAgentLibraryView/components/modals/RunAgentModal/useAgentRunModal.test.tsx+++ b/autogpt_platform/frontend/src/app/(platform)/library/agents/[id]/components/NewAgentLibraryView/components/modals/RunAgentModal/useAgentRunModal.test.tsx@@ -73,7 +73,6 @@ describe("useAgentRunModal", () => {});expect(sendDatafastEvent).toHaveBeenCalledExactlyOnceWith("run_agent", {id: "graph-xyz",- name: "My agent",surface: "library",});});diff --git a/autogpt_platform/frontend/src/app/(platform)/library/agents/[id]/components/NewAgentLibraryView/components/modals/RunAgentModal/useAgentRunModal.tsx b/autogpt_platform/frontend/src/app/(platform)/library/agents/[id]/components/NewAgentLibraryView/components/modals/RunAgentModal/useAgentRunModal.tsxindex e9ae987524..33f914d2ec 100644--- a/autogpt_platform/frontend/src/app/(platform)/library/agents/[id]/components/NewAgentLibraryView/components/modals/RunAgentModal/useAgentRunModal.tsx+++ b/autogpt_platform/frontend/src/app/(platform)/library/agents/[id]/components/NewAgentLibraryView/components/modals/RunAgentModal/useAgentRunModal.tsx@@ -169,10 +169,7 @@ export function useAgentRunModal(// Simulate goes through the same mutation as Run; only a real run// is an activation.if (!variables.data.dry_run) {- trackAgentRunGoal(- { id: agent.graph_id, name: agent.name },- "library",- );+ trackAgentRunGoal(agent.graph_id, "library");}setIsOpen(false);}diff --git a/autogpt_platform/frontend/src/app/(platform)/library/agents/[id]/components/NewAgentLibraryView/components/modals/ScheduleAgentModal/useScheduleAgentModal.ts b/autogpt_platform/frontend/src/app/(platform)/library/agents/[id]/components/NewAgentLibraryView/components/modals/ScheduleAgentModal/useScheduleAgentModal.tsindex 97e7aae1a2..1005be147c 100644--- a/autogpt_platform/frontend/src/app/(platform)/library/agents/[id]/components/NewAgentLibraryView/components/modals/ScheduleAgentModal/useScheduleAgentModal.ts+++ b/autogpt_platform/frontend/src/app/(platform)/library/agents/[id]/components/NewAgentLibraryView/components/modals/ScheduleAgentModal/useScheduleAgentModal.ts@@ -34,10 +34,7 @@ export function useScheduleAgentModal(toast({title: "Schedule created",});- trackScheduleCreatedGoal(- { id: agent.graph_id, name: agent.name },- "library",- );+ trackScheduleCreatedGoal(agent.graph_id, "library");callbacks?.onCreateSchedule?.(response.data);invalidateAllScheduleQueries(queryClient, agent.graph_id);// Reset formdiff --git a/autogpt_platform/frontend/src/app/(platform)/library/agents/[id]/components/NewAgentLibraryView/components/selected-views/SelectedRunView/components/SelectedRunActions/useSelectedRunActions.test.tsx b/autogpt_platform/frontend/src/app/(platform)/library/agents/[id]/components/NewAgentLibraryView/components/selected-views/SelectedRunView/components/SelectedRunActions/useSelectedRunActions.test.tsxindex 035f789c2d..ab54397522 100644--- a/autogpt_platform/frontend/src/app/(platform)/library/agents/[id]/components/NewAgentLibraryView/components/selected-views/SelectedRunView/components/SelectedRunActions/useSelectedRunActions.test.tsx+++ b/autogpt_platform/frontend/src/app/(platform)/library/agents/[id]/components/NewAgentLibraryView/components/selected-views/SelectedRunView/components/SelectedRunActions/useSelectedRunActions.test.tsx@@ -85,7 +85,6 @@ describe("useSelectedRunActions", () => {});expect(sendDatafastEvent).toHaveBeenCalledExactlyOnceWith("run_agent", {id: "graph-xyz",- name: "My agent",surface: "rerun",});});diff --git a/autogpt_platform/frontend/src/app/(platform)/library/agents/[id]/components/NewAgentLibraryView/components/selected-views/SelectedRunView/components/SelectedRunActions/useSelectedRunActions.ts b/autogpt_platform/frontend/src/app/(platform)/library/agents/[id]/components/NewAgentLibraryView/components/selected-views/SelectedRunView/components/SelectedRunActions/useSelectedRunActions.tsindex 8a8d8a37a9..b4088238e1 100644--- a/autogpt_platform/frontend/src/app/(platform)/library/agents/[id]/components/NewAgentLibraryView/components/selected-views/SelectedRunView/components/SelectedRunActions/useSelectedRunActions.ts+++ b/autogpt_platform/frontend/src/app/(platform)/library/agents/[id]/components/NewAgentLibraryView/components/selected-views/SelectedRunView/components/SelectedRunActions/useSelectedRunActions.ts@@ -99,7 +99,7 @@ export function useSelectedRunActions({const newRunId = okData(res)?.id;if (newRunId) {- trackAgentRunGoal({ id: run.graph_id, name: agent?.name }, "rerun");+ trackAgentRunGoal(run.graph_id, "rerun");}await queryClient.invalidateQueries({diff --git a/autogpt_platform/frontend/src/app/(platform)/library/agents/[id]/components/NewAgentLibraryView/components/selected-views/SelectedScheduleView/components/SelectedScheduleActions/useSelectedScheduleActions.test.tsx b/autogpt_platform/frontend/src/app/(platform)/library/agents/[id]/components/NewAgentLibraryView/components/selected-views/SelectedScheduleView/components/SelectedScheduleActions/useSelectedScheduleActions.test.tsxindex 97ffae1a35..115abd337e 100644--- a/autogpt_platform/frontend/src/app/(platform)/library/agents/[id]/components/NewAgentLibraryView/components/selected-views/SelectedScheduleView/components/SelectedScheduleActions/useSelectedScheduleActions.test.tsx+++ b/autogpt_platform/frontend/src/app/(platform)/library/agents/[id]/components/NewAgentLibraryView/components/selected-views/SelectedScheduleView/components/SelectedScheduleActions/useSelectedScheduleActions.test.tsx@@ -152,7 +152,6 @@ describe("useSelectedScheduleActions", () => {});expect(sendDatafastEvent).toHaveBeenCalledExactlyOnceWith("run_agent", {id: "graph-xyz",- name: "My agent",surface: "library",});});diff --git a/autogpt_platform/frontend/src/app/(platform)/library/agents/[id]/components/NewAgentLibraryView/components/selected-views/SelectedScheduleView/components/SelectedScheduleActions/useSelectedScheduleActions.ts b/autogpt_platform/frontend/src/app/(platform)/library/agents/[id]/components/NewAgentLibraryView/components/selected-views/SelectedScheduleView/components/SelectedScheduleActions/useSelectedScheduleActions.tsindex def829fa21..be91e17781 100644--- a/autogpt_platform/frontend/src/app/(platform)/library/agents/[id]/components/NewAgentLibraryView/components/selected-views/SelectedScheduleView/components/SelectedScheduleActions/useSelectedScheduleActions.ts+++ b/autogpt_platform/frontend/src/app/(platform)/library/agents/[id]/components/NewAgentLibraryView/components/selected-views/SelectedScheduleView/components/SelectedScheduleActions/useSelectedScheduleActions.ts@@ -88,10 +88,7 @@ export function useSelectedScheduleActions({const newRunID = okData(res)?.id;if (newRunID) {- trackAgentRunGoal(- { id: schedule.graph_id, name: agent.name },- "library",- );+ trackAgentRunGoal(schedule.graph_id, "library");}await queryClient.invalidateQueries({diff --git a/autogpt_platform/frontend/src/app/(platform)/library/agents/[id]/components/NewAgentLibraryView/components/sidebar/SidebarRunsList/components/ScheduleActionsDropdown.test.tsx b/autogpt_platform/frontend/src/app/(platform)/library/agents/[id]/components/NewAgentLibraryView/components/sidebar/SidebarRunsList/components/ScheduleActionsDropdown.test.tsxindex 4cd22a22ca..81456db54d 100644--- a/autogpt_platform/frontend/src/app/(platform)/library/agents/[id]/components/NewAgentLibraryView/components/sidebar/SidebarRunsList/components/ScheduleActionsDropdown.test.tsx+++ b/autogpt_platform/frontend/src/app/(platform)/library/agents/[id]/components/NewAgentLibraryView/components/sidebar/SidebarRunsList/components/ScheduleActionsDropdown.test.tsx@@ -79,7 +79,6 @@ describe("ScheduleActionsDropdown", () => {});expect(sendDatafastEvent).toHaveBeenCalledExactlyOnceWith("run_agent", {id: "graph-xyz",- name: "My agent",surface: "library",});});diff --git a/autogpt_platform/frontend/src/app/(platform)/library/agents/[id]/components/NewAgentLibraryView/components/sidebar/SidebarRunsList/components/ScheduleActionsDropdown.tsx b/autogpt_platform/frontend/src/app/(platform)/library/agents/[id]/components/NewAgentLibraryView/components/sidebar/SidebarRunsList/components/ScheduleActionsDropdown.tsxindex 1ad5d0dcc8..ef565d1442 100644--- a/autogpt_platform/frontend/src/app/(platform)/library/agents/[id]/components/NewAgentLibraryView/components/sidebar/SidebarRunsList/components/ScheduleActionsDropdown.tsx+++ b/autogpt_platform/frontend/src/app/(platform)/library/agents/[id]/components/NewAgentLibraryView/components/sidebar/SidebarRunsList/components/ScheduleActionsDropdown.tsx@@ -89,10 +89,7 @@ export function ScheduleActionsDropdown({const newRunID = okData(res)?.id;if (newRunID) {- trackAgentRunGoal(- { id: schedule.graph_id, name: agent.name },- "library",- );+ trackAgentRunGoal(schedule.graph_id, "library");}await queryClient.invalidateQueries({diff --git a/autogpt_platform/frontend/src/app/(platform)/marketplace/components/AddToLibraryButton/AddToLibraryButton.tsx b/autogpt_platform/frontend/src/app/(platform)/marketplace/components/AddToLibraryButton/AddToLibraryButton.tsxindex 20cc52b3bf..ab05705761 100644--- a/autogpt_platform/frontend/src/app/(platform)/marketplace/components/AddToLibraryButton/AddToLibraryButton.tsx+++ b/autogpt_platform/frontend/src/app/(platform)/marketplace/components/AddToLibraryButton/AddToLibraryButton.tsx@@ -135,10 +135,7 @@ export function AddToLibraryButton({queryKey: getGetV2ListLibraryAgentsQueryKey(),});- analytics.sendDatafastEvent("add_to_library", {- name: data.name,- id: data.id,- });+ analytics.sendDatafastEvent("add_to_library", { id: data.id });const addedToast = toast({title: `Workflow ${agentName} added to your library.`,diff --git a/autogpt_platform/frontend/src/app/(platform)/marketplace/components/AgentInfo/useAgentInfo.test.tsx b/autogpt_platform/frontend/src/app/(platform)/marketplace/components/AgentInfo/useAgentInfo.test.tsxnew file mode 100644index 0000000000..48d331b568--- /dev/null+++ b/autogpt_platform/frontend/src/app/(platform)/marketplace/components/AgentInfo/useAgentInfo.test.tsx@@ -0,0 +1,72 @@+import { getPostV2AddMarketplaceAgentMockHandler } from "@/app/api/__generated__/endpoints/library/library.msw";+import { getGetV2DownloadAgentFileMockHandler } from "@/app/api/__generated__/endpoints/store/store.msw";+import type { LibraryAgent } from "@/app/api/__generated__/models/libraryAgent";+import { server } from "@/mocks/mock-server";+import { act, renderHook } from "@/tests/integrations/test-utils";+import { QueryClient, QueryClientProvider } from "@tanstack/react-query";+import type { ReactNode } from "react";+import { afterEach, describe, expect, test, vi } from "vitest";+import { useAgentInfo } from "./useAgentInfo";++function wrapper({ children }: { children: ReactNode }) {+ const client = new QueryClient({+ defaultOptions: { queries: { retry: false } },+ });+ return <QueryClientProvider client={client}>{children}</QueryClientProvider>;+}++const sendDatafastEvent = vi.hoisted(() => vi.fn());+vi.mock("@/services/analytics", () => ({+ analytics: { sendDatafastEvent },+}));++vi.mock("@/lib/utils", async (importOriginal) => ({+ ...(await importOriginal<typeof import("@/lib/utils")>()),+ exportAsJSONFile: vi.fn(),+}));++afterEach(() => {+ sendDatafastEvent.mockClear();+ server.resetHandlers();+});++describe("useAgentInfo", () => {+ test("add_to_library carries the library ID and no workflow name", async () => {+ server.use(+ getPostV2AddMarketplaceAgentMockHandler({+ id: "lib-1",+ name: "Jane's private workflow",+ } as LibraryAgent),+ );+ const { result } = renderHook(+ () => useAgentInfo({ storeListingVersionId: "slv-1" }),+ { wrapper },+ );++ await act(() =>+ result.current.handleLibraryAction({ isAddingAgentFirstTime: true }),+ );++ expect(sendDatafastEvent).toHaveBeenCalledExactlyOnceWith(+ "add_to_library",+ { id: "lib-1" },+ );+ });++ test("download_agent carries the ID and no workflow name", async () => {+ server.use(getGetV2DownloadAgentFileMockHandler());+ const { result } = renderHook(+ () => useAgentInfo({ storeListingVersionId: "slv-1" }),+ { wrapper },+ );++ await act(() =>+ result.current.handleDownload("agent-1", "Jane's private workflow"),+ );++ expect(sendDatafastEvent).toHaveBeenCalledExactlyOnceWith(+ "download_agent",+ { id: "agent-1" },+ );+ });+});diff --git a/autogpt_platform/frontend/src/app/(platform)/marketplace/components/AgentInfo/useAgentInfo.ts b/autogpt_platform/frontend/src/app/(platform)/marketplace/components/AgentInfo/useAgentInfo.tsindex 22203f05e7..889432e53c 100644--- a/autogpt_platform/frontend/src/app/(platform)/marketplace/components/AgentInfo/useAgentInfo.ts+++ b/autogpt_platform/frontend/src/app/(platform)/marketplace/components/AgentInfo/useAgentInfo.ts@@ -52,10 +52,7 @@ export const useAgentInfo = ({ storeListingVersionId }: UseAgentInfoProps) => {queryKey: getGetV2ListLibraryAgentsQueryKey(),});- analytics.sendDatafastEvent("add_to_library", {- name: data.name,- id: data.id,- });+ analytics.sendDatafastEvent("add_to_library", { id: data.id });}router.push(`/library/agents/${data.id}`);@@ -85,10 +82,7 @@ export const useAgentInfo = ({ storeListingVersionId }: UseAgentInfoProps) => {agentGraphExportFilename(file, agentName),);- analytics.sendDatafastEvent("download_agent", {- name: agentName,- id: agentId,- });+ analytics.sendDatafastEvent("download_agent", { id: agentId });toast({title: "Download Complete",diff --git a/autogpt_platform/frontend/src/app/(public)/tour/chat/__tests__/share.test.tsx b/autogpt_platform/frontend/src/app/(public)/tour/chat/__tests__/share.test.tsxindex b4c9f1c44e..49e77512ef 100644--- a/autogpt_platform/frontend/src/app/(public)/tour/chat/__tests__/share.test.tsx+++ b/autogpt_platform/frontend/src/app/(public)/tour/chat/__tests__/share.test.tsx@@ -13,7 +13,11 @@ vi.mock("@/components/ui/dot-distortion-shader", () => ({DotDistortionShader: () => null,}));-import { configureCookiebot } from "@/tests/integrations/cookiebot";+import {+ configureCookiebot,+ installCookiebot,+ removeCookiebot,+} from "@/tests/integrations/cookiebot";import TourChatPage from "../page";import { DEFAULT_SCENARIO_ID } from "../script/tourScenarios";@@ -31,9 +35,9 @@ describe("Tour share button", () => {});clipboardWrite.mockClear();clipboardWrite.mockImplementation(async () => {});- // /tour sends DataFast events without consent, but only on the tour- // itself and only when a consent banner is configured.+ // DataFast waits for analytics consent on the tour like everywhere else.configureCookiebot();+ installCookiebot({ statistics: true });window.history.pushState({}, "", "/tour/chat");window.datafast = datafast;datafast.mockClear();@@ -51,6 +55,7 @@ describe("Tour share button", () => {vi.runOnlyPendingTimers();vi.useRealTimers();vi.unstubAllEnvs();+ removeCookiebot();window.history.pushState({}, "", "/");});diff --git a/autogpt_platform/frontend/src/app/(public)/tour/chat/__tests__/tracking.test.tsx b/autogpt_platform/frontend/src/app/(public)/tour/chat/__tests__/tracking.test.tsxindex 67215969a8..7be9afc0ac 100644--- a/autogpt_platform/frontend/src/app/(public)/tour/chat/__tests__/tracking.test.tsx+++ b/autogpt_platform/frontend/src/app/(public)/tour/chat/__tests__/tracking.test.tsx@@ -64,9 +64,9 @@ describe("Tour DataFast tracking", () => {beforeEach(() => {vi.useFakeTimers();vi.stubEnv("NEXT_PUBLIC_BEHAVE_AS", "CLOUD");- // /tour sends DataFast events without consent, but only on the tour- // itself and only when a consent banner is configured.+ // DataFast waits for analytics consent on the tour like everywhere else.configureCookiebot();+ installCookiebot({ statistics: true });window.history.pushState({}, "", "/tour/chat");window.datafast = datafast;datafast.mockClear();@@ -89,6 +89,28 @@ describe("Tour DataFast tracking", () => {window.history.pushState({}, "", "/");});+ test("sends no DataFast events before the visitor consents", async () => {+ installCookiebot();+ render(<TourChatPage />);+ await advanceThroughTurn();+ await pressEnterToSend();+ fireEvent.click(screen.getByText("Make this workflow yours"));++ expect(datafast).not.toHaveBeenCalled();+ });++ test("fires tour_start on a later visit when consent was not known on the first", async () => {+ installCookiebot();+ const first = render(<TourChatPage />);+ first.unmount();+ expect(eventsNamed("tour_start")).toHaveLength(0);++ installCookiebot({ statistics: true });+ render(<TourChatPage />);++ expect(eventsNamed("tour_start")).toHaveLength(1);+ });+test("fires tour_start once per session and tour_scenario_start per scenario run", async () => {render(<TourChatPage />);diff --git a/autogpt_platform/frontend/src/app/(public)/tour/chat/tracking.ts b/autogpt_platform/frontend/src/app/(public)/tour/chat/tracking.tsindex b8b8dfddc0..7cfe5bef17 100644--- a/autogpt_platform/frontend/src/app/(public)/tour/chat/tracking.ts+++ b/autogpt_platform/frontend/src/app/(public)/tour/chat/tracking.ts@@ -24,14 +24,20 @@ export function trackTourStart() {{},{ oncePerTabKey: POSTHOG_TOUR_START_KEY },);+ // DataFast's guard is marked only once the event goes out: an event dropped+ // because consent was not known yet gets another chance on the next mount.try {if (sessionStorage.getItem(TOUR_START_SESSION_KEY)) return;- sessionStorage.setItem(TOUR_START_SESSION_KEY, "1");} catch {// In-app browsers may block sessionStorage — double-counting a visit// beats dropping it.}- analytics.sendDatafastEvent("tour_start", {});+ if (!analytics.sendDatafastEvent("tour_start", {})) return;+ try {+ sessionStorage.setItem(TOUR_START_SESSION_KEY, "1");+ } catch {+ // See above.+ }}export function trackTourScenarioStart(scenarioId: string) {diff --git a/autogpt_platform/frontend/src/services/analytics/__tests__/activation-goals.test.ts b/autogpt_platform/frontend/src/services/analytics/__tests__/activation-goals.test.tsindex 279da42347..0399ff99b7 100644--- a/autogpt_platform/frontend/src/services/analytics/__tests__/activation-goals.test.ts+++ b/autogpt_platform/frontend/src/services/analytics/__tests__/activation-goals.test.ts@@ -15,22 +15,20 @@ beforeEach(() => {});describe("activation goals", () => {- it("reports a human agent run with its surface", () => {- trackAgentRunGoal({ id: "graph-1", name: "Daily digest" }, "builder");+ it("reports a human agent run with its surface and no workflow name", () => {+ trackAgentRunGoal("graph-1", "builder");expect(sendDatafastEvent).toHaveBeenCalledWith("run_agent", {id: "graph-1",- name: "Daily digest",surface: "builder",});});- it("reports a new schedule and tolerates a missing agent name", () => {- trackScheduleCreatedGoal({ id: "graph-2", name: null }, "library");+ it("reports a new schedule with its surface and no workflow name", () => {+ trackScheduleCreatedGoal("graph-2", "library");expect(sendDatafastEvent).toHaveBeenCalledWith("schedule_agent", {id: "graph-2",- name: "",surface: "library",});});@@ -40,6 +38,6 @@ describe("activation goals", () => {throw new Error("tag exploded");});- expect(() => trackAgentRunGoal({ id: "graph-3" }, "rerun")).not.toThrow();+ expect(() => trackAgentRunGoal("graph-3", "rerun")).not.toThrow();});});diff --git a/autogpt_platform/frontend/src/services/analytics/__tests__/consent-consumers.test.tsx b/autogpt_platform/frontend/src/services/analytics/__tests__/consent-consumers.test.tsxindex dad3173e7a..c2a3e2cb38 100644--- a/autogpt_platform/frontend/src/services/analytics/__tests__/consent-consumers.test.tsx+++ b/autogpt_platform/frontend/src/services/analytics/__tests__/consent-consumers.test.tsx@@ -160,57 +160,6 @@ describe("with NEXT_PUBLIC_COOKIEBOT_CBID", () => {});});-describe("DataFast loaded under the tour exemption", () => {- const reload = vi.fn<() => void>();- let loaded: HTMLScriptElement | null = null;-- function loadDataFast({ exempt }: { exempt: boolean }) {- loaded = document.createElement("script");- loaded.src = DATAFAST_SRC;- if (exempt) loaded.dataset.consentExempt = "true";- document.head.appendChild(loaded);- }-- beforeEach(() => {- configureCookiebot();- reload.mockReset();- vi.spyOn(window.location, "reload").mockImplementation(() => reload());- });-- afterEach(() => {- loaded?.remove();- loaded = null;- vi.restoreAllMocks();- });-- it("reloads to shed the script once the visitor leaves the tour without consent", () => {- loadDataFast({ exempt: true });- installCookiebot();-- render(<SetupAnalytics host="platform.agpt.co" ga={GA} />);-- expect(reload).toHaveBeenCalledOnce();- });-- it("keeps the script when the visitor has consented", () => {- loadDataFast({ exempt: true });- installCookiebot({ statistics: true });-- render(<SetupAnalytics host="platform.agpt.co" ga={GA} />);-- expect(reload).not.toHaveBeenCalled();- });-- it("waits for the visitor's reply when Cookiebot asks again about a script loaded with consent", () => {- loadDataFast({ exempt: false });- installCookiebot();-- render(<SetupAnalytics host="platform.agpt.co" ga={GA} />);-- expect(reload).not.toHaveBeenCalled();- });-});-describe("ConsentWithdrawalReload", () => {const reload = vi.fn<() => void>();diff --git a/autogpt_platform/frontend/src/services/analytics/activation-goals.ts b/autogpt_platform/frontend/src/services/analytics/activation-goals.tsindex 675dafa370..9e1bdddc4d 100644--- a/autogpt_platform/frontend/src/services/analytics/activation-goals.ts+++ b/autogpt_platform/frontend/src/services/analytics/activation-goals.ts@@ -18,20 +18,17 @@ import { analytics } from "@/services/analytics";export type AgentRunSurface = "library" | "builder" | "rerun";export type ScheduleSurface = "library" | "builder";-interface AgentRef {- id: string;- name?: string | null;-}--export function trackAgentRunGoal(agent: AgentRef, surface: AgentRunSurface) {- sendGoal("run_agent", { id: agent.id, name: agent.name ?? "", surface });+// Only the graph ID goes to DataFast: workflow names are written by people+// and may hold personal data.+export function trackAgentRunGoal(graphId: string, surface: AgentRunSurface) {+ sendGoal("run_agent", { id: graphId, surface });}export function trackScheduleCreatedGoal(- agent: AgentRef,+ graphId: string,surface: ScheduleSurface,) {- sendGoal("schedule_agent", { id: agent.id, name: agent.name ?? "", surface });+ sendGoal("schedule_agent", { id: graphId, surface });}function sendGoal(name: string, metadata: Record<string, string>) {diff --git a/autogpt_platform/frontend/src/services/analytics/index.test.ts b/autogpt_platform/frontend/src/services/analytics/index.test.tsindex 93428d8968..cbf670f8de 100644--- a/autogpt_platform/frontend/src/services/analytics/index.test.ts+++ b/autogpt_platform/frontend/src/services/analytics/index.test.ts@@ -95,84 +95,58 @@ describe("sendDatafastEvent", () => {]);});- it("does not queue pre-consent events outside the tour", () => {- vi.mocked(hasConsentFor).mockReturnValue(false);-- analytics.sendDatafastEvent("run_agent", { agent_name: "x" });+ it("reports whether the event was sent, queued or dropped", () => {+ expect(analytics.sendDatafastEvent("tour_start", {})).toBe(true);- const datafast = vi.fn();- window.datafast = datafast;- flushDatafastQueue();+ window.datafast = vi.fn();+ expect(analytics.sendDatafastEvent("tour_start", {})).toBe(true);- expect(datafast).not.toHaveBeenCalled();- });-- it("does not send without consent once the script has loaded", () => {- // DataFast loaded under the tour exemption stays on window after the- // visitor navigates away from /tour.vi.mocked(hasConsentFor).mockReturnValue(false);- configureCookiebot();- window.history.pushState({}, "", "/marketplace");- const datafast = vi.fn();- window.datafast = datafast;-- analytics.sendDatafastEvent("run_agent", { agent_name: "x" });-- expect(datafast).not.toHaveBeenCalled();+ expect(analytics.sendDatafastEvent("tour_start", {})).toBe(false);});- it("queues pre-consent events on the consent-exempt tour pages", () => {+ it("does not queue pre-consent events", () => {vi.mocked(hasConsentFor).mockReturnValue(false);- configureCookiebot();- window.history.pushState({}, "", "/tour/chat");- analytics.sendDatafastEvent("tour_start", {});+ analytics.sendDatafastEvent("run_agent", { id: "graph-1" });const datafast = vi.fn();window.datafast = datafast;flushDatafastQueue();- expect(datafast).toHaveBeenCalledWith("tour_start", {});+ expect(datafast).not.toHaveBeenCalled();});- it("sends tour events without consent once the script has loaded", () => {+ it("does not send without consent once the script has loaded", () => {+ // The script stays on window after the visitor takes consent back.vi.mocked(hasConsentFor).mockReturnValue(false);configureCookiebot();- window.history.pushState({}, "", "/tour");+ window.history.pushState({}, "", "/marketplace");const datafast = vi.fn();window.datafast = datafast;- analytics.sendDatafastEvent("tour_start", {});-- expect(datafast).toHaveBeenCalledWith("tour_start", {});- });-- it("does not exempt the tour without a consent banner", () => {- vi.mocked(hasConsentFor).mockReturnValue(false);- vi.stubEnv("NEXT_PUBLIC_COOKIEBOT_CBID", "");- window.history.pushState({}, "", "/tour/chat");-- analytics.sendDatafastEvent("tour_start", {});-- const datafast = vi.fn();- window.datafast = datafast;- flushDatafastQueue();+ analytics.sendDatafastEvent("run_agent", { id: "graph-1" });expect(datafast).not.toHaveBeenCalled();});- it("does not treat /tourism as a consent-exempt tour page", () => {- vi.mocked(hasConsentFor).mockReturnValue(false);- window.history.pushState({}, "", "/tourism");+ it.each(["/tour", "/tour/chat"])(+ "waits for consent on the public tour (%s) like everywhere else",+ (path) => {+ vi.mocked(hasConsentFor).mockReturnValue(false);+ configureCookiebot();+ window.history.pushState({}, "", path);- analytics.sendDatafastEvent("tour_start", {});+ analytics.sendDatafastEvent("tour_start", {});- const datafast = vi.fn();- window.datafast = datafast;- flushDatafastQueue();+ const datafast = vi.fn();+ window.datafast = datafast;+ flushDatafastQueue();+ analytics.sendDatafastEvent("tour_scenario_start", { scenario: "x" });- expect(datafast).not.toHaveBeenCalled();- });+ expect(datafast).not.toHaveBeenCalled();+ },+ );it("warns again when the queue overflows after a successful flush", () => {const warn = vi.spyOn(console, "warn").mockImplementation(() => {});diff --git a/autogpt_platform/frontend/src/services/analytics/index.tsx b/autogpt_platform/frontend/src/services/analytics/index.tsxindex 0dca9709da..c708ee0bd5 100644--- a/autogpt_platform/frontend/src/services/analytics/index.tsx+++ b/autogpt_platform/frontend/src/services/analytics/index.tsx@@ -6,15 +6,12 @@"use client";import type { GAParams } from "@/types/google";-import {- hasConsentFor,- isConsentManagerConfigured,-} from "@/services/consent/consent";+import { hasConsentFor } from "@/services/consent/consent";import Script from "next/script";import { environment } from "../environment";import { GoogleConsentModeSync } from "./GoogleConsentModeSync";import { DATA_LAYER_NAME, gtag } from "./gtag";-import { DATAFAST_SCRIPT_SRC, isDataFastConsentExempt } from "./loading-policy";+import { DATAFAST_SCRIPT_SRC } from "./loading-policy";import { useSetupAnalytics } from "./useSetupAnalytics";type DatafastEvent = [name: string, metadata: Record<string, unknown>];@@ -34,8 +31,7 @@ export function SetupAnalytics(props: SetupProps) {const { ga, host } = props;const { gaId, debugMode, nonce } = ga;const adsID = environment.getGoogleAdsID();- const { googleTagEnabled, dataFastEnabled, dataFastWithoutConsent } =- useSetupAnalytics(host);+ const { googleTagEnabled, dataFastEnabled } = useSetupAnalytics(host);return (<>@@ -71,7 +67,6 @@ export function SetupAnalytics(props: SetupProps) {data-website-id="dfid_g5wtBIiHUwSkWKcGz80lu"data-domain="agpt.co"src={DATAFAST_SCRIPT_SRC}- data-consent-exempt={dataFastWithoutConsent ? "true" : undefined}onLoad={flushDatafastQueue}/>) : null}@@ -124,24 +119,24 @@ const MAX_QUEUED_DATAFAST_EVENTS = 100;const datafastQueue: DatafastEvent[] = [];let datafastQueueOverflowWarned = false;-function sendDatafastEvent(name: string, metadata: Record<string, unknown>) {- if (typeof window === "undefined") return;- // Checked on every event, not only before the script loads: a script the- // tour loaded stays on window after navigating away from it, and must not- // carry events the visitor never agreed to. Pre-consent events must not+// Returns whether the event was sent or queued, so a once-per-session guard+// can stay unset when the event was dropped.+function sendDatafastEvent(+ name: string,+ metadata: Record<string, unknown>,+): boolean {+ if (typeof window === "undefined") return false;+ // Checked on every event, not only before the script loads: the script+ // stays on window after consent is taken back. Pre-consent events must not// queue either — they would be replayed once consent is granted.- const consentExempt = isDataFastConsentExempt(- window.location.pathname,- isConsentManagerConfigured(),- );- if (!consentExempt && !hasConsentFor("analytics")) return;+ if (!hasConsentFor("analytics")) return false;if (window.datafast) {// Self-heal if the Script's onLoad never fired (e.g. consent toggle// remounted it after the script had already loaded): replay the backlog// first so queued events keep their order ahead of this one.flushDatafastQueue();window.datafast(name, metadata);- return;+ return true;}// The script loads afterInteractive, so mount-time events (tour_start,// tour_scenario_start) fire before window.datafast exists. Queue them and@@ -153,9 +148,10 @@ function sendDatafastEvent(name: string, metadata: Record<string, unknown>) {`DataFast queue full (${MAX_QUEUED_DATAFAST_EVENTS} events); dropping new events until the script loads`,);}- return;+ return false;}datafastQueue.push([name, metadata]);+ return true;}export function flushDatafastQueue() {diff --git a/autogpt_platform/frontend/src/services/analytics/loading-policy.test.ts b/autogpt_platform/frontend/src/services/analytics/loading-policy.test.tsindex 07b4def351..55e76858ac 100644--- a/autogpt_platform/frontend/src/services/analytics/loading-policy.test.ts+++ b/autogpt_platform/frontend/src/services/analytics/loading-policy.test.ts@@ -8,7 +8,6 @@ function consent(overrides: Partial<ConsentState> = {}): ConsentState {const production = {host: "platform.agpt.co",- pathname: "/marketplace",isLocal: false,isConsentManaged: true,};@@ -92,7 +91,6 @@ describe("resolveAnalyticsLoading", () => {it("loads the Google tag locally only with analytics consent", () => {const local = {host: "localhost:3000",- pathname: "/",isLocal: true,isConsentManaged: true,};@@ -116,35 +114,4 @@ describe("resolveAnalyticsLoading", () => {expect(result.dataFast).toBe(true);});-- it("loads DataFast on the public tour without consent", () => {- const result = resolveAnalyticsLoading({- ...production,- pathname: "/tour/chat",- consent: consent(),- });-- expect(result.dataFast).toBe(true);- });-- it("keeps DataFast off the tour when no banner is configured", () => {- const result = resolveAnalyticsLoading({- ...production,- pathname: "/tour",- isConsentManaged: false,- consent: consent(),- });-- expect(result).toEqual({ googleTag: false, dataFast: false });- });-- it("does not treat /tourism as the tour", () => {- const result = resolveAnalyticsLoading({- ...production,- pathname: "/tourism",- consent: consent(),- });-- expect(result.dataFast).toBe(false);- });});diff --git a/autogpt_platform/frontend/src/services/analytics/loading-policy.ts b/autogpt_platform/frontend/src/services/analytics/loading-policy.tsindex ee2e4dfc52..b8c9ba6947 100644--- a/autogpt_platform/frontend/src/services/analytics/loading-policy.ts+++ b/autogpt_platform/frontend/src/services/analytics/loading-policy.ts@@ -4,7 +4,6 @@ export const DATAFAST_SCRIPT_SRC = "https://datafa.st/js/script.js";interface LoadingArgs {host: string;- pathname: string | null;isLocal: boolean;isConsentManaged: boolean;consent: ConsentState;@@ -12,7 +11,6 @@ interface LoadingArgs {export function resolveAnalyticsLoading({host,- pathname,isLocal,isConsentManaged,consent,@@ -24,35 +22,15 @@ export function resolveAnalyticsLoading({// keeps it cookieless where consent is required (see consent-mode.ts) and// Cookiebot sends the answer once there is one. Without a banner nothing// could ever answer, so the tag stays off. Open-source developers running- // locally only send analytics after opting in.+ // locally only send analytics after opting in. DataFast waits for consent+ // everywhere, the public tour included.googleTag:(isProductionDomain && isConsentManaged) ||(isLocal && consent.analytics),- dataFast:- isProductionDomain &&- (consent.analytics ||- isDataFastConsentExempt(pathname, isConsentManaged)),+ dataFast: isProductionDomain && consent.analytics,};}-// TODO(SECRT-2713): the public tour loads DataFast without the consent gate-// so tour funnel events fire for first-touch visitors. The old banner stayed-// hidden on /tour; Cookiebot's does not, so revisit this exemption there.-// Without a banner nothing optional loads, the tour included.-export function isDataFastConsentExempt(- pathname: string | null,- isConsentManaged: boolean,-): boolean {- return isConsentManaged && isTourPath(pathname);-}--// Segment-boundary match: /tourism must not inherit the tour's consent-// exemption.-function isTourPath(pathname: string | null): boolean {- if (!pathname) return false;- return pathname === "/tour" || pathname.startsWith("/tour/");-}-const PRODUCTION_HOST = "platform.agpt.co";// The Host header is client-controlled, so a substring match would hand thediff --git a/autogpt_platform/frontend/src/services/analytics/useSetupAnalytics.ts b/autogpt_platform/frontend/src/services/analytics/useSetupAnalytics.tsindex 93b9d71247..78c27b3bb6 100644--- a/autogpt_platform/frontend/src/services/analytics/useSetupAnalytics.ts+++ b/autogpt_platform/frontend/src/services/analytics/useSetupAnalytics.ts@@ -2,33 +2,19 @@import { isConsentManagerConfigured } from "@/services/consent/consent";import { useConsent } from "@/services/consent/useConsent";-import { usePathname } from "next/navigation";import { useEffect } from "react";import { environment } from "../environment";-import { DATAFAST_SCRIPT_SRC, resolveAnalyticsLoading } from "./loading-policy";+import { resolveAnalyticsLoading } from "./loading-policy";export function useSetupAnalytics(host: string) {const consent = useConsent();- const pathname = usePathname();const { googleTag, dataFast } = resolveAnalyticsLoading({host,- pathname,isLocal: environment.isLocal(),isConsentManaged: isConsentManagerConfigured(),consent,});- useEffect(() => {- // DataFast's script tracks client-side navigation on its own and can't be- // unloaded, so once the tour's exemption no longer covers it (the visitor- // navigated into the app without consenting) the page reloads to shed it.- // The element stays after unmount, even while still downloading, and is- // only marked when the exemption loaded it: a script loaded with consent- // that Cookiebot is asking about again waits for the visitor's reply.- if (dataFast || !isDataFastLoadedWithoutConsent()) return;- window.location.reload();- }, [dataFast]);-useEffect(() => {if (!googleTag) return;@@ -43,14 +29,5 @@ export function useSetupAnalytics(host: string) {return {googleTagEnabled: googleTag,dataFastEnabled: dataFast,- dataFastWithoutConsent: dataFast && !consent.analytics,};}--function isDataFastLoadedWithoutConsent() {- return Boolean(- document.querySelector(- `script[src="${DATAFAST_SCRIPT_SRC}"][data-consent-exempt]`,- ),- );-}diff --git a/docs/engineering/tracking-plan.md b/docs/engineering/tracking-plan.mdindex d636bfc150..618f5c9948 100644--- a/docs/engineering/tracking-plan.md+++ b/docs/engineering/tracking-plan.md@@ -165,10 +165,13 @@ require `surface = tour`. The signup CTA uses `free-trial` in cloud mode andThe tour funnel also goes to DataFast (`tour_start`, `tour_scenario_start`,`tour_scenario_complete`, `tour_cta_click`); the PostHog events mirror it withthe same properties and nothing identifying in them: `/tour` is public and-pre-signup, so they land on the visitor's anonymous id. `/tour` sends the-DataFast goals without consent (SECRT-2713), but the PostHog events wait for-analytics consent like every browser event, so the two funnels count-differently.+pre-signup, so they land on the visitor's anonymous id. Both need analytics+consent, on `/tour` like everywhere else, but they still count differently:+PostHog holds an event until the visitor's answer arrives, while DataFast drops+any event fired before consent is known. So the DataFast tour funnel misses+mount-time steps (`tour_start`, the first `tour_scenario_start`) on a first+visit where the answer arrives only after the page loads; `tour_start` is+retried on the next tour visit in that session.## Onboarding and activation