Rails Guide: Stream Segment Events into Slack
Because your team needs help engaging customers


Today, so many teams rely on Slack. It’s a chat-like communication tool that enables teams to work together to solve tough problems. Even NASA uses it to “put robots on Mars”.
That’s why our team at Knowtify decided to build a tool called Relay on top of the Slack platform. Relay helps find important activity inside your app and share the details with your Slack team. Here is an example of Relay in action.


Sound good? Let’s get started!
You’ll need:
- A Rails app
- A Segment account (signup here)
- A Relay account (signup here)
- 15 Minutes


Step 1: Install the analytics-ruby gem
Adding the above info gives you everything you need to start shipping events to Segment from your Rails app. Let’s start with something simple.
Step 2: Send a user sign up event to Segment
This step assumes you’re using devise to manage users. The process should be similar for other setups.
Now after a user is created you ship the event to Segment. If you are using the debugger in Segment, don’t worry if you don’t see events right away. The gem sends events in batches so you’ll probably need to queue up a few they ship.
Also, you might be tempted by using Analytics.js to ship events to Segment. That approach can be problematic for a variety of reasons. You have to figure out where to put the JS to trigger events and make sure you don’t trigger events multiple times. It’s doable but I prefer using the gem.
Step 3: Track important models
Say you’re building a blogging app and you’ve got a model called Post for when a user creates a new post. You could track it the same way you track new users.
Step 4: Setup your Relay account
After you create a Relay account you’ll be asked to integrate with Slack and Segment. Follow the instructions then you should see something like this.


Click ‘Create Stream’ and start off by adding a new channel called ‘app-events’. This adds a new channel to Slack. Later you’ll probably want to start incorporating important events into existing channels but I recommend starting with a new channel until you get a feel for what events to stream and how often.
Once you add a stream, you’ll be ready to start adding events from Segment to Slack!


Select the events you want to see. Configure the frequency, color, properties you want to show in Slack then turn it live!


Need more help configuring Relay? Check out the help docs.
Step 5: See your events in Slack!
Now your important app events should be flowing into Slack. Pretty soon you’ll have a happy team and happy users.


Next Steps
If you want to make the most of the events streaming into Slack, I highly recommend spending time thinking about what events your team needs access to and which properties they’ll need per event. Just showing when a new user signs up is great but there are opportunities to do so much more.
Here are a few ideas for other actionable events you could add.
- Upgrades: When a user upgrades an account they’ll likely need help understanding new functionality they have access to.
- Downgrades: Find out why.
- Failure to complete important task: We design work flows all the time in apps. When someone starts a workflow and doesn’t finish, you should understand why. Sometimes it makes sense to talk to the user, other times you can get hints from important properties associated with the event.
- Any event that triggers an admin action: Say you’ve got an app where users submit content that has to be admin approved before it’s published. Instead of having your admin constantly checking a spreadsheet all day, ship the event to slack and approve/disapprove it right away. An immediate action can make a huge difference to a user in these situations.
- Important milestones: Sometimes it’s more important to stream ‘feel good’ events into your stream than ‘actionable’ events. Feel good events keep your team engaged and ready to act! An example of these might be a user upgrading to your biggest plan. Include your team members involved in making that happen as properties!