Tips & Tricks: Chat Icon Callbacks (JavaScript)

JavaScript callbacks are custom JavaScript code that can be processed for various chat icon and chat window actions. If your webpage contains these callbacks, the PHP Live! system will call those functions. Include your custom code inside the callback functions. The following callbacks are available:
Chat icon has loaded
When the chat icon has loaded on the page, this function will be called if it exists on the page:
phplive_callback_loaded( department_id, online_offline_status )
    Function Parameters
  • department_id = the department ID the chat icon references
  • online_offline_status = the chat icon status (1 is online, 0 is offline)
Example:
function phplive_callback_loaded( department_id, online_offline_status )
{
	var status = ( online_offline_status == 1 ) ? "online" : "offline" ;
	alert( "Chat icon has been loaded for department ID " + department_id + " and the status is " + status ) ;
}
Chat icon has been clicked
When the chat icon is clicked, this function will be called if it exists on the page:
phplive_callback_launchchat( online_offline_status, department_id )
    Function Parameters
  • online_offline_status = the chat icon status (1 is online, 0 is offline)
  • department_id = the department ID the chat icon references
Example:
function phplive_callback_launchchat( online_offline_status, department_id )
{
	var status = ( online_offline_status == 1 ) ? "online" : "offline" ;
	alert( "Chat icon has been clicked for department ID " + department_id + " and the status is " + status ) ;
}
Chat icon status is online
After the chat icon has loaded and the status is online, this function will be called if it exists on the page:
phplive_callback_online( department_id )
    Function Parameters
  • department_id = the department ID the chat icon references
Example:
function phplive_callback_online( department_id )
{
	alert( "Chat status is ONLINE for department ID " + department_id ) ;
}
Chat icon status is offline
After the chat icon has loaded and the status is offline, this function will be called if it exists on the page:
phplive_callback_offline( department_id )
    Function Parameters
  • department_id = the department ID the chat icon references
Example:
function phplive_callback_offline( department_id )
{
	alert( "Chat status is OFFLINE for department ID " + department_id ) ;
}
The visitor minimizes the chat window (embed chat)
When the embed chat window is minimized, this function will be called if it exists on the page:
phplive_callback_minimize()
    Function Parameters
  • none
Example:
function phplive_callback_minimize()
{
	alert( "Embed chat has been minimzed." ) ;
}
Note: If chat window is minimized and the visitor navigates to another page, this function will be called on the next page because the chat window has been loaded, in minimized state.
The visitor maximizes the chat window (embed chat)
When the embed chat window is maximized, this function will be called if it exists on the page:
phplive_callback_maximize()
    Function Parameters
  • none
Example:
function phplive_callback_maximize()
{
	alert( "Embed chat has been maximized." ) ;
}
Note: If chat window is maximized and the visitor navigates to another page, this function will be called on the next page because the chat window has been loaded, in maximized state.
The visitor closes the chat window (embed chat)
When the embed chat window is closed, this function will be called if it exists on the page:
phplive_callback_close()
    Function Parameters
  • none
Example:
function phplive_callback_close()
{
	alert( "Embed chat has been closed." ) ;
}
Note: If you have multiple chat icon HTML codes that reference different department IDs on the same page, the callbacks will process for the first HTML code that has loaded. The chat icons load asynchronous, meaning the multiple chat icons on the same page will load in a different order for each page load.
Tips & Tricks
  • CSS Open Chat - Reference the open chat function using CSS class within the span, div or link.
  • Custom Variables - Pre-populate the name, email and question or send your custom variables to the chat request window.
  • Transcript Action - When the chat session ends, process your custom PHP code to performan your custom actions.
  • Custom Console - Inject custom code to the operator console to add your custom widgets, actions and more.