How to Integrate Intercom with Ruby on Rails

Photo of Mateusz Pałyz

Mateusz Pałyz

Updated Dec 6, 2024 • 6 min read
SMruby on rails faq copy

Intercom is a popular marketing and consumer communication tool. Intercom integration in your Ruby on Rails app is not complicated and, thanks to this guide, you should be able to do it in no time.

I assume you have:

  • user model configured,
    or

  • config.include_for_logged_out_users = true set in the Intercom configuration (for more info see Step 3).

What You Will Use

Pros:

  • easy to integrate;

  • multipurpose - in-app live chat, marketing automation, customer feedback, customer support, client tracking;

  • many integrations available - Facebook, Github, Mailchimp, Salesforce, Mixpanel, Stripe, Hipchat, Zendesk, Slack, Zapier, Webhooks;

  • great documentation.

Cons:

  • pricing - may become expensive in certain scenarios - a couple of plans to choose from (Live Chat, Marketing Automation, Customer Feedback, Customer Support; pricing based on the number of tracked customers.

Step 1

Obtain an app id from https://www.intercom.io/ - a 14-day trial is available; however, a credit card is needed.

Step 2

Add intercom-rails gem to your Gemfile:

gem 'intercom-rails'

Then run:

bundle install

Use your app id to generate a config file:

rails generate intercom:config APP-ID

Step 3

Initialiser is saved as config/initializers/intercom.rb. This is where all the customisation is done.

config.app_id = ENV["INTERCOM_APP_ID"] || "sOm3th1ng"

Remember to remove hard-coded APP-ID from the initialiser. It should be stored either in git ignored config file or as an environmental variable.

By default, intercom script is added on every page where the current user can be identified. This behaviour can be changed by either limiting chat insertion for a specific controller

skip_after_action :intercom_rails_auto_include

Or adding the chat for unidentified users.

config.include_for_logged_out_users = true

Step 4

Further customisation. Intercom offers some really interesting options.

A method that defines the current user can be associated with Intercom via:

config.user.current = Proc.new { some_method }

Custom data can be associated with user:

config.user.custom_data = {
plan: Proc.new { |user| user.plan.name },
happy_user: Proc.new { |user| user.happy? }
}

Users can be grouped as if they were from a single company:

config.company.current = Proc.new { company_method }

Intercom, by default, adds a button which activates the chat. If you want to override this behaviour, add:

config.inbox.style = :custom

Now, each element with the id of Intercom will act as an activator. Further customisation of CSS selector can be achieved with:

config.inbox.custom_activator = '.intercom-link'

Use Cases

Intercom can be used in four vital areas of the application.

Live Chat

Real-time chat - makes it possible to track which users are currently visiting the page and what they are doing. The most frequently answered question can be saved as templates, whereas the messages can be sent automatically (e.g. when a user visits a specific page for the first time or when a user visits the site for the 3rd time). Intercom inbox informs when a customer is entering a message and which team member is handling the conversation.

Marketing Automation

Automated, targeted emails for customers. Creating rules for users messaging (e.g. the user didn’t log in for 1 month, or the user used a specific part of an application only once). Personalised content-rich messages - embedded images, videos, buttons, etc. Metrics can be created based on the effectiveness (e.g. 70% of users filled up profile page after receiving message A; 60% of users filled up the profile page after receiving message B; message A performs better).

Customer Feedback

Gathering information about a product (e.g. a message asking for feedback after the user stopped using an application; asking for feedback about the new feature just after the first interaction). Lightweight replying system (thumb up / thumb down), asking users about feedback without causing too much distraction.

Customer Support

Customers can get in touch via inbound email or in-app messenger. Client questions handling can be assigned to a team member with the greatest experience in a given field. All customer data and previous conversations are stored in one place so that the team is always on the same page with the customer. Private notes can be added to any conversation - these notes are only visible to the team, not the client.

Summary

During this tutorial, you have learned how to properly integrate and customise Intercom using a gem and example uses cases how to use it in business applications. I hope you find it helpful - feel free to comment if you have questions or like to add something.
Photo of Mateusz Pałyz

More posts by this author

Mateusz Pałyz

Mateusz started his adventure in IT at the university where he studied computer networks. Soon, he...
Efficient software development  Build faster, deliver more  Start now!

Read more on our Blog

Check out the knowledge base collected and distilled by experienced professionals.

We're Netguru

At Netguru we specialize in designing, building, shipping and scaling beautiful, usable products with blazing-fast efficiency.

Let's talk business