Contents
The Manual
Integrations
Self hosting
Other
Nodejs SDK
Installation
Use npm to install Operational’s nodejs SDK. Run this inside your project:
npm install --save-exact @operational.co/sdk
Initialize SDK
Pass your API key to the constructor:
import Operational from "@operational.co/sdk"
// Or use this if you're on a older version of nodejs
// const Operational = require('@operational.co/sdk')
const apikey = ''; // <-- Enter your api key here
const ops = new Operational(apikey);
Constructor options
You can pass baseUrl, test, and debug as constructor options.
import Operational from "@operational.co/sdk";
const ops = new Operational("API_KEY", {
baseUrl: "https://api.operational.co", // optional
test: false, // optional, when true events are sent as test events
debug: true, // optional, logs SDK errors to console
});
events.ingest(event)
This is the main SDK function for sending events.
import Operational from "@operational.co/sdk";
const ops = new Operational("API_KEY");
await ops.events.ingest({
name: "user signed up",
avatar: "✅",
category: "auth",
content: "New signup from landing page",
});
You can also send structured rows:
await ops.events.ingest({
name: "payment failed",
type: "rows",
category: "billing",
content: [
{ label: "Invoice", content: "inv_2044" },
{ label: "Amount", content: "$39.00" },
{ label: "Reason", content: "card_declined" },
],
});
Complete example
import Operational from "@operational.co/sdk";
const ops = new Operational("API_KEY", {
debug: true,
});
await ops.events.ingest({
name: "server started",
category: "server",
content: "api-west-2 booted",
});
Related docs
For self hosters
Pass your backend’s url when initiating the Operational class.
const ops = new Operational(apikey, {
baseUrl : 'https://xzy.abc.com' // <- Enter your backend's url here.
})
You can find this url inside your self hosted instance’s profile page under your api key.