The Javascript library helps you identify the people on your website (contacts), tracks their activities in real-time, gives you a history of their past activities, and the pages they have viewed. 

  1. Getting started

    1. Copy the snippet from Admin Settings > Leads, Contacts, & Accounts > CRM Code library > Javascript, which is prefilled with your freshsales_portal_url and authentication_token.

    2. Or, replace freshsales_portal_url and authentication_token in the below snippet with your portal’s URL and Authentication token and copy it.

<script> function createTempFunction(function_name) { (window.freshsales)[function_name]=function() { (window.freshsales).push([function_name].concat(Array.prototype.slice.call(arguments,0))) }; } (function(url, app_token) { window.assets_url='//d952cmcgwqsjf.cloudfront.net'; window.freshsales = window.freshsales || []; functions_list='init identify trackPageView trackEvent set'.split(' '); for(var i=0; i < functions_list.length; i++) { var function_name = functions_list[i]; createTempFunction(function_name); } var script_tag = document.createElement('script'); script_tag.async=1; script_tag.src= window.assets_url +'/assets/analytics.js'; var first_script_tag = document.getElementsByTagName('script')[0]; first_script_tag.parentNode.insertBefore(script_tag,first_script_tag); freshsales.init(url, app_token); })('freshsales_portal_url','authentication_token'); </script>

Null

 

    1. Paste the library on the HTML header of your website.

  1. Create contacts

Capture website visitors as contacts using fs_contact,

  1. Replace the element ID’s with the actual field ID’s of your web form.

  2. After web form’s submission and validation, call identify method

var identifier = $("#email").val(), contact_properties = { "fs_contact" : true, "First name" : $("#first_name").val(), "Last name" : $("#last_name").val(), "Date Of Birth" : $("#dob").val(), "company" : { "Name" : $("#company_name").val(), "Website" : $("#compan_website").val() } }; freshsales.identify(identifier, contact_properties);

Null


Note: 
1. The library also tracks their activities before and after signing up, and displays it in the details page.
2. If your web form has fields that aren’t provided by default, create custom fields for the same and get the values pushed to your application. For example the Date Of Birth field can be created as a custom field of with type date picker. 
  1. Track Pageviews 

The library pasted on your HTML header gets embedded in all the web pages and tracks them as soon as the library is initialized. 


However, if yours is a single page application, call  freshsales.trackPageView(“<URL of the Page>”);

Null

in the individual pages on your website to track pageviews. 

  1. Track Events

Track visitor activities on your website - like downloading a white-paper, clicking on the social profiles’ follow buttons - as events in your web application.


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.

var sample_event_properties = { 'title': 'How to win more sales' // Replace with title of the whitepaper }; freshsales.trackEvent('Downloaded White paper', sample_event_properties);

Null


  1. Update contact information

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

To update contact information, 


Call the set method from the snippet below.

var sample_properties = { 'Address': '8691 MacGyver Mews', // Replace with address of user 'City': 'New Jermaine', // Replace with city of user 'Mobile': '13457879', // Replace with mobile number of user 'Custom Field': 'custom field value' // Replace with a custom field }; freshsales.set(sample_properties);

Null


  • Every time a form is submitted or an action performed, the email address of that user is searched for matches to prevent duplicates.

  • If a match is found in the contacts, all the details submitted in the web form are filled in that contact’s record.

  • In the event of multiple matches, the data is associated with the record with the most recent activity.