diff --git a/apps/web/app/environments/[environmentId]/FormbricksClient.tsx b/apps/web/app/environments/[environmentId]/FormbricksClient.tsx
index d9414cc230..e4e6f5f32b 100644
--- a/apps/web/app/environments/[environmentId]/FormbricksClient.tsx
+++ b/apps/web/app/environments/[environmentId]/FormbricksClient.tsx
@@ -8,6 +8,7 @@ if (typeof window !== "undefined" && formbricksEnabled) {
formbricks.init({
environmentId: process.env.NEXT_PUBLIC_FORMBRICKS_ENVIRONMENT_ID || "",
apiHost: process.env.NEXT_PUBLIC_FORMBRICKS_API_HOST || "",
+ logLevel: "debug",
});
}
diff --git a/apps/web/app/onboarding/Objective.tsx b/apps/web/app/onboarding/Objective.tsx
index b4fd59ba2d..8b70c5769f 100644
--- a/apps/web/app/onboarding/Objective.tsx
+++ b/apps/web/app/onboarding/Objective.tsx
@@ -55,7 +55,7 @@ const Objective: React.FC
= ({ next, skip, formbricksResponseId
formbricksResponseId
) {
const res = await updateResponse(formbricksResponseId, {
- objective: selectedObjective.id,
+ objective: selectedObjective.label,
});
if (!res.ok) {
console.error("Error updating response", res.error);
diff --git a/apps/web/app/onboarding/Role.tsx b/apps/web/app/onboarding/Role.tsx
index e75eb9e79e..4e0e735641 100644
--- a/apps/web/app/onboarding/Role.tsx
+++ b/apps/web/app/onboarding/Role.tsx
@@ -52,7 +52,7 @@ const Role: React.FC = ({ next, skip, setFormbricksResponseId }) => {
const res = await createResponse(
process.env.NEXT_PUBLIC_FORMBRICKS_ONBOARDING_SURVEY_ID as SurveyId,
{
- role: selectedRole.id,
+ role: selectedRole.label,
}
);
if (res.ok) {
diff --git a/apps/web/lib/formbricks.ts b/apps/web/lib/formbricks.ts
index faee4e7922..703e569812 100644
--- a/apps/web/lib/formbricks.ts
+++ b/apps/web/lib/formbricks.ts
@@ -30,3 +30,7 @@ export const updateResponse = async (
data,
});
};
+
+export const formbricksLogout = async () => {
+ return await formbricks.logout();
+};
diff --git a/apps/web/pages/api/v1/client/environments/[environmentId]/people/[personId]/user-id.ts b/apps/web/pages/api/v1/client/environments/[environmentId]/people/[personId]/user-id.ts
index 4b15d86ed2..739166bd7d 100644
--- a/apps/web/pages/api/v1/client/environments/[environmentId]/people/[personId]/user-id.ts
+++ b/apps/web/pages/api/v1/client/environments/[environmentId]/people/[personId]/user-id.ts
@@ -59,7 +59,7 @@ export default async function handle(req: NextApiRequest, res: NextApiResponse)
},
},
});
- // if person exists, reconnect ression and delete old user
+ // if person exists, reconnect session and delete old user
if (existingPerson) {
// reconnect session to new person
await prisma.session.update({
diff --git a/packages/js/src/index.ts b/packages/js/src/index.ts
index 2b5ee52773..c0d98e4395 100644
--- a/packages/js/src/index.ts
+++ b/packages/js/src/index.ts
@@ -16,37 +16,45 @@ const logger = Logger.getInstance();
logger.debug("Create command queue");
const queue = new CommandQueue();
-const init = (initConfig: InitConfig) => {
+const init = async (initConfig: InitConfig) => {
ErrorHandler.init(initConfig.errorHandler);
queue.add(false, initialize, initConfig);
+ await queue.wait();
};
-const setUserId = (userId: string): void => {
+const setUserId = async (userId: string): Promise => {
queue.add(true, setPersonUserId, userId);
+ await queue.wait();
};
-const setEmail = (email: string): void => {
+const setEmail = async (email: string): Promise => {
setAttribute("email", email);
+ await queue.wait();
};
-const setAttribute = (key: string, value: string): void => {
+const setAttribute = async (key: string, value: string): Promise => {
queue.add(true, setPersonAttribute, key, value);
+ await queue.wait();
};
-const logout = (): void => {
+const logout = async (): Promise => {
queue.add(true, resetPerson);
+ await queue.wait();
};
-const track = (eventName: string, properties: any = {}): void => {
+const track = async (eventName: string, properties: any = {}): Promise => {
queue.add(true, trackEvent, eventName, properties);
+ await queue.wait();
};
-const refresh = (): void => {
+const refresh = async (): Promise => {
queue.add(true, refreshSettings);
+ await queue.wait();
};
-const registerRouteChange = (): void => {
+const registerRouteChange = async (): Promise => {
queue.add(true, checkPageUrl);
+ await queue.wait();
};
const formbricks = {
diff --git a/packages/js/src/lib/commandQueue.ts b/packages/js/src/lib/commandQueue.ts
index e7354c4466..0c8f1cd632 100644
--- a/packages/js/src/lib/commandQueue.ts
+++ b/packages/js/src/lib/commandQueue.ts
@@ -8,6 +8,8 @@ export class CommandQueue {
commandArgs: any[];
}[] = [];
private running: boolean = false;
+ private resolvePromise: (() => void) | null = null;
+ private commandPromise: Promise | null = null;
public add(
checkInitialized: boolean = true,
@@ -17,7 +19,16 @@ export class CommandQueue {
this.queue.push({ command, checkInitialized, commandArgs: args });
if (!this.running) {
- this.run();
+ this.commandPromise = new Promise((resolve) => {
+ this.resolvePromise = resolve;
+ this.run();
+ });
+ }
+ }
+
+ public async wait() {
+ if (this.running) {
+ await this.commandPromise;
}
}
@@ -38,14 +49,13 @@ export class CommandQueue {
if (!result) continue;
- /* logger.debug(
- `Command result: ${result.ok === true ? "OK" : "Something went really wrong"}, ${
- currentItem.command.name
- }`
- ); */
-
if (result.ok !== true) errorHandler.handle(result.error);
}
this.running = false;
+ if (this.resolvePromise) {
+ this.resolvePromise();
+ this.resolvePromise = null;
+ this.commandPromise = null;
+ }
}
}