Track signups with Ruby on Rails and Devise

Hook the Devise registrations controller, and OmniAuth callbacks for new records.

Before you start

The Chartsy script must already be on every page of your site, including the app where signup happens - it supplies where the visitor came from; this guide only adds the email. See the installation guides.

1Add your secret key

Copy the site's secret key from Settings → Domains in Chartsy and store it as CHARTSY_SECRET_KEY in your server's environment. It never goes in browser code or git.

CHARTSY_SECRET_KEY=your_secret_key

2Add the Chartsy service

require "net/http"

module Chartsy
  URL = URI("https://dashboard.chartsy.app/api/attribution/identify/")

  def self.identify(email, cookies)
    parse = ->(v) { JSON.parse(CGI.unescape(v.to_s)) rescue {} }
    first = parse.(cookies[:chartsy_attrib])
    last = parse.(cookies[:chartsy_attrib_last]).presence || first
    Net::HTTP.post(URL,
      { email: email, attribution_first: first, attribution_last: last,
        visitor_id: cookies[:chartsy_visitor_id].to_s }.to_json,
      "Content-Type" => "application/json",
      "Authorization" => "Bearer #{ENV.fetch('CHARTSY_SECRET_KEY')}")
  rescue StandardError
    nil
  end
end

3Hook the Devise registrations controller

class Users::RegistrationsController < Devise::RegistrationsController
  def create
    super do |user|
      Chartsy.identify(user.email, cookies) if user.persisted?
    end
  end
end

Point Devise at it:

devise_for :users, controllers: { registrations: "users/registrations" }

4OmniAuth signups

In your OmniAuth callback, call Chartsy.identify only when user.previously_new_record? is true.

Related articles

Chartsy Team

Written by

Chartsy Team

Analytics team at Chartsy

The Chartsy Team writes guides, product updates, and resources to help SaaS and eCommerce founders make sense of their metrics, without SQL or spreadsheets.

Chartsy
Ministry of Economy and Innovation
Startup Albania

The Chartsy program is realized with the financial support of the Albanian Government through the Ministry of Economy and Innovation, under the Grant 2026 scheme, and is implemented by the Innovation4Albania Agency.