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

ARTICLE NAVIGATION

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. com.freshsales.analytics.* 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 = 'john@abc.com';

 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 = 'john@abc.com';

freshsales.trackPageView(identifier, 'http://sample.com/pricing'); 

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 FreshworksCRM.

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 = 'john@abc.com';

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 = 'john@abc.com';

freshsales.set(identifier, contactPayment);

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