Segment is an incredible layer of abstraction between your application and analytics systems. It's major benefit is when tracking events at the user interface side. This includes all kinds of great meta data about the user that isn't available on the server.
In client rendered apps this isn't a problem. Do event tracking at the JavaScript layer once the event is verified as successful! In server-side apps, the browser doesn't have a clear way of knowing whether an action was successful or not.
To get that oh-so-sweet client side meta-data while still maintaining the rapid development and accessibility of server-side rendering; we enqueue user action events in a cookie. We use JavaScript to read the queue and track the events with Segment. Mmmm, now we get the lovely referring domain and utm data!
- Add
segment-rails
to your Gemfile - Configure
segment-rails
in yourApplicationController
class ApplicationController < ActionController::Base
include SegmentRails
def user_identifier
current_user ? current_user.id : nil
end
end
- Instrument your controllers with
track_event("Timmy fell down the well", { reporter: :lassie })
- Profit! (Or at least, observe behaviors which you hope will lead to profit)