@ensdomains/server-analytics
v0.0.1
Published
Backend analytics for ENS gateways
Downloads
20
Readme
Plausible Analytics Tracker
A lightweight tracker for integrating Plausible Analytics into your Cloudflare Workers or Express.js applications.
Install
npm i @ensdomains/server-analytics
# or yarn i @ensdomains/server-analytics
# or pnpm add @ensdomains/server-analytics
# or bun add @ensdomains/server-analytics
Features
- Track endpoint calls and custom events
- Support for Cloudflare Workers and Express.js
- Optional user details inclusion
- Customizable API endpoint
- Logging capabilities
- Data manipulation with custom decoders
Usage
import { Tracker } from './tracker';
const tracker = new Tracker('yourdomain.com', { enableLogging: true });
// track endpoint calls as pageview
await tracker.trackPageview(request);
// track custom events
await tracker.trackEvent(request, 'fetch_call', { props: { statusCode: 418 } });
// usecustom decoders to manipulate data before logging
const values = decodeAbiParameters(
parseAbiParameters('string x, uint y, bool z'),
'0x00000000...'
)
const customDecoder = (req, response) => {
return {
customField: values,
requestPath: req.url,
};
};
// log results with custom decoder
await tracker.logResult.bind(this, customDecoder, request);
License
MIT