README.mdown in intercom-rails-0.2.33 vs README.mdown in intercom-rails-0.2.34

- old
+ new

@@ -42,10 +42,14 @@ * Your user object responds to an `id` or `email` method. * Your current user is accessible in your controllers as `current_user` or `@user`, if not in `config/initializers/intercom.rb`: ```ruby config.user.current = Proc.new { current_user_object } ``` +If your users can be defined in different ways in your app you can also pass an array as follows : +```ruby + config.user.current = [Proc.new { current_user_object }, Proc.new { @user_object }] +``` * If you want the Intercom Messenger to be available when there is no current user, set `config.include_for_logged_out_users = true` in your config and sign up for the [Acquire](https://www.intercom.io/live-chat) package. Feel free to mail us: team@intercom.io, if you're still having trouble. ## Configuration @@ -62,25 +66,64 @@ If you use Intercom Acquire combined with another product like Support, Learn or Engage, any user that uses a shared computer and browser with someone else will be able to see the most recently logged in user’s conversation history until the cookie expires. Because of this, it’s very important to properly shutdown Intercom when a user’s session on your app ends (via manually or automatically logging out). #### Using Devise -If your Rails application uses devise for authentication, you simply need to add the following line in your "config/initializers/session_store.rb" : +If you use devise, you can override (if not already done) the session_controller by replacing in your `config/routes.rb` file : +```ruby +devise_for :users +``` +by +```ruby +devise_for :users, controllers: {sessions: "sessions"} +``` +Then you can use the following code to prepare Intercom Shutdown on log out in your `app/session_controller.rb` + ```ruby - Rails.application.config.session_store :cookie_store, key: 'intercom-session-' + IntercomRails.config.app_id +class SessionsController < Devise::SessionsController + + after_action :prepare_intercom_shutdown, only: [:destroy] + + # Your logic here + + protected + def prepare_intercom_shutdown + IntercomRails::ShutdownHelper.prepare_intercom_shutdown(session) + end +end ``` -You should not modify or remove existing configurations in this file. +Assuming that the `destroy` method of session_controller redirects to your `visitors_controller.rb#index` method, edit your `visitors_controller` as follow : + +```ruby +class VisitorsController < ApplicationController + after_action :intercom_shutdown, only: [:index] + + def index + # You logic here + end + + # You logic here + + protected + def intercom_shutdown + IntercomRails::ShutdownHelper.intercom_shutdown(session, cookies) + end +end +``` + #### Using another service -If you use another service than Devise or if you implemented your own authentication service, you can call the following method in a controller to shutdown Intercom on logout (self being the controller instance). -**Be aware that if you call this method before a 'redirect_to' (quite common on logout) it will have no impact** as it is impossible to update cookies when you use a redirection. +If you use another service than Devise or if you implemented your own authentication service, you can call the following method in a controller to shutdown Intercom on logout. ```ruby -IntercomRails::ShutdownHelper::intercom_shutdown_helper(self) +IntercomRails::ShutdownHelper::intercom_shutdown_helper(cookies) ``` + +**Be aware that if you call this method before a 'redirect_to' (quite common on logout) it will have no impact** as it is impossible to update cookies when you use a redirection. +But you can use the same logic as the `devise` implementation above. #### Session Duration To add a `session_duration` variable (in ms) to the widget, add the following line to `config/initializers/intercom.rb`: