Convention-first customer tracking for Ruby on Rails
Rails developers know that the right place to "do something after a record is created" is an after_create_commit callback. TinyCRM fits that pattern exactly. One callback in your User model syncs every new customer to a unified table — no controllers to touch, no configuration to maintain.
Installation
Add to your Gemfile:
gem "tinycrm"bundle installAdd to credentials or environment:
TINYCRM_API_KEY=tcrm_proj_xxxxxxxxxxxxGetting started: Rails integration
Option A — ActiveRecord callback (recommended)
# app/models/user.rb
class User < ApplicationRecord
after_create_commit :sync_to_tinycrm
private
def sync_to_tinycrm
crm = TinyCRM::Client.new(api_key: ENV["TINYCRM_API_KEY"])
crm.identify(
email: email,
name: name,
status: "free",
params: { created_at: created_at.to_date.to_s }
)
end
endOption B — ActiveJob for async (zero latency impact)
# app/jobs/sync_customer_to_tiny_crm_job.rb
class SyncCustomerToTinyCRMJob < ApplicationJob
queue_as :default
def perform(email:, name:, status: "free", params: {})
crm = TinyCRM::Client.new(api_key: ENV["TINYCRM_API_KEY"])
crm.identify(email: email, name: name, status: status, params: params)
end
end
# Enqueue from model or controller:
SyncCustomerToTinyCRMJob.perform_later(
email: user.email,
name: user.name,
status: "free"
)Integrating with Devise
# app/controllers/users/registrations_controller.rb
class Users::RegistrationsController < Devise::RegistrationsController
def create
super do |resource|
if resource.persisted?
crm = TinyCRM::Client.new(api_key: ENV["TINYCRM_API_KEY"])
crm.identify(
email: resource.email,
name: resource.name,
status: "free",
params: { utm_source: session[:utm_source] }
)
end
end
end
end
# config/routes.rb
devise_for :users, controllers: { registrations: "users/registrations" }Track paid conversions via Stripe webhook
# app/controllers/webhooks/stripe_controller.rb
class Webhooks::StripeController < ApplicationController
skip_before_action :verify_authenticity_token
def create
payload = request.body.read
event = verify_stripe_webhook(payload, request.env["HTTP_STRIPE_SIGNATURE"])
if event[:type] == "checkout.session.completed"
email = event.dig(:data, :object, :customer_email)
plan = event.dig(:data, :object, :metadata, :plan)
crm = TinyCRM::Client.new(api_key: ENV["TINYCRM_API_KEY"])
crm.identify(email: email, status: "paid", params: { plan: plan })
end
head :ok
end
endPing on meaningful user activity
# app/controllers/application_controller.rb
class ApplicationController < ActionController::Base
before_action :ping_tinycrm, if: :user_signed_in?
private
def ping_tinycrm
crm = TinyCRM::Client.new(api_key: ENV["TINYCRM_API_KEY"])
crm.ping(email: current_user.email)
end
endRails ecosystem compatibility
Devise
Override RegistrationsController or use after_create on User.
ActiveRecord
after_create_commit is the cleanest hook point.
ActiveJob + Sidekiq
Queue identify() for zero request latency impact.
Rails API mode
Fully compatible — no view layer needed.
Hotwire / Turbo
No interaction — SDK is server-only, no JS involved.
Heroku / Render
Works on any standard Ruby deployment.
Rails FAQ
Should I use an ActiveRecord callback or a controller action for identify()?
Both work. An after_create_commit callback on the User model is clean and ensures tracking happens regardless of which controller creates the user. Controller actions give you more context (e.g., UTM params from request). For Rails apps with Devise, the Devise::RegistrationsController#create is a common hook point.
Can I use ActiveJob to queue TinyCRM calls in Rails?
Yes. Create a SyncCustomerToTinyCRMJob < ApplicationJob and call TinyCRM.identify from its perform method. Enqueue it with SyncCustomerToTinyCRMJob.perform_later(user.email, user.name) for zero latency impact on request handling.
Does the Ruby SDK work with Devise?
Yes. The most Rails-idiomatic approach is an after_create_commit callback on your User model (the model that Devise manages). Alternatively, override Devise::RegistrationsController#create and add the identify call after super.
Does it work with Rails API mode?
Absolutely. Rails API mode is still a full Rails app — controllers, models, ActiveRecord, and ActiveJob all work identically. The SDK has no dependency on view rendering.
See every Rails customer in one table
14-day free trial. No credit card. Convention over configuration.
gem "tinycrm"