Skip to content

Add standalone event publisher - #537

Merged
marcospassos merged 3 commits into
masterfrom
feature/event-publisher
Oct 14, 2026
Merged

marcospassos merged 3 commits into
masterfrom
feature/event-publisher

Conversation

@marcospassos

Copy link
Copy Markdown
Member

Adds EventPublisher, a stateless client for the track endpoint, like Evaluator and ContentFetcher. It lets events be tracked outside the browser, e.g. from a server.

await publisher.publish({
    type: 'goalCompleted',
    payload: {goalId: 'signup'},
    clientId,
    timestamp,
    context: {tabId, url},
});
  • The payload is sent as given, in the format the tracking API expects. The publisher doesn't transform it or fill anything in.
  • HttpBeaconChannel now sends through the publisher, so there's a single implementation of the track request.
  • Internal container option trackerEndpointUrl → trackerBaseEndpointUrl. The public SDK config is unchanged.
  • TrackingErrorType is deprecated in favor of PublishErrorType.

Small behavior changes in the browser channel:

  • It now sends mode: 'cors' and credentials: 'omit', like the other clients.
  • The 202 (tracking suspended) warning uses the shared help text.

@pkg-pr-new

pkg-pr-new Bot commented Oct 13, 2026 •

Copy link
Copy Markdown

Open in StackBlitz

npm i https://pkg.pr.new/@croct/sdk@537

commit: 9ca5cab

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔵 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 EventPublisher with PublishError/PublishErrorType, timeout handling, and browser-aware mode/credentials behavior.
  • Refactor HttpBeaconChannel to publish through EventPublisher; deprecate TrackingErrorType in favor of PublishErrorType, and use shared help text for the 202 (suspended) warning.
  • Rename container/SDK option trackerEndpointUrl → trackerBaseEndpointUrl and derive the /client/web/track path 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.

Comment thread src/eventPublisher.ts Outdated
Comment on lines +177 to +178
// Tracking is suspended, but the event was accepted
this.logger.warn(Help.forStatusCode(202));

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If tracking is suspended the payload event is not even read. So it does not mean it was or would be accepted.

@marcospassos
marcospassos merged commit ff7afae into master Oct 14, 2026
8 checks passed
@marcospassos
marcospassos deleted the feature/event-publisher branch October 14, 2026 17:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

feature New feature

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants