finds.dev← search

// the find

railslove/rack-tracker

★ 649 · Ruby · MIT · updated Mar 2024

Tracking made easy: Don’t fool around with adding tracking and analytics partials to your app and concentrate on the things that matter.

Rack middleware that injects third-party tracking scripts (Google Analytics, GTM, Facebook Pixel, and a dozen others) into HTML responses from a single configuration point. Lets you fire server-side tracking events from controllers without scattering `<script>` tags across templates. Useful for Rails or Sinatra apps that need to manage several trackers without turning every layout into a graveyard of vendor snippets.

DNT header support is on by default and has to be explicitly overridden per-handler — that's the right default and most trackers skip it entirely. The custom handler interface is clean: subclass, provide an ERB template, implement `self.track`, done. Dynamic configuration via lambdas (e.g. `id: lambda { |env| env['PIXEL_ID'] }`) means multi-tenant pixel IDs work without hacks. Test coverage is solid — both unit specs per handler and integration specs that verify actual HTML injection.

Google Analytics UA (`analytics.js`) is dead — Google killed it in July 2023, yet it's still the primary GA handler here. The `google_global` gtag.js handler exists but the README buries it. Last meaningful activity was 2024, and several supported services (Zanox, GoSquared, VWO) are either defunct or rebranded. XSS is called out in the README as a known risk with no mitigation built in — the responsibility is entirely punted to the caller, so one careless `t.google_analytics :send, params[:event]` and you have a problem. No support for consent management or cookie categories, which is now a legal requirement in most of Europe.

View on GitHub → Homepage ↗

// want more like this?

We dig through GitHub every week and send a few repos picked for what you actually care about — each with an honest take like this one.

Get finds in your inbox → Search again →