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

- old
+ new

@@ -1,7 +1,9 @@ # IntercomRails +[![Join the chat at https://gitter.im/intercom/intercom-rails](https://badges.gitter.im/intercom/intercom-rails.svg)](https://gitter.im/intercom/intercom-rails?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge) + The easiest way to install Intercom in a rails app. For interacting with the Intercom REST API, use the `intercom` gem (https://github.com/intercom/intercom-ruby) ## Installation @@ -52,12 +54,48 @@ If you want to use secure mode, ensure you set your API secret in `config/initializers/intercom.rb`: ```ruby config.api_secret = '123456' ``` +**Note: This example is just for the sake of simplicity, you should never include your api secret in source control. Instead, you should use the Rails [secret config](http://guides.rubyonrails.org/4_1_release_notes.html#config-secrets-yml) feature.** +### Shutdown +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" : + +```ruby + Rails.application.config.session_store :cookie_store, key: 'intercom-session-' + IntercomRails.config.app_id +``` + +You should not modify or remove existing configurations in this file. + +#### 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. + +```ruby +IntercomRails::ShutdownHelper::intercom_shutdown_helper(self) +``` + +#### Session Duration + +To add a `session_duration` variable (in ms) to the widget, add the following line to `config/initializers/intercom.rb`: + +```ruby +config.session_duration = 5 * 60 * 1000 +``` +That will force your Intercom session to expire after 5 minutes which is the minimum amount of time authorized. + +More information about how session_duration works in [intercom documentation](https://docs.intercom.io/configuring-for-your-product-or-site/customizing-the-intercom-messenger#secure-user-conversations-configure-your-cookie-timeout) + ### User Custom data attributes + You can associate any attributes, specific to your app, with a user in Intercom. For custom data attributes you want updated on every request set them in `config/initializers/intercom.rb`, the latest value will be sent to Intercom on each page visit. Configure what attributes will be sent using either a: @@ -104,10 +142,14 @@ ```ruby config.company.current = Proc.new { current_company } ``` +`current_company` is the method/variable that contains the user's current company in your controllers. +If you are using devise you should replace `current_company` with `current_user.company` in the above code and every time you see 'current_company' in your configuration file. +This will result in injecting the user current company in the widget settings. + and like with Users, you can set custom attribute on companies too: ```ruby config.company.custom_data = { :number_of_messages => Proc.new { |app| app.messages.count }, @@ -245,17 +287,9 @@ The SHA-256 hash is available using `csp_sha256` just after generating the tag itself: ```erb <%= intercom_script_tag %> <% add_entry_to_csp_whitelist(intercom_script_tag.csp_sha256) %> ``` -## Importing your users -To get started faster with Intercom, `IntercomRails` includes a Rake task that will do an initial import of your users: - -``` -rake intercom:import -``` - -Any custom data defined in `config/initializers/intercom.rb` will also be sent. ## Running tests/specs specs should run on a clean clone of this repo, using the following commands. (developed against ruby 2.1.2 and 1.9.3)