GuidesBackend

Ruby and Rails analytics, cookieless and hosted in the EU

Server-side analytics for Ruby and Rails, with event data stored in Germany.

Privytics tracks events straight from your Ruby or Rails backend using the openpanel-sdk gem. You install the gem, set three environment variables, build a tracker and call track. Because the events leave your server rather than the browser, there is no script tag and nothing written to the visitor's device.

Why Ruby teams use Privytics

Server-side events do not get blocked

Requests originate from your Rails process, not the browser, so ad blockers, tracking protection and script blockers never see them. Signups, payments and background job outcomes get recorded whatever the client is running.

Fits the Rails request lifecycle

The tracker constructor takes a global properties hash and a disabled flag, so you can build one instance per request in ApplicationController, tag every event with Rails.env, and switch tracking off in development with a single argument.

You decide what leaves your server

Client IP and user agent are not collected implicitly. You forward them yourself with set_header, using request.ip and request.user_agent, so the data your backend sends is exactly what you chose to send.

Profiles keyed on your own user ids

Backend events have no browser to fingerprint. You attach them with profile_id or an IdentifyUser object built from your own User record, which is the natural identifier a Rails app already has. Note that identifying users is opt-in and needs your own lawful basis.

Set it up

About five minutes, on the free plan, without a credit card.

  1. Install the gem

    The gem requires Ruby 3.2.0 or higher.

    bundle add openpanel-sdk
    
    # or, without Bundler
    gem install openpanel-sdk
  2. Point the SDK at Privytics

    The SDK reads its configuration from environment variables. Set them in your .env file. The track URL must point at the Privytics ingestion API, otherwise events go to the default OpenPanel host. Note it takes a full URL ending in /track, not a bare host.

    OPENPANEL_TRACK_URL=https://api.privytics.com/track
    OPENPANEL_CLIENT_ID=YOUR_CLIENT_ID
    OPENPANEL_CLIENT_SECRET=YOUR_CLIENT_SECRET
  3. Create a tracker

    Require the gem and build a tracker. The first argument is a hash of global properties applied to every event, so pass an empty hash if you have none. In Rails, build one per request so it can carry the environment, forward the request details and be disabled locally.

    require 'openpanel-sdk'
    
    tracker = OpenPanel::SDK::Tracker.new({})
    
    # Rails: app/controllers/application_controller.rb
    class ApplicationController < ActionController::Base
      before_action :set_openpanel_tracker
    
      protected
    
      def set_openpanel_tracker
        @openpanel_tracker = OpenPanel::SDK::Tracker.new(
          { env: Rails.env.to_s },
          disabled: Rails.env.development?
        )
        @openpanel_tracker.set_header 'x-client-ip', request.ip
        @openpanel_tracker.set_header 'user-agent', request.user_agent
      end
    end
  4. Track events and identify users

    track takes an event name and a payload, and optionally a profile_id to attach the event to a known user. IdentifyUser sets profile properties, and the profile counters take that same object.

    # A plain event
    @openpanel_tracker.track('signup_completed', payload: { plan: 'free' })
    
    # An event attached to a known user
    @openpanel_tracker.track(
      'invoice_paid',
      profile_id: current_user.id.to_s,
      payload: { amount: 49 }
    )
    
    # Build a profile
    identify_user = OpenPanel::SDK::IdentifyUser.new
    identify_user.profile_id = current_user.id.to_s
    identify_user.email = current_user.email
    identify_user.first_name = current_user.first_name
    identify_user.last_name = current_user.last_name
    identify_user.properties = { tier: 'premium', company: 'Acme Inc' }
    
    @openpanel_tracker.identify(identify_user)
    
    # Counters on the profile
    @openpanel_tracker.increment_property(identify_user, 'visits', 1)
    @openpanel_tracker.decrement_property(identify_user, 'credits', 1)
    
    # Revenue
    @openpanel_tracker.revenue(
      user: identify_user,
      amount: 49,
      properties: { currency: 'EUR' }
    )

Privytics runs the open-source OpenPanel engine, so the upstream Ruby SDK reference applies here too. Point apiUrl at Privytics and the data lands in your Privytics project.

Questions

Does this work with Ruby on Rails?

Yes. The documented pattern is to build a tracker in ApplicationController with the Rails environment as global properties and disabled: Rails.env.development?, forward the client IP and user agent with set_header, then reuse that instance across your actions.

Is the openpanel-sdk gem official?

It is a community-maintained gem published on RubyGems as openpanel-sdk, not a first-party package under the @openpanel scope like the JavaScript SDKs. It is the gem the OpenPanel Ruby documentation points to.

Do server-side Ruby events set cookies?

No. Privytics is cookieless by default and a backend event has no browser to write to. Events are anonymous unless you attach a profile_id or call identify with your own user id.

How do I send events to Privytics instead of OpenPanel?

Set OPENPANEL_TRACK_URL to https://api.privytics.com/track. The gem defaults to the OpenPanel host, so this variable is required rather than optional. There is no in-code option for it, and no script tag is involved in a server-side SDK.

Where is the event data stored?

Event data is stored in EU data centres in Germany. Privytics is a managed service built on the open-source OpenPanel engine and is not affiliated with OpenPanel.