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_key2Add 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
end3Hook the Devise registrations controller
class Users::RegistrationsController < Devise::RegistrationsController
def create
super do |user|
Chartsy.identify(user.email, cookies) if user.persisted?
end
end
endPoint 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.


