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

ARTICLE NAVIGATION

STEP 1: Getting started

  1. You can install the library using

pip install freshsales


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

 

 import FreshsalesAnalytic


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

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


  1.  Replace the "<APP URL>"and "<APP TOKEN>" with your portal url and app token. You can find it under Admin Settings > CRM Code library > Python

STEP 2: Create contacts

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

new_contact = {

'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_contact)


 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.  

STEP 3: 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 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 Freshworks CRM.

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 5: Update contact information

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

To update 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)