How to send a Slack notification when there's a recording to watch
Contents
Sometimes it's important to watch recordings as soon as they are available. You can take advantage of a little custom code and our new Hog powered functions to receive a Slack notification every time there's a new recording.
Prerequisites
You'll need:
- PostHog Cloud or a self-hosted PostHog instance
- A little custom code when you start
posthog-js
- A destination sending to Slack
Data pipeline realtime destinations
We'll be using PostHog's data pipelines to react to events in realtime, sending messages to destinations like Slack, Airtable, and many more.
This enables us to send an event to PostHog from a user's browser when we detect a recording that we want to act on and have that converted to a message to a Slack channel.
A little custom code
When you start posthog-js
, we can add code once the library is loaded to watch for the condition that for your app means the recording is ready to watch.
Here we'll wait until a recording has been idle for 5 minutes, but you might wait for some time after starting or use the onCapture
hook to send a Slack message when a user experiences a $exception
event.
Now, for every session this instance of PostHog starts, whenever it first sees 5 minutes of inactivity, it sends an event with the session ID and URL for the recording.
A CDP destination
You can see how to setup a Slack destination in our docs here
In this case, we want to set the event trigger to the event emitted above:
- Set the event trigger to the event
session_idle_for_five_minutes
. - If you use our replay ingestion controls, not all sessions are recorded. You can add a filter for
session_recording_start_reason is set
to only react to sessions where recording is running.
Finally, you can change the templated message we send to Slack. Here we add a button to jump to the person or straight to the recording:
Subscribe to our newsletter
Product for Engineers
Read by 100,000+ founders and builders
We'll share your email with Substack