While building products, there are many times where you need to get notified of a json payload, env vars in production, webhook data, etc.
Unfortunately, most notification tools are designed for simple user-to-user tasks.
In comes Operational, a Event tracker tool. With this tool, pass json, structured json, image urls and more in your events and get notified in the webapp or on your mobile.
Let's get started.
Sending your first event
- Signup to Operational.co and get your API token
- Install the Operational SDK
import Operational from "@operational.co/sdk"
Then paste this code in your project. Replace the TOKEN with your API key.
const ops = new Operational("TOKEN");
await ops.events.ingest({
name : "User trial ended",
avatar : "π€"
});
That's it!
Taking it further
Now let's try sending a large javascript object to operational. This could be useful for getting notified of Stripe webhooks, 3rd party API webhooks, etc.
Run this code:
const webhookData = {
}
await ops.events.ingest({
name : "User signed up",
avatar : "π€",
type : "json",
content : {
user_name : "Shash",
email : "shash@operational",
id : 13760
}
});
Contextual events
Sometimes, it is helpful to chain events together.
This is super helpful for understanding complex workflows, cronjobs and other scenarios. This is what Operational calls contextual events.
Hereβs how you can setup contextual events:
/*
* Set a unique Id to chain events together.
* We will use this id for related events later
*/
const contextId = "user-12312-signup";
// First event
await ops.events.ingest({
name : "User signup",
avatar : "π€",
contextStart : true,
contextId : contextId,
actions : [
{
key : "Ban",
url: "https://xyz.com/webhook/ban",
}
]
});
// second event some time later
await ops.events.ingest({
name : "User activated",
avatar : "π",
contextId : contextId,
});
// third event
await ops.events.ingest({
name : "User created their project",
avatar : "π",
contextId : contextId,
content : "Project Operational created for user Shash"
});
As long as the contextId is same, all these events will show up in the βchainβ.
Conclusion
I hope this guide has been helpful for you. Let me know in the comments how you're using Operational to track events in your own backend!
Top comments (0)