Replies: 2 comments 1 reply
-
|
Appreciate you putting this RFC together, @stordahl. I’m a big fan of the concept—excited to see where it goes! |
Beta Was this translation helpful? Give feedback.
0 replies
-
|
Is it WIP somewhere? |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Summary
This RFC proposes adding custom event tracking capabilities to Counterscale while maintaining full backward compatibility with existing pageview tracking. The implementation leverages unused Cloudflare Analytics Engine columns to store custom event data without affecting existing functionality.
Motivation
Currently, Counterscale only supports pageview tracking. Many analytics use cases require tracking custom events like button clicks, form submissions, downloads, and other user interactions. This enhancement would enable comprehensive user behavior analytics while preserving the simplicity and performance of the existing system.
Related Issues:
Design
Schema Extensions
New column mappings will be added to
packages/server/app/analytics/schema.ts:API Interface
The
/collectendpoint will accept new optional query parameters:en- Event name (string)ec- Event category (string)ed- Event data (URL-encoded JSON string)Data Structure
The
DataPointinterface will be extended with optional custom event fields:Implementation Strategy
eventNameandeventCategoryeventDatafield for arbitrary event informationTracker Package Integration
Standard Schema Support
The tracker package will integrate with the Standard Schema specification to provide type-safe event registration and validation. Standard Schema is a common interface implemented by popular validation libraries like Zod, Valibot, ArkType, and Effect Schema.
The motivation for this integration is to provide a flexible mechanism to ensure user defined data structures are always sent to the server with the same structure. Since the current iteration of Counterscale relies on all users deploying the same server, it's difficult to add server-side validation for custom events/data structures. While all of that is true, I do think making schemas optional should be considered as to not hand-hold users of the tracker npm package. Having first-class support for all Standard Schemas should enable those that need to validate can do so easily, but we shouldn't force someone to adopt a schema validation library to define custom events.
Event Registration API
Following the existing Counterscale API patterns, custom events will be registered and tracked through module-level functions similar to
trackPageview:Usage Example
API Method Summary
registerEvent()+trackEvent()createEventTracker()Dashboard Integration
The dashboard will be extended with new routes and components to provide visualization and analysis of custom events while maintaining the existing user experience for pageview analytics.
Key features:
Considerations
Performance
Data Validation
Developer Experience
Future Extensions
Dependencies
The tracker package will depend on the Standard Schema specification for type-safe validation, which is compatible with major validation libraries including Zod, Valibot, ArkType, and Effect Schema.
Beta Was this translation helpful? Give feedback.
All reactions