The Java Library helps you track the in-app activities of your customers using your web application.


STEP 1: Getting started

To install the library you must,

  1. Download the latest version of Freshsales Analytics jar (analytics-1.0.0.jar).

  2.* package contains all the core classes needed to push analytics data. Import this package in your java classes.

  3. Instantiate the core analytics class FreshsalesAnalytics with the snippet below

FreshsalesAnalytics freshsales = new FreshsalesAnalytics("<APP URL>", "<APP TOKEN>");

      4. Replace "<APP URL>"and "<APP TOKEN>" with your portal url and app token under 

Admin Settings > CRM Code Library > Java 

STEP 2: Create contacts

You can use freshsales.set from the snippet below to create contacts, track signups and logins.

JSONObject newLead= new JSONObject();

 newLead.put('Last name', 'John');

 newLead.put('fs_contact', true);

 JSONObject company = new JSONObject();

 company.put('name', 'Test Company');

 newLead.put('company', company);

 String identifier = '';

 freshsales.set(identifier, newLead);

STEP 3: Track Pageviews

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

String identifier = '';

freshsales.trackPageView(identifier, ''); 

STEP 4: 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 your web application.

To track events, 

  1. Identify the specific call to action buttons that you’d like to be notified about. 

  2. Call the trackEvent method from the snippet below.

String identifier = '';

String eventName = 'Inviting new User';

JSONObject eventProperties = new JSONObject();

eventProperties.put('user_role', 'admin'); //Replace this with your event property

freshsales.trackEvent(identifier, eventName, eventProperties);

STEP 5: Update contact information

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

To update contact information,

Call freshsales.set from the snippet below.

JSONObject contactPayment= new JSONObject();

contactPayment.put('Payment Id', 129863);

contactPayment.put('Plan Name', '2 agents');

contactPayment.put('Amount', '$2500')

contactPayment.put('CustomField', 'custom field value'); // Replace with a custom field

      String identifier = '';

freshsales.set(identifier, contactPayment);

Create custom fields to capture information that cannot the captured using the default fields.