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' }
)