generated from digitalservicebund/remix-application-template
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Reapply "Add plausible error handling"
This reverts commit a11e63a.
- Loading branch information
1 parent
a11e63a
commit fa5162c
Showing
4 changed files
with
26 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,28 @@ | ||
const plausibleUrl = "https://plausible.io/api/event"; | ||
const plausibleDomain = "digitalcheck-dito.prod.ds4g.net"; | ||
|
||
export default function trackCustomEvent( | ||
export default async function trackCustomEvent( | ||
request: Request, | ||
event: { name: string; props?: Record<string, string> }, | ||
) { | ||
if (process.env.NODE_ENV === "development") { | ||
console.log("TRACKING", event); | ||
return; | ||
} | ||
void fetch(plausibleUrl, { | ||
method: "POST", | ||
body: JSON.stringify({ | ||
domain: plausibleDomain, | ||
url: request.url, | ||
referrer: request.referrer, | ||
...event, | ||
}), | ||
}); | ||
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); | ||
} | ||
} |