Privacy-first analytics for Rails apps in 2026
Add lightweight, cookieless analytics to your Rails app in 5 minutes. No cookies, no cookie banner for analytics, and an MCP server your AI tools can query.
Rails developers have plenty of analytics options — but most of them involve third-party JavaScript that bloats your bundle, requires consent banners, or sends user data to an ad network. If you want clean traffic data without the overhead, here’s how to add privacy-first analytics to a Rails app in under 5 minutes.
The one-line setup
Add the Measure tracking script to your application layout:
<%# app/views/layouts/application.html.erb %>
<head>
<title>My App</title>
<%= csrf_meta_tags %>
<%= csp_meta_tags %>
<!-- Measure — no cookies -->
<script defer src="https://lets.measure.events/api/script/YOUR_TRACKING_ID"></script>
</head>Replace YOUR_TRACKING_ID with the ID from your Measure dashboard. That’s the minimum setup — pageviews and time on page are now tracked automatically across your entire app, with humans, AI agents and bots counted separately.
Turbo and SPA support
If your Rails app uses Turbo (Hotwire), page transitions don’t trigger a full reload. That’s fine: Turbo Drive updates the URL with the browser’s history API, and the Measure script hooks pushState and popstate, so each Turbo visit is counted as a pageview. No Stimulus controller or turbo:load listener needed.
Tracking conversions
The script is pageviews only — there’s no JavaScript API for custom events. For signups and similar actions, the simplest approach is a real destination page: redirect to /welcome or /thanks after the action, and that path’s pageviews are your conversion count.
Server-side events via the API
For things that never touch a page — completed payments, background job completions, webhook events — post an event to the Measure REST API (https://lets.measure.events/api/v1) directly from Ruby. Events are recorded against a path, so give each one a descriptive virtual path:
# lib/measure_events.rb
require 'net/http'
require 'json'
module MeasureEvents
TRACKING_ID = ENV.fetch('MEASURE_TRACKING_ID')
BASE_URL = 'https://lets.measure.events/api/v1'
def self.track(path)
uri = URI("#{BASE_URL}/events")
http = Net::HTTP.new(uri.host, uri.port)
http.use_ssl = true
request = Net::HTTP::Post.new(uri)
request['Content-Type'] = 'application/json'
request['Authorization'] = "Bearer #{ENV.fetch('MEASURE_API_KEY')}" # mk_...
request.body = { site_key: TRACKING_ID, path: path }.to_json
http.request(request)
rescue => e
Rails.logger.warn "MeasureEvents tracking failed: #{e.message}"
end
endThen call it from any model, controller, or job:
# After a successful Stripe webhook
class StripeWebhooksController < ApplicationController
def create
case event.type
when 'checkout.session.completed'
MeasureEvents.track('/events/subscription-started')
when 'customer.subscription.deleted'
MeasureEvents.track('/events/subscription-cancelled')
end
end
endThe body can also carry referrer, user_agent, agent and utm_* fields, and there’s a batch endpoint at /api/v1/events/batch that takes {"events": [...]} if you’re sending many at once.
Excluding admin traffic
You don’t want your own dashboard visits inflating your numbers. Exclude them cleanly:
<%# app/views/layouts/application.html.erb %>
<% unless current_user&.admin? %>
<script defer src="https://lets.measure.events/api/script/YOUR_TRACKING_ID"></script>
<% end %>The MCP server: query your traffic with AI
This is where Measure goes beyond a standard analytics tool.
Add the MCP server to your Cursor or Claude configuration, using an API key (they start with mk_):
{
"mcpServers": {
"measure-events": {
"url": "https://lets.measure.events/mcp",
"headers": {
"Authorization": "Bearer mk_your_api_key_here"
}
}
}
}Now you can ask your AI assistant directly:
“How many people reached /welcome this week?” “Which blog post is driving the most traffic to /pricing?” “Is /dashboard usage trending up since we shipped the new feature?”
No dashboard tab-switching. No building custom queries. Your Rails app’s traffic data is part of your AI workflow.
Privacy and consent
Measure is fully cookieless — no document.cookie writes, nothing stored on the visitor’s device, no IP addresses or user-agent strings stored. Visitors are counted with a daily-rotating salted hash. That means a cookie banner isn’t needed for Measure. Whether you need consent for anything else depends on your jurisdiction and the rest of your stack — talk to your counsel.
For Rails apps with a consent management setup, you can still conditionally load the script:
<% if user_consented_to_analytics? %>
<script defer src="https://lets.measure.events/api/script/YOUR_TRACKING_ID"></script>
<% end %>Get started
- Start a 14-day trial — $29/month covers 40 sites
- Create a site and copy your tracking ID
- Add the script tag to
app/views/layouts/application.html.erb - Deploy — you’re tracking
The whole setup takes about 5 minutes. The MCP server config takes another 2.
Let your agent read the numbers.
$29 a month covers 40 sites, then $0.50 a site. 14-day trial.