Skip to content

Commit

Permalink
Revert "Add plausible error handling"
Browse files Browse the repository at this point in the history
This reverts commit 4e8841f.
  • Loading branch information
HendrikSchmidt committed Jul 12, 2024
1 parent 1413565 commit a11e63a
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 26 deletions.
2 changes: 1 addition & 1 deletion packages/dito/app/routes/download.$fileName.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export async function loader({ params, request }: LoaderFunctionArgs) {
const filePath = path.join("public", "assets", fileName);
const pdfData = await fs.readFile(filePath);

void trackCustomEvent(request, { name: "Download Dokumentation" });
trackCustomEvent(request, { name: "Download Dokumentation" });
return new Response(pdfData, {
status: 200,
headers: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -152,10 +152,7 @@ export async function action({ params, request }: ActionFunctionArgs) {
} else if (Object.values(answers).find((a) => a === "unsure")) {
result = "Unsicher";
}
void trackCustomEvent(request, {
name: "Download Vorprüfung",
props: { result },
});
trackCustomEvent(request, { name: "Download Vorprüfung", props: { result } });

return new Response(pdfData, {
status: 200,
Expand Down
5 changes: 1 addition & 4 deletions packages/dito/app/routes/vorpruefung.ergebnis/route.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,7 @@ export async function loader({ request }: LoaderFunctionArgs) {
} else if (unsureQuestions.length > 0) {
result = "Unsicher";
}
void trackCustomEvent(request, {
name: "Vorprüfung Resultat",
props: { result },
});
trackCustomEvent(request, { name: "Vorprüfung Resultat", props: { result } });

return json({ positiveQuestions, unsureQuestions, negativeQuestions });
}
Expand Down
27 changes: 10 additions & 17 deletions packages/dito/app/utils/trackCustomEvent.ts
Original file line number Diff line number Diff line change
@@ -1,28 +1,21 @@
const plausibleUrl = "https://plausible.io/api/event";
const plausibleDomain = "digitalcheck-dito.prod.ds4g.net";

export default async function trackCustomEvent(
export default function trackCustomEvent(
request: Request,
event: { name: string; props?: Record<string, string> },
) {
if (process.env.NODE_ENV === "development") {
console.log("TRACKING", event);
return;
}
try {
const response = await fetch(plausibleUrl, {
method: "POST",
body: JSON.stringify({
domain: plausibleDomain,
url: request.url,
referrer: request.referrer,
...event,
}),
});
if (!response.ok) {
throw new Error(`Error tracking event: ${response.status}`);
}
} catch (error) {
console.error("Error tracking event", event, error);
}
void fetch(plausibleUrl, {
method: "POST",
body: JSON.stringify({
domain: plausibleDomain,
url: request.url,
referrer: request.referrer,
...event,
}),
});
}

0 comments on commit a11e63a

Please sign in to comment.