PHP Library

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

Getting started

To install the library you must,

  1. Download the latest version of PHP library zip here
  2. Unzip the Library and add Freshworks CRMAnalytics.php in your project.
  3. Instantiate the core analytics class Freshworks CRMAnalytics with the snippet below
    Copied Copy
    1
    2
    3
    4
    5
    6
    Freshworks CRMAnalytics::init(array( 'domain' => "FRESHSALES_URL", 'app_token' => "FRESHSALES_APP_TOKEN" );
    EXPAND ↓

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 > PHP.

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 has the following fields:

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

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
Freshworks CRMAnalytics::identify(array( 'identifier' => $user->id, 'First name' => $user->first_name, 'Last name' => $user->last_name, 'Email' => $user->email, 'company' => array( 'Name' => $user->company_name, 'Website' => $user->company_website ) ));
EXPAND ↓

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 has the following fields:

FIELD TYPE DESCRIPTION
identifier
(Required)
String This is the unique identification that you can give to your User. Usually Database ID will be used as identifier. 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
4
5
6
Freshworks CRMAnalytics::trackPageView(array( 'identifier' => '123456', 'url' => 'https://www.myfreshworks.com/crm/sales/libraries/php') );
EXPAND ↓

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 has the following fields:

FIELD TYPE DESCRIPTION
identifier
(Required)
String This is the unique identification that you can give to your User. Usually Database ID will be used as identifier. Refer user_id section of identify spec to know more.
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
Freshworks CRMAnalytics::trackEvent(array( 'identifier' => '123456', 'name' => 'Inviting Users', 'user email' => 'user@abc.com' ));
EXPAND ↓

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 work

Example identify call with hard-coded user information:

Copied Copy
1
2
3
4
5
6
7
8
9
10
11
Freshworks CRMAnalytics::identify(array( 'identifier' => '123456', sample_properties => array( 'Payment id' => 129863, 'Plan name' => '2 agents', 'Amount' => 2500, 'Alternate contact number' => '98765432' ) ));
EXPAND ↓
Help and Support
Send us a message
Chat with us