Java Library

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

Getting Started

To install the library you must,

  1. Download the latest version of Java library zip here
  2. Unzip the Library and add analytics-1.0.0.jar in the classpath of the your project.
  3. com.freshsales.analytics.* package contains all the core classes needed to push analytics data. Import this package in your java classes
  4. Instantiate the core analytics class Freshworks CRMAnalytics with the snippet below
    Copied Copy
    1
    2
    3
    Freshworks CRMAnalytics freshsales = new Freshworks CRMAnalytics("FRESHSALES_URL", "FRESHSALES_APP_TOKEN");
    EXPAND ↓

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

Creat 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
freshsales.identify(userId, properties);

identify method has the following fields:

FIELD TYPE DESCRIPTION
userId
(Required)
String This is the unique identification that you can give to your User. Usually Database ID will be used as userId. 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
JSONObject sample_user_properties = new JSONObject(); sample_user_properties.put("First name", "John"); sample_user_properties.put("Last name", "Doe"); sample_user_properties.put("Email", "john.doe@example.com"); JSONObject company = new JSONObject(); company.put("Name", "Example.com"); company.put("Website", "www.example.com"); sample_user_properties.put("company", company); freshsales.identify("123456", sample_user_properties);
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
JSONObject sample_user_properties = new JSONObject(); sample_user_properties.put("First name", user.first_name); sample_user_properties.put("Last name", user.last_name); sample_user_properties.put("Email", user.email); JSONObject company = new JSONObject(); company.put("Name", user.company.name); company.put("Website", user.company.website); sample_user_properties.put("company", company); freshsales.identify(user.id, sample_user_properties);
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
freshsales.trackPageView(userId, url)

trackPageView method has the following fields:

FIELD TYPE DESCRIPTION
userId
(Required)
String This is the unique identification that you can give to your User. Usually Database ID will be used as userId. 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
freshsales.trackPageView("123456", "https://www.myfreshworks.com/crm/sales/libraries/java");
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
freshsales.trackEvent(userId, eventName, eventProperties)

trackEvent method has the following fields:

FIELD TYPE DESCRIPTION
userId
(Required)
String This is the unique identification that you can give to your User. Usually Database ID will be used as userId. Refer user_id section of identify spec to know more.
eventName
(Required)
String The name of the event you are tracking. Refer event_name section of trackEvent spec to know more.
eventProperties
(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
JSONObject sampleEventProperties = new JSONObject(); sampleEventProperties.put("user email", "user@abc.com"); freshsales.trackEvent("123456", 'Inviting Users', sampleEventProperties);
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 work

Example identify call with hard-coded user information:

Copied Copy
1
2
3
4
5
6
7
8
9
JSONObject sampleUserProperties = new JSONObject(); sampleUserProperties.put("Payment id", 129863); sampleUserProperties.put("Plan name", "2 agents"); sampleUserProperties.put("Amount", 2500); sampleUserProperties.put("Alternate contact number","98765432"); freshsales.identify("123456", sampleUserProperties);
EXPAND ↓
Help and Support
Send us a message
Chat with us