feat: Configurable filter and transform functions for TrackPayload#6
feat: Configurable filter and transform functions for TrackPayload#6christiankalinowski wants to merge 1 commit into
Conversation
📝 WalkthroughWalkthroughThis PR adds event filtering and payload transformation hooks to the Rybbit tracking configuration. The ChangesEvent Filter and Transform Configuration
Sequence Diagram(s)sequenceDiagram
participant Caller
participant track
participant filter
participant transform
participant Network
Caller->>track: track(event)
track->>track: buildPayload()
track->>filter: currentConfig.filter(payload)
alt filter returns false
filter-->>track: false
track-->>Caller: return (filtered)
else filter returns true
filter-->>track: true
track->>transform: currentConfig.transform(payload)
transform-->>track: transformedPayload
track->>Network: JSON.stringify(transformedPayload)
Network-->>Caller: sent
end
Estimated code review effort🎯 2 (Simple) | ⏱️ ~12 minutes Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Warning There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure. 🔧 ESLint
ESLint skipped: no ESLint configuration detected in root package.json. To enable, add Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@src/config.ts`:
- Around line 163-164: When building the config (where filter: options.filter ??
localDefaults.filter and transform: options.transform ?? localDefaults.transform
are set) validate that both filter and transform are functions before saving
them: if typeof options.filter === 'function' use it, else fall back to
localDefaults.filter only if it's a function (same for transform), otherwise set
the config value to undefined (or throw a clear error). Update the config
assembly logic that references filter and transform so the persisted config only
contains actual functions (use typeof ... === 'function' checks) to avoid
runtime TypeErrors when track() invokes filter() or transform().
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: d47c9d07-2091-42e0-a31b-792325977bbb
📒 Files selected for processing (5)
src/config.test.tssrc/config.tssrc/core.test.tssrc/core.tssrc/types.ts
| filter: options.filter ?? localDefaults.filter, | ||
| transform: options.transform ?? localDefaults.transform, |
There was a problem hiding this comment.
Validate filter/transform are functions before persisting config.
Truthy non-function values can be accepted here and then throw at runtime when invoked in track() (src/core.ts Line 109 and Line 114), dropping events.
Suggested fix
+ const validatedFilter =
+ typeof options.filter === "function" ? options.filter : localDefaults.filter;
+ const validatedTransform =
+ typeof options.transform === "function" ? options.transform : localDefaults.transform;
+
+ if (options.filter !== undefined && typeof options.filter !== "function") {
+ logError("`filter` must be a function. Falling back to default.");
+ }
+ if (options.transform !== undefined && typeof options.transform !== "function") {
+ logError("`transform` must be a function. Falling back to default.");
+ }
+
internalConfig = {
@@
- filter: options.filter ?? localDefaults.filter,
- transform: options.transform ?? localDefaults.transform,
+ filter: validatedFilter,
+ transform: validatedTransform,🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@src/config.ts` around lines 163 - 164, When building the config (where
filter: options.filter ?? localDefaults.filter and transform: options.transform
?? localDefaults.transform are set) validate that both filter and transform are
functions before saving them: if typeof options.filter === 'function' use it,
else fall back to localDefaults.filter only if it's a function (same for
transform), otherwise set the config value to undefined (or throw a clear
error). Update the config assembly logic that references filter and transform so
the persisted config only contains actual functions (use typeof ... ===
'function' checks) to avoid runtime TypeErrors when track() invokes filter() or
transform().
Added option to
RybbitConfigto allow defining optionalfilterandtransformfunctions. Those can be used to fine tune the payload before sending.Example use-cases for filter:
Example use-cases for transform:
utm_*)page_titleSummary by CodeRabbit
New Features
Tests