Skip to main content

Subscribe to GoRails to get access to this episode and all other pro episodes, and new awesome content every month.

Subscribe Now
Only $19/month

Unlimited access. Cancel anytime.

21 Common Features:

Analytics with Segment

Episode 195 · June 27, 2017

Track users and the actions they take in your Rails app and then send them over to various 3rd party services using Segment

Javascript Analytics


Subscribe or login to view the transcript for this episode.



Great episode Chris! Would be awesome to see some more detailed episodes both for client and server side implementations.


Got any specifics you'd like to see?


Would be great to see more details on how/why to choose client/server/mixed solutions and keep them in sync (I guess for some of the actions only FE can be used, but for others BE would be safer). How to build a bit more robust analytics tracking system with a bunch of analytics events without polluting/slowing down your code. (For instance creating a wrapper class for all analytics events, when to use BG jobs or when to use promises on FE, etc.). So basically a system design for a more complex segment implementation. I think this is also a great opportunity to show how to structure 3rd party code (as there can be many events in different places) and still writing clean ruby code.


Yeah, for some things for example you may want to track form submissions. Frontend code generally would just track the form submitting, but not whether or not it was successful. This can be useful and you may want to know attempted submissions vs successful submissions as an example.

You're not going to be slowing down your code in either case. Frontend runs in the user's browser so it won't slow anything down. Server-side events are submitted in asynchronously so they won't affect the speed of your code there either.

As for complex integrations, generally analytics are just designed to be an additional line of code that runs in your logic. You will already have methods or classes for that logic so you'd just drop in an additional line to says "Purchase complete" after running through your payments code.

I'll try to come up with an example to go a bit more in-depth on. Generally analytics aren't anything too complex, you've just gotta make sure you write good names for events so they make sense when you're analyzing them later. :)


Lots of places in the video where I think you meant to edit in a cut, but instead left all of the re-takes in. It didn't make a difference to me, but you might want to be more thorough with editing (especially on the pro videos).


For anyone that wants to see a very detailed implementation of Segment within a real world Rails SaaS app, I wrote extensively about that here:


For anyone who isn't seeing events load in the debugger:

Make sure you have any adblockers switched off for localhost:3000 or any other website with this that you're testing!

Login or create an account to join the conversation.