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


STEP 1: Getting started

  1. You can install the library using
pip install freshsales

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

   import FreshsalesAnalytics

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

freshsales = 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 > Python




STEP 2: Create leads and contacts

You can use the snippet below to create leads, track signups and logins.

new_lead = {
  'First name' : 'John', // Replace with first name of the user
  'Last name' : 'Doe',  // Replace with last name of the user
  'Custom Field' : 'custom field value'// Replace with a custom field
}
identifier = 'john@abc.com'
freshsales.set(identifier,new_lead)

 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. 




STEP 3: Create contacts

To create contacts, use the snippet below.

new_lead = {
  'First name' : 'John', // Replace with first name of the user
  'Last name' : 'Doe',  // Replace with last name of the user
  'fs_contact' : true,
  'Custom Field' : 'custom field value'// Replace with a custom field
}
identifier = 'john@abc.com'
freshsales.set(identifier,new_lead)

 



STEP 4: Track Pageviews

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

identifier = 'john@abc.com'
freshsales.trackPageView(identifier, '/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,

  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
sample_event_properties = {
 'user_role' : 'admin' //Replace this with your event property
}
event_name = 'Invited new user'
identifier = 'user@abc.com'
freshsales.trackEvent(identifier,event_name,event_properties)

 



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, 

  1. Call the 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'
freshsales.set(identifier,contact_payment)