How to send more info about visitors to HappyFox Chat?

Custom field is a mechanism to pass more data about visitors from your website to HappyFox Chat. Your visitors don't have to enter these data. You can send it via a JavaScript SDK.

This feature is available from Mighty plan and above.

Let us say you are running an eCommerce website. A registered user is visiting your website or initiating a chat. If you want to pass the subscription plan details of the user or number of orders placed previously, to HappyFox Chat, custom field enables that for you.

Step 1: How to add custom fields?

Custom fields can be created in "Custom Fields" section under "Manage" tab of your HappyFox Chat Account.

Click on "Add" button. Enter name of the custom field.
 


Text and Number are the two types of custom field types available. Choose any of the values and click on "Save" button.

Step 2: How to pass values to custom fields?

Custom fields can be passed from your website to HappyFox Chat using a JavaScript code snippet. 

Syntax:

HappyFoxChat.setCustomFields(<customFieldObject>, <callback>);
  • <customFieldObject> is a mandatory argument. JSON object with the custom fields created in step 1.
  • <callback> is an optional argument.

Example:

HappyFoxChat.setCustomFields( { Plan :'free'} )

Here is sample snippet of code to set some example custom fields (pastOrders and subscriptionPlan with values 30 and 'free' respectively): 

<script>
var HappyFoxChat;
window.HFCHAT_CONFIG.onload = function() {
  /**
   * Getting the reference of HappyFoxChat object
   */
  HappyFoxChat = this;
  /**
   * Custom fields
   */
  var customFields = {
    pastOrders: 3,
    Plan: 'free'
  };
  /**
   * Setting custom fields
   */
  HappyFoxChat.setCustomFields(customFields, function(error, result) {
    if (error) {
      console.error('Failed to set custom fields', error);
    } else {
      console.log('Successfully set custom fields', result);
    }
  });
};
</script> 

Step 3: How to filter visitors using custom field?

In "Visitors" tab, click on "By Filter" section.

Select "Add filter" option from the drop down list.

After setting filter name, set the necessary condition using the custom field. Visitors matching the conditions in the filter will be displayed.

Custom fields details will be displayed in the following areas,

1. Agent Chat Interface

On clicking custom fields,

2. History > Chat transcripts

3. History > Offline messages