Ruby Library

The Freshsales Ruby library helps you track the in-app activity of customers in your web application. This library is open-source, so you can check it out on Github

Getting Started

  1. Copy this snippet and paste it in the gem file and run bundle install.
    Copied Copy
    1
    2
    3
    gem 'freshsales-analytics', git:'git@github.com:freshdesk/freshsales-ruby-sdk.git'
    EXPAND ↓
  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.
    Copied Copy
    1
    2
    3
    4
    app_token: "FRESHSALES_APP_TOKEN" url: "FRESHSALES_URL"
    EXPAND ↓

Replace the "FRESHSALES_URL"and "FRESHSALES_APP_TOKEN" with your app token and portal url. You can find it under Admin Settings > Integrations > Freshsales for Web > Ruby

Create Leads

You can use the identify method to create leads, track signups. You can find more details about this method's payload in identify spec

identify method syntax:

1
2
3
Freshworks CRMAnalytics::identify(user_id, properties)

identify method has the following fields:

FIELD TYPE DESCRIPTION
user_id
(Required)
String This is the unique identification that you can give to your User. Usually Database ID will be used as user_id. Refer user_id section of identify spec to know more.
properties
(Optional)
Object This contains the information you know about the user. Refer properties section of identify spec to know more.

Example identify call with hard-coded user information:

Copied Copy
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
sample_user_properties = { 'First name' => 'John', 'Last name' => 'Doe', 'Email' => 'john.doe@example.com', 'company' => { 'Name' => 'Example.com', 'Website' => 'www.example.com' } } begin Freshworks CRMAnalytics::identify('123456', sample_user_properties) rescue Freshworks CRMAnalytics::Exceptions => exc p '#{exc.err_obj}: #{exc.message}' end
EXPAND ↓

Note:
To capture website visitors as contacts instead of leads, use fs_contact in the above user payload.

You need to replace the hard-coded information in the above example call with the actual user information while calling identify. When you do so, your identify call will look like:

Copied Copy
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
sample_user_properties = { 'First name' => user.first_name, 'Last name' => user.last_name, 'Email' => user.email, 'company' => { 'Name' => user.company.name, 'Website' => user.company.website } } begin Freshworks CRMAnalytics::identify("#{user.id}", sample_user_properties) rescue Freshworks CRMAnalytics::Exceptions => exc p '#{exc.err_obj}: #{exc.message}' end
EXPAND ↓

Track Pageviews

You can use trackPageView method to track the pages that your users are viewing. You can find more details about this method in trackPageView spec

trackPageView method syntax:

1
2
3
Freshworks CRMAnalytics::trackPageView(user_id, url)

trackPageView method has the following fields:

FIELD TYPE DESCRIPTION
user_id
(Required)
String This is the unique identification that you can give to your User. Usually Database ID will be used as user_id. Refer user_id section of identify spec to know more.
url
(Required)
String Url of the page you want to track.

Example trackPageView call:

Copied Copy
1
2
3
4
5
6
7
begin Freshworks CRMAnalytics::trackPageView('123456', 'https://www.myfreshworks.com/crm/sales/libraries/ruby') rescue Freshworks CRMAnalytics::Exceptions => exc p '#{exc.err_obj}: #{exc.message}' end
EXPAND ↓

Track Events

You can use trackEvent method 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.

  1. Pick the specific call to action buttons that you’d like to be notified about.
  2. Call the trackEvent method on click of the button. You can find more details about this method's payload in trackEvent spec

trackEvent method syntax:

1
2
3
Freshworks CRMAnalytics::trackEvent(user_id, event_name, event_properties)

trackEvent method has the following fields:

FIELD TYPE DESCRIPTION
user_id
(Required)
String This is the unique identification that you can give to your User. Usually Database ID will be used as user_id. Refer user_id section of identify spec to know more.
event_name
(Required)
String The name of the event you are tracking. Refer event_name section of trackEvent spec to know more.
event_properties
(Optional)
Object This contains the additional properties you know about the event. Refer event_properties section of trackEvent spec to know more.

Example trackEvent call with hard-coded event information:

Copied Copy
1
2
3
4
5
6
7
8
9
10
11
sample_event_properties = { 'user email' => 'user@abc.com' } begin Freshworks CRMAnalytics::trackEvent('123456', 'Inviting Users', sample_event_properties) rescue Freshworks CRMAnalytics::Exceptions => exc p '#{exc.err_obj}: #{exc.message}' end
EXPAND ↓

Update Leads/Contacts

You can use the identify method to update the existing leads based on their activity in your application. Know more about How identify call works

Example identify call with hard-coded user information:

Copied Copy
1
2
3
4
5
6
7
8
9
10
11
12
13
14
sample_user_properties = { 'Payment Id' => 129863, 'Plan Name' => '2 agents', 'Amount' => $2500, 'Custom Field' => 'custom field value' } begin Freshworks CRMAnalytics::identify('123456', sample_user_properties) rescue Freshworks CRMAnalytics::Exceptions => exc p '#{exc.err_obj}: #{exc.message}' end
EXPAND ↓
Help and Support
Send us a message
Chat with us