Skip to content

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): send the DataFast signup goal under the name the funnel expects (#14167)

Nicholas Tindleb4d81e18fb83
diff --git a/autogpt_platform/frontend/src/services/analytics/datafast-server.test.ts b/autogpt_platform/frontend/src/services/analytics/datafast-server.test.ts
index 37b7791636..9ea45854d3 100644
--- a/autogpt_platform/frontend/src/services/analytics/datafast-server.test.ts
+++ b/autogpt_platform/frontend/src/services/analytics/datafast-server.test.ts
@@ -3,6 +3,7 @@ import { cookies } from "next/headers";
import { after } from "next/server";
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
import {
+ resetConfigErrorReportingForTests,
scheduleAccountCreatedGoal,
wasAccountCreated,
} from "./datafast-server";
@@ -16,6 +17,9 @@ const VISITOR_ID = "a3ab2331-989f-4cfa-91c6-2461c9e3c6bd";
describe("DataFast server-side account creation tracking", () => {
beforeEach(() => {
vi.clearAllMocks();
+ // Misconfiguration is reported once per server instance; give each test a
+ // clean instance so the assertions stay independent of test order.
+ resetConfigErrorReportingForTests();
vi.stubEnv("DATAFAST_API_KEY", "df_test");
vi.stubEnv("NEXT_PUBLIC_BEHAVE_AS", "LOCAL");
vi.mocked(cookies).mockResolvedValue({
@@ -54,9 +58,11 @@ describe("DataFast server-side account creation tracking", () => {
Authorization: "Bearer df_test",
"Content-Type": "application/json",
},
+ // The goal name has to match the "Create Account" step of the DataFast
+ // "Site to Paid" funnel; any other name drops out of the funnel.
body: JSON.stringify({
datafast_visitor_id: VISITOR_ID,
- name: "signup",
+ name: "signup_completed",
metadata: { method: "email" },
}),
}),
@@ -95,10 +101,12 @@ describe("DataFast server-side account creation tracking", () => {
expect(Sentry.captureException).not.toHaveBeenCalled();
});
- it("reports a missing website API key in cloud", async () => {
+ it("reports a missing website API key in cloud once per server instance", async () => {
vi.stubEnv("DATAFAST_API_KEY", "");
vi.stubEnv("NEXT_PUBLIC_BEHAVE_AS", "CLOUD");
+ await scheduleAccountCreatedGoal("email");
+ await scheduleAccountCreatedGoal("google");
await scheduleAccountCreatedGoal("email");
expect(after).not.toHaveBeenCalled();
diff --git a/autogpt_platform/frontend/src/services/analytics/datafast-server.ts b/autogpt_platform/frontend/src/services/analytics/datafast-server.ts
index 149b0ef083..0a580987ff 100644
--- a/autogpt_platform/frontend/src/services/analytics/datafast-server.ts
+++ b/autogpt_platform/frontend/src/services/analytics/datafast-server.ts
@@ -8,6 +8,8 @@ import {
import { environment } from "@/services/environment";
const DATAFAST_GOALS_URL = "https://datafa.st/api/v1/goals";
+// Must match the "Create Account" step of the DataFast "Site to Paid" funnel.
+const ACCOUNT_CREATED_GOAL = "signup_completed";
const DATAFAST_VISITOR_COOKIE = "datafast_visitor_id";
const USER_CREATED_HEADER = "X-AutoGPT-User-Created";
const VISITOR_ID_PATTERN =
@@ -54,10 +56,31 @@ export async function scheduleAccountCreatedGoal(method: SignupMethod) {
}
}
+const reportedConfigErrors = new Set<string>();
+
+/**
+ * A missing or malformed key is one deploy-time mistake, not one failure per
+ * signup. Report it once per server instance so a misconfiguration stays
+ * visible without burying the project in thousands of identical events.
+ */
+function reportConfigurationError(message: string) {
+ if (reportedConfigErrors.has(message)) return;
+ reportedConfigErrors.add(message);
+ reportTrackingError(new Error(message));
+}
+
+/** Restores the once-per-instance reporting state between tests. */
+export function resetConfigErrorReportingForTests() {
+ reportedConfigErrors.clear();
+}
+
function reportTrackingError(error: unknown) {
try {
Sentry.captureException(error, {
- tags: { analytics_provider: "datafast", analytics_goal: "signup" },
+ tags: {
+ analytics_provider: "datafast",
+ analytics_goal: ACCOUNT_CREATED_GOAL,
+ },
});
} catch {
console.error("Failed to report DataFast signup goal error");
@@ -78,13 +101,15 @@ async function getGoalContext(
const apiKey = process.env.DATAFAST_API_KEY?.trim();
if (!apiKey) {
- if (!environment.isCloud()) return null;
-
- throw new Error("DATAFAST_API_KEY must be configured in cloud");
+ if (environment.isCloud()) {
+ reportConfigurationError("DATAFAST_API_KEY must be configured in cloud");
+ }
+ return null;
}
if (!apiKey.startsWith("df_")) {
- throw new Error("DATAFAST_API_KEY must use a df_ website key");
+ reportConfigurationError("DATAFAST_API_KEY must use a df_ website key");
+ return null;
}
return { apiKey, method, visitorID };
@@ -99,7 +124,7 @@ async function sendAccountCreatedGoal(context: GoalContext) {
},
body: JSON.stringify({
datafast_visitor_id: context.visitorID,
- name: "signup",
+ name: ACCOUNT_CREATED_GOAL,
metadata: { method: context.method },
}),
cache: "no-store",