The Freshworks CRM PHP Library helps you track the in-app activities of your customers using your web application.
STEP 1: Getting started
To install the library you must,
Download the latest version of Freshworks CRM Analytics.zip (analytics-1.0.0..zip)
Include FreshsalesAnalytics.php in your application
Instantiate the core analytics class FreshsalesAnalytics with the snippet below
FreshsalesAnalytics::init(array( ‘domain’ => "<APP URL>", ‘app_token’ => "<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 > PHP
STEP 2: Create contacts
You can use the snippet below to create contacts, track signups and logins.
FreshsalesAnalytics::identify(array( 'identifier' => "email@example.com", 'Last name' => "Doe", 'fs_contact' => true, 'company' => array( 'Name' => "Test Company" ) ));
STEP 3: Track Pageviews
You can track the pages viewed in your application using the snippet below.
FreshsalesAnalytics::trackPageView(array( 'identifier' => ‘firstname.lastname@example.org', //Identifier 'url' => 'http://sample.com/pricing' //Track Page URL ));
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 Freshsales.
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.
FreshsalesAnalytics::trackEvent(array( 'identifier' => ‘email@example.com', //Identifier 'name' => 'Inviting New User', //Event Name 'user_email' => 'firstname.lastname@example.org', //Custom Property 1 'prop2' => 'value2' //Custom Property 2 ));
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 FreshsalesAnalytics::identify from the snippet below.
FreshsalesAnalytics::identify(array( ‘Identifier’ => ‘email@example.com’, contactPayment => array( ‘Payment Id’ => 129863, ‘Plan Name’ => ‘2 agents’, ‘Amount’ => ‘$2500’, ‘CustomField’ => ‘Custom Field Value’ ) ));
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.