Skip to content

Commit

Permalink
chore: add GA events for the validation result
Browse files Browse the repository at this point in the history
  • Loading branch information
JeelRajodiya committed Aug 23, 2024
1 parent 57edce3 commit 1284764
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions lib/client-functions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
import { OutputReducerAction } from "./reducers";
import { CodeFile, TestCaseResult } from "./types";
import { hyperjumpCheckAnnotations, hyperjumpValidate } from "./validators";
import { sendGAEvent } from "@next/third-parties/google";

export async function validateCode(
codeString: string,
Expand Down Expand Up @@ -58,6 +59,9 @@ export async function validateCode(
if (validationStatus === "valid") {
dispatchOutput({ type: "valid", payload: {} });
completeStep(chapterIndex, stepIndex);
sendGAEvent("event", "validation", {
validation_result: "passed",
});
} else {
const sortedResults = testCaseResults.sort((a, b) => {
if (a.passed === b.passed) {
Expand All @@ -69,18 +73,27 @@ export async function validateCode(
type: "invalid",
payload: { testCaseResults: sortedResults, totalTestCases },
});
sendGAEvent("event", "validation", {
validation_result: "failed",
});
}
} catch (e) {
if ((e as Error).message === "Invalid Schema") {
dispatchOutput({
type: "invalidSchema",
payload: { errors: e as InvalidSchemaError },
});
sendGAEvent("event", "validation", {
validation_result: "failed - invalid schema",
});
} else {
dispatchOutput({
type: "syntaxError",
payload: { errors: (e as Error).message },
});
sendGAEvent("event", "validation", {
validation_result: "failed - syntax error",
});
}
}
}
Expand Down

0 comments on commit 1284764

Please sign in to comment.