I'm looking at the Kissmetrics (analytics app) JS API docs, and they have an "identify" method that lets you tell Kissmetrics about a user. Here's what their docs say:
We recommend you call identify in two scenarios:
When a user successfully signs up When a user successfully logs in, either through cookies or through a login page
What would be the best way to achieve that? How can I detect when a user has just signed up or signed in?
Lets divide the problem in two: register and log in.
You can detect when a new user has registered in you app just adding a
after_create
hook in youUser
model. Something likeDetecting when the user logs in is a little bit dirtier. Devise modify the
user.current_sign_in_at
attribute of the user when he/she logs in, so you could add abefore_save
hook in the user model and check if thecurrent_sign_in_at
attribute has changed. It should be something like:Once you have the right callbacks for detecting sign in/sign up, you can just create a cookie with the info and read it from the javascript or write a helper method for the
User
model and write something like this in your layout:Following this way, the complete model would be: