SDK reference
Every method and option of the browser and Node clients, and the HTTP endpoints they use.
Setup is covered in Install the SDK. Every browser method is safe to call before init, during server-side rendering, or after opting out: it simply does nothing.
Browser
init options
datahop.init(token, options?)
Prop
Type
Methods
| Method | What it does |
|---|---|
capture(event, properties?) | Send an event. |
register(properties) · unregister(key) | Add a property to every later event · remove it. |
identify(id, $set?, $set_once?) | Link the visitor to your user id. See Identify users. |
setPersonProperties($set, $set_once?) | Update the current person's properties. |
reset() | Start over as a new anonymous visitor. Call it on logout. |
getDistinctId() · getSessionId() | The current ids. |
group(type, key, properties?) | Attach this user and every later event to a group. |
resetGroups() · getGroups() | Stop attaching groups · the current groups. |
getFeatureFlag(key, { sendEvent? }) | A flag's value. Records an exposure unless sendEvent: false. |
isFeatureEnabled(key, { sendEvent? }) | Whether a flag is on (or any variant). |
getFeatureFlagPayload(key) | The payload for the user's value. |
getAllFlags() | Every flag value. |
onFeatureFlags(callback) | Runs whenever flags load. Returns an unsubscribe function. |
reloadFeatureFlags() | Fetch flags again. |
overrideFeatureFlags(flags | false) | Force values locally for testing. false clears them. |
feedback({ message, rating?, category?, email?, url?, properties?, anonymous? }) | Send feedback. Resolves with its id. See Feedback. |
optOut() · optIn() · hasOptedOut() | Stop or resume capturing for this browser. |
flush() | Send everything queued now. |
shutdown() | Flush and stop this instance (tests, hot reload). |
For a second project on the same page, create another instance: new Datahop().init('dh_other_token', { … }).
Node / Bun
new Datahop({ token, host, … })
Prop
Type
| Method | What it does |
|---|---|
capture({ distinctId, event, properties?, groups?, $set?, $set_once?, timestamp?, uuid? }) | Send an event. timestamp for imports, uuid to make re-sends safe. |
identify({ distinctId, anonDistinctId?, properties?, $set_once? }) | Set person properties, and optionally link a browser's anonymous id. |
setPersonProperties({ distinctId, $set, $set_once? }) | Update person properties. |
groupIdentify({ groupType, groupKey, properties? }) | Create or update a group. |
getFeatureFlag({ distinctId, key, groups?, personProperties?, groupProperties?, sendEvent? }) | A flag's value. Records an exposure unless sendEvent: false. |
isFeatureEnabled(…) · getFeatureFlagPayload(…) | Same inputs as getFeatureFlag. |
getAllFlags({ distinctId, groups?, … }) | Every flag value. |
feedback({ message, distinctId?, rating?, category?, groups?, … }) | Send feedback right away. Resolves with its id. |
flush() · shutdown() | Send what's queued · send and stop. Await one before the process exits. |
pending, sent and dropped count events, which is handy in import scripts.
HTTP endpoints
All three use your public project token and work from any website.
POST /i/batch
Send up to 500 events.
Prop
Type
Each event:
Prop
Type
Returns { "ok": true, "accepted": n }. A 400 means the payload is invalid and the whole batch was rejected. A 401 means the token is wrong. Retry 429, 5xx and network errors. The body can be up to 5 MB.
Special events work as they do in the SDKs:
$identifywithproperties.$anon_distinct_idlinks an anonymous id todistinct_id.$groupidentifywith$group_type,$group_keyand$group_setcreates or updates a group.$feature_flag_calledwith$feature_flagand$feature_flag_responserecords a flag exposure.
POST /i/flags
{ "token": "dh_…", "distinct_id": "user_123", "groups": { "company": "acme" }, "person_properties": { "plan": "pro" } }Returns { "flags": { "new-checkout": "test", "dark-mode": true }, "payloads": {} } with every flag that's on. groups is needed for flags that match by company. person_properties and group_properties add to the stored properties for this check only. This doesn't record exposures.
POST /i/feedback
{ "token": "dh_…", "message": "Love the new dashboard", "distinct_id": "user_123", "rating": 5, "category": "praise" }Returns { "ok": true, "id": "…" }. All fields are on the Feedback page.