Skip to content

Add standalone track function - #388

Merged
marcospassos merged 4 commits into
masterfrom
feature/track-api
Oct 14, 2026
Merged

marcospassos merged 4 commits into
masterfrom
feature/track-api

Conversation

@marcospassos

@marcospassos marcospassos commented Oct 13, 2026 •

Copy link
Copy Markdown
Member

Adds track() to @croct/plug/api, next to evaluate and fetchContent, for tracking events outside the browser, e.g. from a server.

await track(
  {
    type: 'goalCompleted',
    clientId,
    timestamp,
    context: {tabId, url},
    payload: {goalId: 'signup'},
  },
  {apiKey: apiKey},
);

It's a thin wrapper around the SDK's new EventPublisher (croct-tech/sdk-js#537). The event is sent as given, except that userId is renamed to the API's externalUserId for sign-in/out/up events.

Depends on croct-tech/sdk-js#537.

@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/plug@388

commit: a3de604

@marcospassos marcospassos added the feature New feature label Oct 13, 2026
Comment thread src/api/track.ts
const {apiKey, appId, baseEndpointUrl, logger, ...publishOptions} = options;
const auth: AuthOptions = apiKey !== undefined ? {apiKey: apiKey} : {appId: appId};

const publisher = new EventPublisher({

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.

Should we pass logger to EventPublisher here? Publisher logs a warning on HTTP 202 - tracking suspended. We're missing it here

Comment thread package.json Outdated
"@croct/content": "^1.1.0",
"@croct/json": "^2.1.0",
"@croct/sdk": "^0.22.4",
"@croct/sdk": "https://pkg.pr.new/@croct/sdk@537",

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.

reminder to bump this

@marcospassos
marcospassos merged commit 1bcb837 into master Oct 14, 2026
11 checks passed
@marcospassos
marcospassos deleted the feature/track-api branch October 14, 2026 17:22
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.

4 participants