The Freshsales Ruby library helps you track the in-app activity of customers using your web application. 

STEP 1: Getting started

  1. Copy this snippet and paste it in the gem file and run bundle install.
gem 'freshsales-analytics', git:''

      2. Create a .yml file and name it “fs_analytics_config.yml” in the config folder of your web app.

      3. Copy and paste the snippet below in the .yml file you created.

app_token: ‘your freshsales app token’
url: ‘your freshsales portal url’

     4. Replace the app_token and url with your app token and portal url. You can find it under Admin Settings > Integrations > Freshsales for web > Ruby 

STEP 2: Create leads 

You can use the snippet below to create leads, track signups and logins. 

sample_contact = {
  'First Name' => 'John', // Replace with first name of the user
  'Last Name' => 'Doe',  // Replace with last name of the user
  'Email' => '',  // Replace with email of the user
  ‘Custom Field' => 'custom field value',  // Replace with a custom field
  FreshsalesAnalytics::identify('', sample_contact)
rescue FreshsalesAnalytics::Exceptions => exc
  p '#{exc.err_obj}: #{exc.message}'

 If your web form has fields that aren’t in Freshsales, you can create custom fields for the same and get the values pushed to Freshsales. 

STEP 4: Track Pageviews

You can track the pages viewed in your application using trackPageView from the snippet below.



STEP 5: Track Events

You can use the snippet below to track all the in-app activities of your users like - adding users, enabling/disabling integrations, password resets, number of logins etc as Events in Freshsales.

To track events,

  1. Identify the specific call to action buttons that you’d like to be notified about. 
  2. Call the FreshsalesAnalytics::trackEvent  method from the snippet below
sample_event_properties = {
  'user email' => ''  //Replace this with the event you want to track
  FreshsalesAnalytics::trackEvent('Inviting Users', sample_event_properties)
rescue FreshsalesAnalytics::Exceptions => exc
  p '#{exc.err_obj}: #{exc.message}'


STEP 6: Update lead and contact information

The library also updates lead and contact information through web forms and visitor activity on the webapp. 

To update lead/contact information, 

  1. Call the FreshsalesAnalytics::set method from the snippet below.
contact_payment = {
 “Payment Id” => 129863,
 “Plan Name” => “2 agents”,
 “Amount”=> $2500,
 “Custom Field” => “custom field value” // Replace with a custom field
identifier = “”
  FreshsalesAnalytics::set(identifier, contact_payment)
rescue FreshsalesAnalytics::Exceptions => exc
  p '#{exc.err_obj}: #{exc.message}'