Repository navigation
Add standalone event publisher - #537
Conversation
commit: |
There was a problem hiding this comment.
🔵 Needs a closer look
It refactors the core beacon-delivery path and adds a new public client with behavior changes (mode/credentials, delegated logging), which warrants final human review despite the comprehensive tests and no issues found.
0 open findings
What changed in this PR
This PR introduces EventPublisher, a new stateless client that sends a single tracking event directly to the track endpoint, mirroring the existing Evaluator/ContentFetcher clients. It also refactors HttpBeaconChannel to delegate the actual track request to this publisher, eliminating the duplicated fetch/track implementation, and renames the internal container option trackerEndpointUrl to the base-URL form trackerBaseEndpointUrl (the public SDK config is unchanged). The publisher forwards the event payload verbatim in the API's expected shape and supports app-ID or API-key credentials, timeouts, optional client metadata, and extra fetch options.
Changes:
- Add
EventPublisherwithPublishError/PublishErrorType, timeout handling, and browser-awaremode/credentialsbehavior. - Refactor
HttpBeaconChannelto publish throughEventPublisher; deprecateTrackingErrorTypein favor ofPublishErrorType, and use shared help text for the 202 (suspended) warning. - Rename container/SDK option
trackerEndpointUrl→trackerBaseEndpointUrland derive the/client/web/trackpath inside the publisher.
| File | Description |
|---|---|
| src/eventPublisher.ts | New standalone publisher client for the track endpoint, modeled on Evaluator. |
| src/channel/httpBeaconChannel.ts | Delegates track requests to EventPublisher; deprecates TrackingErrorType; reuses shared help text. |
| src/container.ts | Wires a per-channel EventPublisher and switches to trackerBaseEndpointUrl. |
| src/sdk.ts | Passes trackerBaseEndpointUrl (base URL) instead of the full track URL. |
| test/eventPublisher.test.ts | Comprehensive unit tests for the new publisher. |
| test/eventPublisher.server.test.ts | Verifies mode is unset in a Node environment. |
| test/channel/httpBeaconChannel.test.ts | Updates channel tests to construct via a publisher and covers new paths. |
| test/container.test.ts | Updates expectations for the renamed base-URL option. |
🧠 Review effort: Balanced
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
| // Tracking is suspended, but the event was accepted | ||
| this.logger.warn(Help.forStatusCode(202)); |
There was a problem hiding this comment.
If tracking is suspended the payload event is not even read. So it does not mean it was or would be accepted.
Adds
EventPublisher, a stateless client for the track endpoint, likeEvaluatorandContentFetcher. It lets events be tracked outside the browser, e.g. from a server.HttpBeaconChannelnow sends through the publisher, so there's a single implementation of the track request.trackerEndpointUrl→trackerBaseEndpointUrl. The public SDK config is unchanged.TrackingErrorTypeis deprecated in favor ofPublishErrorType.Small behavior changes in the browser channel:
mode: 'cors'andcredentials: 'omit', like the other clients.