Node.js
The log-style POST /api/v1/server/events is a different endpoint, and this class does not call it. See Server events.
Install
The source is packages/sdk-server/node/src/index.ts, in-repo package name @webcount/node. package.json marks it private, so there is no public install command: copy the file into the service, or depend on it from the workspace. It needs the global fetch in Node.js 18.
Initialize
import { WebCount } from '@webcount/node';
const wc = new WebCount({
apiKey: 'wck_…',
endpoint: 'https://YOUR_ORIGIN',
});endpoint is the origin only, with no path; the class appends /api/v1/track. The key is shown once, at creation. Keep at most its prefix in docs and logs.
Pageviews
This class does not send pageviews. The website script still does. See JavaScript (w.js).
Events
await wc.track('purchase', { loginId: 'USER_ID', insertId: 'order-1', properties: { revenue: 19.9 } });By default it flushes every 3 seconds or at 200 events. Call flush or close before the process exits, or events still in memory are dropped. Set consumer to 'sync' in the constructor to send each event immediately. debug(true) adds debug=1 and validates without storing. insertId is at most 36 characters and stops retries from double-counting. Correct a stored event with trackUpdate or trackOverwrite; manage items with itemSet and itemDelete.
Identity
await wc.trackSignup('USER_ID', 'custom:device-id');
await wc.profileSet('USER_ID', { plan: 'pro' });There are also bind, unbind, profileSetOnce, profileIncrement, profileAppend, and profileUnset. Email and mobile values passed to bind are SHA-256 hashed first. Field rules are in SDK overview.
Limits
| Item | Default | What it means |
|---|---|---|
| Batch | 200 events | Change with maxBatch. The endpoint allows at most 1000 |
| Interval | 3 seconds | Change with flushIntervalMs |
| Key | Required | Header Authorization: Bearer, then the wck_ key |
Errors
Any failed status except 429 throws WebCount track plus the status code. 429 does not throw, and that batch has already left the queue, so it is not resent. A missing key returns 401 NO_API_KEY. An invalid key, or a key without track:write, returns 401 BAD_API_KEY. A bad body returns 400. If endpoint already includes a path, the client appends /api/v1/track again and the result is 404. After a success response, confirm the event is stored in the event list. See Server events & log import.
PHP
It needs PHP 8 and the curl extension. The log endpoint POST /api/v1/server/events is not called by this class. See Server events.
Install
The source is packages/sdk-server/php/src/WebCount.php, namespace Webcount. The directory has no Composer manifest. Place the file where the autoloader can find it.
Initialize
$wc = new \Webcount\WebCount('wck_…', 'https://YOUR_ORIGIN');The second argument is the origin only; the class appends /api/v1/track. Do not write the full key, and keep it out of the repository.
Pageviews
This class does not send pageviews. Use the website script. See JavaScript (w.js).
Events
$wc->track('purchase', [
'loginId' => 'USER_ID',
'insertId' => 'order-1',
'properties' => ['revenue' => 19.9],
]);track sends that one event immediately. There is no client batch queue, and flush and close are empty methods. Pass properties as an associative array, not as an already encoded JSON string.
Always pass insertId
Without insertId the source sends "insert_id": null, which fails validation with 400 VALIDATION, and the event is not stored. Use the same insertId for the same order so notification retries do not count twice.
Identity
$wc->trackSignup('USER_ID', 'custom:device-id', ['source' => 'web']);
$wc->profileSet('USER_ID', ['plan' => 'pro']);Do not pass an empty array as properties to trackSignup or profileSet: PHP encodes it as a JSON array and the endpoint returns 400. Field rules are in SDK overview.
Limits
| Item | This file | What it means |
|---|---|---|
| Each request | 1 event | There is no client batch queue |
| Timeout | 8 seconds | The curl timeout is fixed in the source |
| Key | Bearer | The header is Authorization: Bearer plus the wck_ key |
Errors
This file does not check the status code. It returns the decoded body, or null when curl fails. You have to read accepted and the error code yourself for 401 NO_API_KEY or BAD_API_KEY and 400 validation failures; no exception does not mean the event was accepted. An address that already has a path still gets /api/v1/track appended. See Server events & log import.
Python
It uses only the standard library and fits Python 3.7 or newer. The log endpoint POST /api/v1/server/events is not called by this class. See Server events.
Install
The source is packages/sdk-server/python/webcount/__init__.py. The directory has no package manifest. Put the webcount directory where PYTHONPATH can import it. An import failure usually means the directory is not on the module search path.
Initialize
from webcount import WebCount
wc = WebCount("wck_…", "https://YOUR_ORIGIN")endpoint is the origin only; the class appends /api/v1/track. Do not write the full key, and keep it out of logs and exception text.
Pageviews
This class does not send pageviews. The website script does. See JavaScript (w.js).
Events
wc.track("purchase", login_id="USER_ID", insert_id="order-1", properties={"revenue": 19.9})Each track sends one event immediately. There is no batch queue, and flush and close are empty methods. Use login_id or loginId, and insert_id or insertId.
Always pass insert_id
Without insert_id the source sends "insert_id": null, which fails validation with 400, and the event is not stored. Use the same insert_id for the same business record, and keep it when you retry after a timeout.
Identity
wc.track_signup("USER_ID", "custom:device-id")
wc.profile_set("USER_ID", {"plan": "pro"})Field rules are in SDK overview.
Limits
| Item | This file | What it means |
|---|---|---|
| Each request | 1 event | There is no batch queue |
| Timeout | 8 seconds | Set on the urlopen call |
| Key | Bearer | The Authorization header carries the wck_ key |
Errors
When the status means failure, the standard library raises HTTPError. Catch it and record the status code. 401 means the key is missing or invalid. 400 means the body does not match the field rules. After a success response, confirm the event is stored in the event list. See Server events & log import.
Java
It uses the Java 11 HttpClient. The log endpoint POST /api/v1/server/events is not in this class. See Server events.
Install
The source is packages/sdk-server/java/src/main/java/com/webcount/WebCount.java. The directory has no Maven or Gradle project. Drop that one source file into the com.webcount package of the project.
Initialize
WebCount wc = new WebCount("wck_…", "https://YOUR_ORIGIN");The address is the origin only; the class appends /api/v1/track. Do not write the full key, and keep it out of the source repository.
Pageviews
This class does not send pageviews. See JavaScript (w.js).
Events
wc.track("purchase", "{\"revenue\":19.9}");The properties argument should be JSON object text. null becomes an empty object. Each call sends immediately, with platform fixed to server. The event name is spliced into the JSON as is, so it must not contain quotes or newlines.
Identity
This class has no login method and no login_id or insert_id parameter. When you need a login id or an idempotency key, use the Node.js or Go source, or build the request from the fields in SDK overview.
Limits
| Item | This file | What it means |
|---|---|---|
| Methods | track only | No signup, profile, or batch method |
| Timeout | 8 second connect | Set on the HttpClient; there is no separate read timeout |
| Key | Bearer | The Authorization header carries the wck_ key |
Errors
Network failure throws a checked exception. The class returns the body as a string and does not interpret 401 or 400. Read the accepted count and NO_API_KEY, BAD_API_KEY, or VALIDATION in that text yourself. If the properties argument is not valid JSON object text, the whole body is malformed. Without insert_id, a retry can create a duplicate event. See Server events & log import.
Go
It needs Go 1.18. The log endpoint POST /api/v1/server/events is not called by this file. See Server events.
Install
The source is packages/sdk-server/go/webcount.go. The directory has no go.mod. Put the file in your own module and keep the package name webcount.
Initialize
c := webcount.New("wck_…", "https://YOUR_ORIGIN")The address is the origin only; the function appends /api/v1/track. Keep the key in configuration, do not write it in full, and keep it out of the repository.
Pageviews
This file does not send pageviews. See JavaScript (w.js).
Events
err := c.Track("purchase", map[string]any{
"insert_id": "order-1",
"properties": map[string]any{"revenue": 19.9},
})Track sets type and event in the map you pass, then sends that one event immediately. The map keys are the endpoint fields in SDK overview. When context is absent, the source writes platform server and library name webcount-go; an existing context is kept as is.
Identity
There is no separate login method. Put the login id in the Track map as login_id. Omitting login_id or insert_id is not a compile error.
Limits
| Item | This file | What it means |
|---|---|---|
| Each request | 1 event | There is no batch queue |
| Timeout | 8 seconds | Set on the default HTTP client |
| Key | Bearer | The Authorization header carries the wck_ key |
Errors
A status of 300 or above returns an error whose text is webcount track plus the status. Network errors are returned as they are. Both 401 and 400 take that path, and the body is not parsed into an error code. A nil return only means the status was below 300; still confirm the event is stored in the event list. See Server events & log import.