The Freshsales 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,
- Download the latest version of Freshsales Analytics jar (analytics-1.0.0.jar)
- com.freshsales.analytics.* package contains all the core classes needed to push analytics data. Import this package in your java classes.
- Instantiate the core analytics class FreshsalesAnalytics with the snippet below
FreshsalesAnalytics freshsales = new FreshsalesAnalytics("<APP URL>", "<APP TOKEN>");
4. Replace the "<APP URL>"and "<APP TOKEN>" with your portal url and app token. You can find it under Admin Settings > Integrations > Freshsales for web > Java
STEP 2: Create leads
You can use the snippet below to create leads, track signups and logins.
JSONObject newLead= new JSONObject(); newLead.put('Last name', 'John'); JSONObject company = new JSONObject(); company.put('name', 'Test Company'); newLead.put('company', company); String identifier = 'john@abc.com'; freshsales.set(identifier, newLead);
STEP 3: 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 4: 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 5: 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 Freshsales.
To track events,
-
Identify the specific call to action buttons that you’d like to be notified about.
-
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 6: Update lead and contact information
The library also updates lead and contact information through web forms and visitor activity on the web app.
To update lead/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 Freshsales, you can create custom fields for the same and get the values pushed to Freshsales.