Skip to content

Commit

Permalink
Add telemetry to standalone example
Browse files Browse the repository at this point in the history
  • Loading branch information
willcrichton committed Sep 4, 2024
1 parent e7c59a8 commit b9e9be6
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 4 deletions.
8 changes: 4 additions & 4 deletions example/standalone/pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions example/standalone/src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import React from "react";
import ReactDOM from "react-dom/client";

import quizStr from "./quiz-example.toml?raw";
import "./telemetry";

let App = () => {
let quiz = TOML.parse(quizStr) as any as Quiz;
Expand Down
23 changes: 23 additions & 0 deletions example/standalone/src/telemetry.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
const BASE_URL = "http://localhost:8888";

class Telemetry {
async log(endpoint: string, payload: object) {
let url = `${BASE_URL}/${endpoint}`;

let response = await fetch(url, {
method: "POST",
headers: {
"Content-Type": "application/json"
},
body: JSON.stringify(payload)
});

if (!response.ok) {
throw new Error(`Failed to log with status: ${response.statusText} `);
}
}
}

if (typeof window !== "undefined") {
window.telemetry = new Telemetry();
}

0 comments on commit b9e9be6

Please sign in to comment.