EventTrack
Documentation
Installation
npm install
/eventtrackUsage
SDK Usage
import { EventTrack } from '@wru/eventtrack'
const tracker = new EventTrack('your-api-key')
await tracker.log({
title: 'Event title',
})
Direct API requests
await fetch('https://eventtrack.dev/api/v1/events', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
Authorization: 'Bearer your-api-key',
},
body: JSON.stringify({
title: 'Event title',
}),
})
Schema
{
title: string().min(3),
category: string().min(3).optional(),
notify: boolean().optional(),
icon: hexColor().url().emoji().optional(),
fields: record(string(), any()).optional(),
groupBy: string().optional(),
actions: array(object({
url: string().url(),
label: string(),
}).optional(),
}
title
The title of the event. For example, „User registered“. Must be at least 3 characters long.
category (optional)
A thematic category for the event, e.g. „auth“ for logins or „transactions“ for purchases. Serves to better sort events.
notify (optional)
Indicates whether this event should trigger a notification (e.g. email message).
icon (optional)
A small symbol for the event. Can be either a color code (hex), an emoji, or a link to an image.
groupBy (optional)
Indicates the value by which events should be grouped. Either by the specified category (groupBy: „category“) or one of the fields in „fields“.
fields (optional)
Here additional information about the event can be stored, e.g. an order number, the price or the username. As the „value“ of a field, a JSON string can also be passed.
actions (optional)
A list of buttons (links) that can be displayed with the event. Each button has a text and a link (e.g. „Show invoice“ or „Open user profile“).
Examples
User registered
await tracker.log({
title: 'User registered',
category: 'auth',
fields: {
id: '12345',
email: 'tester@example.com',
},
groupBy: 'email',
})
Cronjob executed
await tracker.log({
title: 'Cronjob executed',
category: 'cron',
groupBy: 'category',
})
Order completed
await tracker.log({
title: 'Order completed',
category: 'transactions',
fields: {
orderId: '12345',
amount: 99.99,
currency: 'USD',
productId: '12345',
},
groupBy: 'productId',
})