A Developers Blog: LiveEngage - Use Your Own Custom Chat Button By Using JQuery

This blog has moved to GitHub, and you should be redirected shortly...

Wednesday, January 13, 2016

LiveEngage - Use Your Own Custom Chat Button By Using JQuery

Update: With the new HTML engagements in LiveEngage, this method is now outdated. It is recommended that you use the supported method listed above.

The purpose of this tutorial is to show you how you can use your own chat buttons with LiveEngage by using JavaScript.

Currently in LiveEngage, you have a limited number of options for creating a chat button in the LiveEngage studio. This can make it hard for the chat button to match the look of your site, especially with all of the things you can do with CSS and JavaScript today.

So, in order to work around this,you will need to create your own chat that you would like to use on your website, and you will need to create a basic embedded chat button in the LiveEngage studio. Don't worry about what the embedded chat button looks like because we are going to use CSS styling to hide the chat button, and then use JavaScript to click the LiveEngage chat button when your button is clicked.

If you have created both buttons, then we can get started.

1. The first thing you will want to do is add the div for your LiveEngage chat button to your site to make sure it works.

2. Now, we are going to wrap this div inside an anchor tag with a class, which is what we are going to use to trigger the click on the chat button. For example, if your LiveEngage div is: <div id="slideout1"></div>, your code will look like this now:

<a class="live-person-ghost"><div id="slideout1"></div></a>

3. Next, we are going to add an id to our custom button. By adding an id, it will allow use to check to see if that button was clicked. Here is an example:

<button type="button" id="live-engage-link">Instant Live Chat</button>

4. If you do not have JQuery on your website, you will need to add the following script to the head section of your site:

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js"></script>

4. Now, we are going to add the JavaScript that will allow us to trigger the click on the LiveEngage button when someone clicks on your custom chat button. Add the following code before your closing body tag:

5. Now that you have added the JavaScript, we can test the code to make sure it works. If you click on your custom chat button, and it triggers the LiveEngage chat button, then the last thing we need to do is hide the LiveEngage chat button. You will need to add the following style to your LiveEngage div: style="display:none".

Here is a complete example of the code:

Summary: This tutorial showed you how to use JavaScript and CSS to use your own custom chat buttons with LiveEngage.

I hope you enjoyed this tutorial. If you have any questions or comments, please feel free to post them below.

Labels: , ,

4 Comments:

At April 15, 2016 at 2:52 PM , Blogger jazikat05 said...

Hey Scott, great article. If I wanted to create a second button further down the page that looks different than the button installed in my header, would I code that the same way? I know each button has a different ID, but I just wanted to make sure it wouldn't change both of them. Thanks!

 
At April 17, 2016 at 6:35 PM , Blogger Scott Westover said...

Hi Jazikato5,

Yes, you would code it the same way. The only extra thing you would need to to do is inside the JavaScript, you would want to make an extra copy of click function and update it with the other div id. For example instead of: $('#live-engage-link').click(function(e) {}, it would be $('#otherdivid').click(function(e) {}.

 
At June 16, 2016 at 6:35 AM , Anonymous Hasan said...

Hi Scott,

Thanks for publishing great articles. I have a question regarding the pre-survey forms, is it possible to auto populate the pre survey form based on customer's login details for example?

 
At July 30, 2016 at 8:32 PM , Blogger Scott Westover said...

Hi Hasan,

This is something that could be done by using some on page JavaScript and the lpEvents binding code that is available. The lpEvents binding code would allow for you to track when someone clicks on the chat button, and once then track when the pre-chat survey is presented.

You could then from there you JavaScript to populate the form with the proper data.

Have you looked into passing the customer's login details through the Engagement Attributes that are available?

Sincerely,

Scott

 

Post a Comment

Subscribe to Post Comments [Atom]

<< Home