The Ruby library helps you track the in-app activity of customers using your web application.
|
STEP 1: Getting started
Copy this snippet and paste it in the gem file and run bundle install.
gem 'freshsales-analytics', git:'git@github.com:freshdesk/freshsales-ruby-sdk.git'
Create a .yml file and name it “fs_analytics_config.yml” in the config folder of your web app.
Copy and paste the snippet below in the .yml file you created.
app_token: ‘your freshsales app token’ url: ‘your freshsales portal url’
Replace the app_token and url with your app token and portal url. You can find it under Admin Settings > CRM Code library > Ruby
STEP 2: Track Pageviews
You can track the pages viewed in your application using trackPageView from the snippet below.
freshsales.trackPageView('/pricing.html');
STEP 3: 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.
To track events,
Identify the specific call to action buttons that you’d like to be notified about. Call the FreshsalesAnalytics::trackEvent method from the snippet below
sample_event_properties = {
'user email' => 'user@abc.com' //Replace this with the event you want to track
}
begin
FreshsalesAnalytics::trackEvent('Inviting Users', sample_event_properties)
rescue FreshsalesAnalytics::Exceptions => exc
p '#{exc.err_obj}: #{exc.message}'
endSTEP 4: Update contact information
The library also updates contact information through web forms and visitor activity on the web app.
To update contact information,
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 = “john@abc.com”
begin
FreshsalesAnalytics::set(identifier, contact_payment)
rescue FreshsalesAnalytics::Exceptions => exc
p '#{exc.err_obj}: #{exc.message}'
end