Readme

Plausible analytics

Call track with the domain you set up in plausible and the request.

I've been using saolsen.val-name. Note that there is no auth for the plausible events API, so if somebody forks the val it'll still work but track all their val page loads in your dashboard which is kinda weird but also kinda cool, idk.

See https://www.val.town/v/saolsen/plausible_example for how to use.

CleanShot 2023-12-27 at 11.20.13@2x.png

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
export async function track(domain: string, req: Request) {
await fetch("https://plausible.io/api/event", {
method: "POST",
headers: {
"User-Agent": req.headers.get("user-agent")!,
"X-Forwarded-For": req.headers.get("true-client-ip")!,
"Content-Type": "application/json",
},
body: JSON.stringify({
name: "pageview",
url: req.url,
domain: domain,
// Note, different spelling between the header val.town sets
// and the one we send to plausible.
referrer: req.headers.get("referer"),
}),
});
}
👆 This is a val. Vals are TypeScript snippets of code, written in the browser and run on our servers. Create scheduled functions, email yourself, and persist small pieces of data — all from the browser.