Back

Version 38

5/26/2024
/** @jsxImportSource https://esm.sh/react */
import { extractValInfo } from "https://esm.town/v/pomdtr/extractValInfo?v=27";
import { sqlite } from "https://esm.town/v/std/sqlite?v=6";
import { renderToString } from "npm:react-dom/server";

const { name, httpEndpoint } = extractValInfo(import.meta.url);

// sqlite.batch([
// {
// sql: `CREATE TABLE IF NOT EXISTS ${name}_impression (
// id INTEGER PRIMARY KEY,
// timestamp TEXT NOT NULL DEFAULT (datetime('now')),
// val TEXT NOT NULL,
// event_name TEXT,
// meta TEXT
// );`,
// args: [],
// },
// ]);

export const initAnalytics = () => {
const urlOfRunningVal = (new Error()).stack.split("\n").at(-1).split(" ").at(-1).split(":").slice(0, 2).join(":");
const { author, name } = extractValInfo(urlOfRunningVal);

// Do not await the response
fetch(`${httpEndpoint}/track?author=${author}&name=${name}`);
};

export default async function(req: Request): Promise<Response> {
const url = new URL(req.url);
if (req.method === "GET" && url.pathname === "/pixel.png") {
console.log(req);
// dprint-ignore
const pngBytes = Uint8Array.from([
0x89, 0x50, 0x4E, 0x47, // PNG signature
0x0D, 0x0A, 0x1A, 0x0A,
maxm-valtownanalytics.web.val.run
Updated: May 30, 2024