Skip to content

📈 Open source, privacy-first web analytics — a cookie-less Google Analytics alternative with built-in error tracking and performance monitoring. Self-host it or use our cloud. Get started for free!

Added support for custom events

Blue Mouse272e02c14829
diff --git a/src/Lib.ts b/src/Lib.ts
index ed9cacd98..07ba3b234 100644
--- a/src/Lib.ts
+++ b/src/Lib.ts
@@ -25,11 +25,11 @@ export interface LibOptions {
}
export interface TrackEventOptions {
- // Unique ID for the event
- id: string
+ // The event name
+ ev: string
- // Parameters for the event, e.g. { ref: 'duckduckgo', plan: 'gold+' }
- params?: Map<string>
+ // If true, only 1 event with the same ID will be saved per user session
+ unique?: boolean
}
export interface PageData {
@@ -61,10 +61,9 @@ export class Lib {
const data = {
pid: this.projectID,
- ev: event.id,
- params: event.params,
+ ...event,
}
- this.submitData(data)
+ this.submitCustom(data)
}
// Tracks page views
@@ -106,7 +105,6 @@ export class Lib {
const data = {
pid: this.projectID,
- ev: 'pageviews',
lc: getLocale(),
tz: getTimezone(),
ref: getReferrer(),
@@ -158,4 +156,15 @@ export class Lib {
body: JSON.stringify(body),
})
}
+
+ private submitCustom(body: object) {
+ return fetch(`${host}/custom`, {
+ method: 'post',
+ headers: {
+ 'Accept': 'application/json',
+ 'Content-Type': 'application/json',
+ },
+ body: JSON.stringify(body),
+ })
+ }
}