January 26, 2026 · 13 min read
How to Add Product Analytics to Your Rails SaaS with PostHog in 2026
Jeronim Morina
Founder, Omaship
You shipped your Rails SaaS. People are signing up. But you have no idea what they actually do after login. Product analytics fixes that — and PostHog is the best tool for the job in 2026.
Most SaaS founders either skip analytics entirely or drop in Google Analytics and call it done. Both are mistakes. GA tells you page views. Product analytics tells you which features drive retention, where users drop off in your onboarding funnel, and which cohorts churn before month two. That is the difference between guessing and knowing.
This guide covers why product analytics matters, how PostHog compares to the alternatives, and exactly how to integrate it into a Rails SaaS using server-side tracking with the omaship_monitoring engine. No vanity metrics, no third-party cookie nightmares, no vendor lock-in.
Why product analytics matters for SaaS (beyond page views)
Page views and bounce rates are not product analytics. They are traffic analytics. They tell you how people find your site. Product analytics tells you what happens after they arrive.
The questions that actually matter for a SaaS:
- Activation: What percentage of signups complete onboarding? Where do they drop off?
- Feature adoption: Which features do paying customers use? Which ones do churned customers never touch?
- Conversion funnel: How many visitors reach the login page? How many log in successfully? How many create their first project?
- Churn signals: Which behaviors predict cancellation? Do users who skip the setup wizard churn faster?
- Revenue correlation: Which features correlate with upgrades to higher plans?
Google Analytics cannot answer any of these. You need event-based tracking tied to identified users, with funnels, cohorts, and retention analysis. That is what product analytics tools do.
PostHog vs Mixpanel vs Amplitude vs Google Analytics: an honest comparison
There are four serious options for product analytics in 2026. Here is how they compare for a Rails SaaS:
| Criteria | PostHog | Mixpanel | Amplitude | GA4 |
|---|---|---|---|---|
| Open source | Yes (MIT) | No | No | No |
| Self-hostable | Yes | No | No | No |
| Ruby SDK | Official (posthog-ruby) | Official | HTTP API only | Measurement Protocol |
| Rails integration | posthog-rails gem | Manual | Manual | Manual |
| Server-side tracking | First-class | Supported | Supported | Limited |
| Session replay | Built-in | Add-on | Add-on | No |
| Feature flags | Built-in | No | Built-in | No |
| EU data residency | Yes (eu.posthog.com) | Yes | Yes | No |
| Free tier | 1M events/mo | 20M events/mo | 50K MTUs | Unlimited (sampled) |
| Vendor lock-in | None (self-host option) | High | High | High |
Mixpanel has the most generous free tier. Amplitude has strong behavioral analytics. GA4 is free and familiar. But PostHog is the only option that is open source, self-hostable, and ships with session replay, feature flags, and a first-class Ruby SDK — all in one platform.
For a Rails SaaS founder who cares about data ownership and privacy, PostHog is the clear choice. You can start on their cloud (EU or US) and self-host later if you need to. No other tool gives you that flexibility.
Server-side vs client-side tracking: why server-side wins for SaaS
Most analytics tools default to client-side tracking: drop a JavaScript snippet on the page and track events from the browser. This works, but it has serious downsides for SaaS products.
Client-side problems:
- Ad blockers kill your data. 30-40% of technical users run ad blockers that block analytics scripts. Your most engaged users are invisible.
- Cookie consent gates everything. Under GDPR, you cannot load the tracking script until the user accepts cookies. If they decline, you get zero data.
- Browser variability. Safari ITP, Firefox ETP, and Brave all restrict third-party tracking. Your data is incomplete by default.
- Unreliable for critical events. Users can close the tab before the event fires. Page unload events are notoriously unreliable.
Server-side advantages:
- 100% event capture. Events fire from your server. No ad blockers, no browser restrictions, no race conditions.
- Privacy-friendly by design. Server-side events do not need cookies. You are tracking application behavior, not browser behavior. This simplifies GDPR compliance significantly.
- Accurate user identity. You have the authenticated user in the session. No need for anonymous ID merging or cross-device identity resolution hacks.
- Simpler implementation. One
PostHog.capturecall in your controller. No JavaScript to debug, no client-side state to manage.
The best approach is a hybrid: server-side for business-critical events (signups, feature usage, conversions) and client-side for UI interactions (button clicks, page scroll depth, session recordings) — but only after cookie consent.
How Omaship integrates PostHog: the omaship_monitoring engine
Omaship ships a dedicated Rails engine — omaship_monitoring — that wires PostHog into your application with sensible defaults. It handles the parts that every SaaS needs and would otherwise require boilerplate: user identification, cookie consent gating, session replay control, and server-side event capture.
The engine depends on two official gems: posthog-ruby for server-side tracking and posthog-rails for automatic exception capture, ActiveJob instrumentation, and user context detection.
Installation is one command:
bin/rails generate omaship:monitoring:install
This generator does four things:
- Creates the PostHog initializer (
config/initializers/omaship_monitoring.rb) with auto-capture for exceptions, ActiveJob instrumentation, and user context detection. - Includes
PosthogIdentifiablein your User model — a concern that providesposthog_distinct_idandposthog_propertiesmethods for consistent identity resolution. - Injects the PostHog head tag into your layouts — with automatic user identification on authenticated layouts and anonymous tracking on public layouts.
- Updates AGENTS.md so AI coding agents know the monitoring engine is installed.
User identity: the PosthogIdentifiable concern
Consistent user identification is the foundation of product analytics. Without it, you cannot build funnels, cohorts, or retention charts. The engine provides a concern that standardizes this:
module OmashipMonitoring
module Concerns
module PosthogIdentifiable
extend ActiveSupport::Concern
def posthog_distinct_id
"user:#{id}"
end
def posthog_properties
{ user_id: id, admin: admin?, created_at: created_at&.iso8601 }
end
end
end
end
The user: prefix prevents ID collisions with other systems. The properties hash gives PostHog baseline context for every event without you having to pass it manually each time.
Cookie consent gating: analytics that respect privacy
The engine's posthog_head_tag helper only renders the PostHog JavaScript when the user has accepted cookies. No consent, no script, no tracking. This is GDPR-compliant by default.
def posthog_head_tag(identify: false)
consent_key = Rails.application.config.omaship_monitoring.cookie_consent_key
return unless cookies[consent_key] == "accepted"
api_key = ENV.fetch("POSTHOG_API_KEY", nil)
return unless api_key.present?
# ...
end
In your layouts, the helper is called differently depending on context:
- Public layout (
application.html.erb):<%= posthog_head_tag %>— anonymous tracking only. - App layout (
app.html.erb):<%= posthog_head_tag(identify: true) %>— automatically callsposthog.identify()with the current user's distinct ID and properties.
Session replay follows the same pattern. It is only enabled when the user explicitly accepts session recording via a separate consent key. Input masking is on by default, with password and email fields masked and a data-private attribute for sensitive elements.
Server-side event tracking: what to capture
The engine configures posthog-rails to automatically capture exceptions and ActiveJob events. For business events, you add PostHog.capture calls in your controllers and models. Here is what matters for a SaaS:
The essential event taxonomy:
# Naming convention: domain.entity.action
# Examples from Omaship's event definitions:
# Growth events
"marketing.landing.viewed" # Home page rendered
"preorder.checkout.started" # Checkout flow initiated
"preorder.checkout.completed" # Purchase completed
# Auth events
"auth.login.viewed" # Login page shown
"auth.login.submitted" # Form submitted
"auth.login.succeeded" # Login successful
"auth.login.failed" # Login failed (with failure_reason)
# Product events
"ship.created" # New project provisioned
"configuration.requested" # Feature configured
"deploy.triggered" # Deploy initiated
# Security events
"api_token.created" # API token generated
"api_token.revoked" # API token revoked
Every event carries required properties (source and path) plus domain-specific properties. The source property distinguishes between web, CLI, and API origins. This lets you build funnels that span your entire product surface.
Tracking an event in a controller:
class ShipsController < ApplicationController
def create
@ship = Current.user.ships.build(ship_params)
if @ship.save
PostHog.capture(
distinct_id: Current.user.posthog_distinct_id,
event: "ship.created",
properties: {
source: "web",
ship_id: @ship.id,
ship_type: @ship.ship_type,
visibility: @ship.visibility,
root_domain: @ship.root_domain
}
)
redirect_to @ship
else
render :new, status: :unprocessable_entity
end
end
end
Note: PostHog.capture is asynchronous by default. It batches events and flushes them in the background. No performance impact on your request cycle.
Key events every SaaS should track
You do not need to track everything. Start with the events that answer your most important business questions:
- Signup completed: The starting point for every funnel. Without this, you cannot measure activation or onboarding completion.
- Onboarding milestones: Each step in your setup flow. Identify where users drop off and fix the friction.
- Core feature used: The action that defines your product's value. For a project management tool, it might be "task created." For Omaship, it is "ship.created."
- Billing events: Checkout started, subscription created, plan changed, subscription canceled. These tie product behavior to revenue.
- Login frequency: Users who stop logging in are about to churn. Track login patterns to build early warning signals.
- Error events: Server exceptions and failed actions. The
posthog-railsgem captures these automatically withauto_capture_exceptions: true.
Building dashboards for SaaS KPIs
Raw events are useless without dashboards. PostHog supports funnels, trends, retention charts, and path analysis out of the box. Here is how Omaship structures its dashboards:
The Landing-to-Login funnel:
# From config/analytics/posthog/dashboards/landing_to_login.v1.yml
tiles:
- type: funnel
title: "Landing -> Login Success"
conversion_window: "7d"
steps:
- event: marketing.landing.viewed
- event: auth.login.viewed
- event: auth.login.submitted
- event: auth.login.succeeded
- type: formula
title: "Login Success Rate"
numerator:
event: auth.login.succeeded
denominator:
event: auth.login.submitted
- type: trends
title: "Login Failures by Reason"
event: auth.login.failed
breakdown: failure_reason
- type: funnel
title: "Landing -> Login by Entry Source"
breakdown: entry_source
steps:
- event: marketing.landing.viewed
- event: auth.login.succeeded
The key dashboards for any SaaS:
- Acquisition funnel: Visitor to signup to first meaningful action. Identify drop-off points and conversion rates at each step.
- Activation rate: What percentage of new signups reach the "aha moment"? Define your activation event and track it as a trend over time.
- Feature adoption: Which features are used by what percentage of active users? Use PostHog's stickiness chart to identify power features.
- Retention cohorts: Week-over-week or month-over-month retention by signup cohort. This is the single most important SaaS metric and PostHog builds it natively.
- Error rate: Exceptions per user session. Spikes in errors correlate with spikes in churn. PostHog captures these automatically via the Rails integration.
Keep your dashboard definitions in version control. Omaship stores them as YAML files in config/analytics/posthog/dashboards/. This makes dashboards reviewable, reproducible, and part of your deployment pipeline rather than ad-hoc configurations in a web UI.
GDPR and privacy: doing analytics without being creepy
Product analytics and privacy are not in conflict. You can track everything you need for product decisions without collecting PII or relying on third-party cookies. Here is how:
- Server-side tracking does not need cookies. When you call
PostHog.capturefrom your Rails backend, you are using an authenticated session. No cookies, no consent banner needed for these events. GDPR still applies (you are processing personal data), but the legal basis shifts from consent to legitimate interest. - Gate client-side tracking on consent. The
posthog_head_taghelper checks for cookie consent before rendering any JavaScript. Users who decline get zero client-side tracking. This is the correct GDPR implementation. - Separate session replay consent. Session recordings are more invasive than event tracking. The engine uses a separate consent key (
omaship_session_replay_consent) so users can accept analytics but decline recordings. - Mask sensitive inputs automatically. The engine configures PostHog to mask password and email input fields in session recordings. Elements with the
data-privateattribute orph-no-captureclass are excluded entirely. - Use EU data residency. The engine defaults to
eu.i.posthog.com. Your analytics data stays in the EU, simplifying GDPR compliance. No need for Standard Contractual Clauses or adequacy decisions. - Self-host for full control. If you need absolute data sovereignty, deploy PostHog on your own infrastructure. Your analytics data never leaves your servers.
The self-hosting angle: own your analytics data
PostHog is one of the few analytics platforms you can actually self-host. This is not a theoretical option — it is a production-ready deployment path with Docker and Kubernetes support.
Why self-hosting matters for SaaS founders:
- No vendor lock-in. Your analytics data is in your database. If PostHog the company disappears tomorrow, your dashboards and historical data survive.
- Cost control at scale. PostHog cloud charges per event. At high volume, self-hosting on a Hetzner server is significantly cheaper. A single dedicated server can handle millions of events per day.
- Data residency without compromise. Self-host in whatever jurisdiction your customers require. No reliance on a vendor's data center choices.
- Full API access. Query your analytics data directly from your Rails app. Build custom reports, export to data warehouses, or feed analytics into your own ML models.
The tradeoff is operational overhead. You need to maintain the PostHog instance, handle upgrades, and manage backups. For most early-stage SaaS products, starting with PostHog Cloud (EU) and migrating to self-hosted later is the pragmatic path. The omaship_monitoring engine supports both — just change the POSTHOG_HOST environment variable.
Putting it all together: the implementation checklist
| Step | What | Time |
|---|---|---|
| 1 | Create PostHog account (EU cloud) and get API key | 5 min |
| 2 | Run bin/rails generate omaship:monitoring:install |
2 min |
| 3 | Set POSTHOG_API_KEY in Rails credentials |
2 min |
| 4 | Add cookie consent banner (if not already present) | 15 min |
| 5 | Define your event taxonomy in config/analytics/posthog/events.v1.yml |
30 min |
| 6 | Add PostHog.capture calls to key controllers |
1-2 hrs |
| 7 | Build your first dashboard (acquisition funnel) | 20 min |
| 8 | Deploy and verify events in PostHog | 10 min |
Total setup time: about half a day. After that, every user action in your SaaS is tracked, funneled, and ready for analysis. You stop guessing what users want and start knowing.
The bottom line
Product analytics is not optional for a SaaS in 2026. It is the difference between building features your users want and building features you think they want. PostHog gives you everything — event tracking, funnels, session replay, feature flags — in one open-source platform with a real Ruby SDK.
Track server-side for reliability and privacy. Gate client-side on consent. Use EU data residency or self-host. Own your data. Ship with confidence because you know what your users actually do.
The best analytics setup is the one you actually use. Start with five events that answer your most important question, build one dashboard, and iterate from there. You do not need to instrument everything on day one. You need to instrument the right things.
Ship with analytics built in
Omaship includes the omaship_monitoring engine with PostHog integration, cookie consent gating, session replay controls, and server-side event tracking — ready to go from day one.