npm.io
0.4.0 • Published 3 weeks ago

crowne

Licence
MIT
Version
0.4.0
Deps
0
Size
11 kB
Vulns
0
Weekly
0

crowne

Cookieless web analytics and custom events for every site you run, from crowne.io.

Read the full docs at crowne.io/docs.

Install

$ npm install crowne

Modules

crowne/browser

Size (gzip): 850 bytes

crowne/server

Size (gzip): 1.1 kB

Usage

Browser

Use crowne/browser when your app has a bundler. It counts a page view now, on each in-app navigation, and on each back/forward restore. See npm package.

import { crowne } from "crowne/browser";

let analytics = crowne("YOUR_SITE_ID");

analytics.track("signup", { plan: "pro" });
Server

Use crowne/server to count events from a Worker or Node, or to serve a first-party proxy. It needs a key with the events:write scope. Never send the key to a browser. See Server package. Outside Cloudflare Workers, set the ip option, as Visitor address shows.

import { env } from "cloudflare:workers";
import { crowne } from "crowne/server";

let analytics = crowne({ key: env.CROWNE_KEY, site: "YOUR_SITE_ID" });

export default {
  async fetch(request, env, ctx) {
    ctx.waitUntil(analytics.pageview(request));
    return new Response("Hello");
  },
};

No package fits? Use the script tag or call the REST API.

License

MIT crowne.io

Keywords