ruby on rails - How to Track Devise User Registration as Conversion in Google Analytics -


i'm using devise rails 3.2 app , want able add track new registrations conversions in google analytics. i'd have new users directed same page being redirected now, if possible (i.e. may pass thru view redirects current page users redirected after create).

can please me figure out best way devise?

# users/registrations_controller.rb # post /resource def create   build_resource   if resource.save             if resource.active_for_authentication?       set_flash_message :notice, :signed_up if is_navigational_format?       sign_up(resource_name, resource)       respond_with resource, :location => after_sign_up_path_for(resource)     else       set_flash_message :notice, :"signed_up_but_#{resource.inactive_message}" if is_navigational_format?       expire_session_data_after_sign_in!       respond_with resource, :location => after_inactive_sign_up_path_for(resource)     end   else     clean_up_passwords resource     respond_with resource   end end  def after_sign_up_path_for(resource)   after_sign_in_path_for(resource) end 

from top of head, i'd use flash.

the flash provides way pass temporary objects between actions. place in flash exposed next action , cleared out.

on registrations_controller.rb:

if resource.active_for_authentication?    flash[:user_signup] = true # or find more appropriate    set_flash_message :notice, :signed_up if is_navigational_format?   sign_up(resource_name, resource)   respond_with resource, :location => after_sign_up_path_for(resource) else   set_flash_message :notice, :"signed_up_but_#{resource.inactive_message}" if is_navigational_format?   expire_session_data_after_sign_in!   respond_with resource, :location => after_inactive_sign_up_path_for(resource) end 

then, on view redirect after signup, i'd render necessary code trigger google analytics event based on presence of flash[:user_signup].


Comments

Popular posts from this blog

ios - RestKit 0.20 — CoreData: error: Failed to call designated initializer on NSManagedObject class (again) -

java - Digest auth with Spring Security using javaconfig -

laravel - PDOException in Connector.php line 55: SQLSTATE[HY000] [1045] Access denied for user 'root'@'localhost' (using password: YES) -