Skip to content

Commit

Permalink
chore: prints response headers from plausible
Browse files Browse the repository at this point in the history
  • Loading branch information
akoenig committed May 5, 2024
1 parent dbb2827 commit b41113a
Showing 1 changed file with 22 additions and 14 deletions.
36 changes: 22 additions & 14 deletions app/routes/$category.$id/route.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,21 +32,29 @@ export async function loader({ params, request }: LoaderFunctionArgs) {

const domain = baseUrl.host;

fetch("https://plausible.openformation.io/api/event", {
method: "POST",
headers: {
"User-Agent": request.headers.get("User-Agent") ?? "fetch",
"X-Forwarded-For": request.headers.get("X-Forwarded-For") ?? "",
"Content-Type": "application/json",
},
body: JSON.stringify({
name: "InstallScriptWasDownloaded",
domain,
url: request.url,
}),
}).catch((cause) => {
try {
const response = await fetch(
"https://plausible.openformation.io/api/event",
{
method: "POST",
headers: {
"User-Agent": request.headers.get("User-Agent") ?? "fetch",
"X-Forwarded-For": request.headers.get("X-Forwarded-For") ?? "",
"Content-Type": "application/json",
},
body: JSON.stringify({
name: "InstallScriptWasDownloaded",
domain,
url: request.url,
}),
},
);

console.log(response.status, await response.text());
console.log(response.headers.toJSON());
} catch (cause) {
console.error(`failed to send event to Plausible: ${cause}`);
});
}

const response = new Response(script, {
headers: {
Expand Down

0 comments on commit b41113a

Please sign in to comment.