Python Library

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

Getting Started

  1. Download the latest version of Python library here
  2. Unzip the Library and add "freshsales" folder of the library in your project.
  3. Freshworks CRMAnalytics package contains all the core classes needed to push analytics data. Import this package in your classes.
  4. Freshworks CRMAnalytics package contains all the core classes needed to push analytics data. Import this package in your classes
    Copied Copy
    1
    2
    3
    from freshsales import Freshworks CRMAnalytics
  5. Instantiate the core analytics class Freshworks CRMAnalytics with the snippet below
    Copied Copy
    1
    2
    3
    freshsales = Freshworks CRMAnalytics("FRESHSALES_URL", "FRESHSALES_APP_TOKEN")

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

Create 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(user_id, properties)

identify method has the following fields:

FIELD TYPE DESCRIPTION
user_id
(Required)
String This is the unique identification that you can give to your User. Usually Database ID will be used as user_id. 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
sample_user_properties = { 'First name': 'John', 'Last name': 'Doe', 'Email': 'john.doe@example.com', 'company': { 'Name': 'Example.com', 'Website': 'www.example.com' } } freshsales.identify('123456', sample_user_properties)

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
sample_user_properties = { 'First name': user.first_name, 'Last name': user.last_name, 'Email': user.email, 'company': { 'Name': user.company.name, 'Website': user.company.website } } freshsales.identify(str(user.id), sample_user_properties)

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(user_id, url)

trackPageView method has the following fields:

FIELD TYPE DESCRIPTION
user_id
(Required)
String This is the unique identification that you can give to your User. Usually Database ID will be used as user_id. 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/python')

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(user_id, event_name, event_properties)

trackEvent method has the following fields:

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

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 works

Example identify call with hard-coded user information:

Copied Copy
1
2
3
4
5
6
7
8
9
10
sample_user_properties = { 'Payment Id': 129863, 'Plan Name': '2 agents', 'Amount': $2500, 'Custom Field': 'custom field value' } freshsales.identify('123456', sample_user_properties)
Help and Support
Send us a message
Chat with us