ActionLab Analytics for Ruby on Rails
Add privacy-first, AI-powered analytics to your Ruby on Rails site in under 60 seconds. No cookies, no consent banners, no complex setup.
Setup at a Glance
Add ActionLab to Ruby on Rails in 4 simple steps. Copy one script tag, paste it into your project, and start collecting privacy-friendly analytics immediately.
About Ruby on Rails
Ruby on Rails is a full-stack web framework that pioneered many conventions modern web development takes for granted. Its convention-over-configuration philosophy, Active Record ORM, and rich gem ecosystem power thousands of production applications. With the addition of Turbo (Hotwire) for SPA-like navigation, Rails applications now provide the responsiveness of single-page applications with server-rendered reliability. ActionLab integrates through ERB templates with environment variable configuration, and automatically tracks Turbo Drive navigation.
Why Add Analytics to Ruby on Rails
Rails developers value convention and simplicity, and ActionLab integration follows Rails conventions with environment variable configuration and layout template inclusion. The automatic Turbo Drive tracking is particularly important for modern Rails applications where Turbo replaces full page reloads with client-side navigation — many analytics tools miss these transitions. No gem dependency means no Bundler conflicts, no version pinning, and no security updates to track for the analytics integration.
Installation Code
<%# app/views/layouts/application.html.erb %>
<head>
<script
src="https://cdn.actionlabanalytics.com/actionlab.js"
data-site="<%= ENV['ACTIONLAB_SITE_ID'] %>"
defer
></script>
</head>Step-by-Step Setup
- 1
Add the ActionLab script to your application layout: app/views/layouts/application.html.erb.
- 2
Set ACTIONLAB_SITE_ID in your environment variables (via .env, credentials, or your hosting platform environment configuration).
- 3
Turbo/Hotwire navigation is tracked automatically without any additional configuration.
- 4
No Rails gem or initializer needed — the ERB template inclusion is the complete integration.
Why Use ActionLab with Ruby on Rails
- Environment variable configuration follows Rails conventions for external service credentials.
- Turbo/Hotwire Drive navigation is tracked automatically, capturing page transitions in Turbo-enabled Rails applications.
- No gem dependency to maintain, keeping your Gemfile clean and avoiding version compatibility concerns.
- Compatible with Rails 6+ and works with Importmap, jsbundling-rails, and cssbundling-rails asset approaches.
Frequently Asked Questions
Does ActionLab work with Turbo Drive?
Yes. ActionLab detects Turbo Drive navigation events via the History API and tracks them as pageviews automatically. When Turbo Drive navigates between pages (replacing the body without a full page reload), ActionLab records each navigation. No additional JavaScript, Stimulus controllers, or Turbo event listeners are needed.
Does ActionLab work with Rails Turbo Frames?
Turbo Frames update portions of a page without full navigation. Frame updates that do not change the URL are not tracked as pageviews (they are not page navigations). If a Turbo Frame update changes the URL via turbo-action="advance", ActionLab tracks it as a navigation.
Can I use Rails credentials for the site ID?
Yes. Instead of ENV, use Rails.application.credentials.actionlab[:site_id] to store the site ID in encrypted credentials. Both approaches work — choose whichever matches your application credentials management pattern.
Does ActionLab work with Rails API-only mode?
Rails API-only mode does not serve HTML pages, so there is no layout to add the script to. ActionLab is designed for websites with HTML pages. If you have a separate frontend application (React, Vue, etc.) that consumes your Rails API, add ActionLab to the frontend application instead.
Can I fire custom events from Stimulus controllers?
Yes. ActionLab JavaScript API for custom events can be called from any Stimulus controller action. This lets you track specific interactions like form submissions, modal opens, or feature toggles within the Stimulus-driven Rails frontend.