Skip to content

feat: add trackEvent for custom pipeline events#384

Open
talissoncosta wants to merge 6 commits intofeat/send-evaluation-data-to-analytics-pipelinefrom
feat/track-event-custom-pipeline
Open

feat: add trackEvent for custom pipeline events#384
talissoncosta wants to merge 6 commits intofeat/send-evaluation-data-to-analytics-pipelinefrom
feat/track-event-custom-pipeline

Conversation

@talissoncosta
Copy link
Contributor

@talissoncosta talissoncosta commented Mar 17, 2026

Summary

  • Add trackEvent(eventName, metadata?) public method to send custom events through the evaluation analytics pipeline (v1/analytics/batch)
  • Events tracked before identify() are buffered and drained once identity is set, preserving original timestamps
  • Pipeline-only: requires evaluationAnalyticsConfig; no-op otherwise. Pending events are cleared on logout()
  • Add PipelineEventType enum (FLAG_EVALUATION, CUSTOM_EVENT) to replace magic strings, exported from index.ts for consumer access
  • Uses Record<string, unknown> instead of Record<string, any> for metadata, enforcing type narrowing on consumers

Test plan

  • Unit tests (10 new): correct event shape, no-op guards (no config, empty name), queue-before-identify, flush on flushInterval === 0, no deduplication, timestamp preservation, logout cleanup, maxBuffer cap, identify → logout → buffer cycle
  • All 86 tests pass (no regressions)
  • Manual E2E validation with Angular playground app + local echo server

talissoncosta and others added 6 commits March 17, 2026 13:46
Add trackEvent(eventName, metadata?) to the public type definitions,
allowing custom events to be sent through the evaluation analytics pipeline.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Add trackEvent method that sends custom_event through the analytics
pipeline batch endpoint. Events tracked before identify() are buffered
in pendingCustomEvents and drained once identity is set, preserving
original timestamps. Pending events are cleared on logout.

Includes helper methods (getPageUrl, currentTraitsSnapshot, sdkMetadata,
buildCustomEvent) to keep the implementation clean.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Cover custom event shape, no-op without config, no-op with empty name,
queue-before-identify with drain, immediate flush when flushInterval is 0,
no deduplication, timestamp preservation, cleanup on logout, and pending
buffer maxBuffer cap.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
… trackEvent

Use the stricter Record<string, unknown> for user-provided metadata,
which forces consumers to narrow values before using them.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Replace string literals 'flag_evaluation' and 'custom_event' with
PipelineEventType.FLAG_EVALUATION and PipelineEventType.CUSTOM_EVENT
to avoid magic strings and ensure type safety.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
- Replace 'custom_event' string literals with PipelineEventType.CUSTOM_EVENT
  in test assertions and helpers
- Export PipelineEventType from index.ts for consumer access
- Add test for identify → logout → track cycle to verify state resets

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@talissoncosta talissoncosta marked this pull request as ready for review March 17, 2026 20:35
@talissoncosta talissoncosta requested a review from a team as a code owner March 17, 2026 20:35
@talissoncosta talissoncosta requested review from kyle-ssg and removed request for a team March 17, 2026 20:35
@talissoncosta talissoncosta linked an issue Mar 19, 2026 that may be closed by this pull request
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Track evaluation analytics custom events

1 participant