The Python Library helps you track the in-app activities of your customers in your web application.
|
STEP 1: Getting started
You can install the library using
pip install freshsales
FreshsalesAnalytics package contains all the core classes needed to push analytics data. Import this package in your classes.
import FreshsalesAnalytic
Instantiate the core analytics class FreshsalesAnalytics with the snippet below
freshsales = FreshsalesAnalytics("<APP URL>", "<APP TOKEN>")
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 = '[email protected]'
freshsales.set(identifier,new_contact)
If you would like to capture additional fields in your web forms apart from those offered by default fields, create custom fields to capture and send data back to the product.
STEP 3: Track Pageviews
You can track the pages viewed in your application using trackPageView from the snippet below.
identifier = '[email protected]'
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.
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
sample_event_properties = {
'user_role' : 'admin' //Replace this with your event property
}
event_name = 'Invited new user'
identifier = '[email protected]'
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,
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 = '[email protected]'
freshsales.set(identifier,contact_payment)