Typescript
The Raindrop SDK allows you to track user events and AI interactions in your app. This documentation provides a brief overview of how to use the Typescript SDK.
Installation
Install with your package manager of choice:
Quick-start: the Interaction API
The new interaction workflow is a three-step pattern:
begin()
- creates an interaction object and logs the initial user input.- Update - optionally call
setProperty
,setProperties
, oraddAttachments
. finish()
- records the AI’s final output and closes the interaction.
Example: chat completion with the ai
SDK
Updating an interaction
You can update an interaction at any time using setProperty
, setProperties
, or addAttachments
.
Resuming an interaction
If you don’t have access to the interaction object that was returned from begin()
, you can resume an interaction by calling resumeInteraction()
.
Interactions are subject to the global 1 MB event limit; oversized payloads will be truncated.
Single-shot tracking (legacy trackAi
)
If your interaction is atomic (e.g. “user asked, model answered” in one function) you can still call trackAi()
directly:
Heads‑up: We recommend migrating to
begin()
→finish()
for all new code so you gain partial‑event buffering, tracing helpers, and upcoming features such as automatic token counts.
Tracking Signals (feedback)
Signals capture explicit or implicit quality ratings on an earlier AI event. Use trackSignal()
with the same eventId
you used in begin()
or trackAi()
.
Parameter | Type | Description |
---|---|---|
eventId | string | The ID of the AI event you’re evaluating |
name | "thumbs_up" | "thumbs_down" | string | Name of the signal (e.g. "thumbs_up" ) |
type | "default" | "feedback" | "edit" | Optional, defaults to "default" |
comment | string | For feedback signals |
after | string | For edit signals – the user’s final content |
…others | See API reference |
Attachments
Attachments allow you to include context from the user or that hte model outputted. These could be documents, generated images, code, or even an entire web page. They work the same way in begin()
interactions and in single‑shot trackAi
calls.
Each attachment is an object with the following properties:
-
type
(string): The type of attachment. Can be “code”, “text”, “image”, or “iframe”. -
name
(optional string): A name for the attachment. -
value
(string): The content or URL of the attachment. -
role
(string): Either “input” or “output”, indicating whether the attachment is part of the user input or AI output. -
language
(optional string): For code attachments, specifies the programming language.
Supported types: code
, text
, image
, iframe
.
Identifying users
PII redaction
Read more on how Raindrop handles privacy and PII redaction here. You can enable client-side PII redaction when intializing the Analytics
class like so:
Error Handling
If an error occurs while sending events to Raindrop, an exception will be raised. Make sure to handle exceptions appropriately in your application.
Configuration & helpers
- Debug logs –
debugLogs: true
prints every queued event. - Closing – call
await raindrop.close()
before your process exits to flush buffers.
That’s it! You’re ready to explore your events in the Raindrop dashboard. Ping us on Slack or email us if you get stuck!