ServiceBell
Search…
Examples of Custom Behavior
Trigger ServiceBell from Buttons

Custom dial trigger

ServiceBell can be invoked by most HTML elements by adding an onclick attribute.
1
<button onclick="ServiceBell.dial()">Need live help?</button>
Copied!
Or you can listen for the click event in JavaScript.
1
var button = document.getElementById('my-button');
2
button.addEventListener("click", function() {
3
ServiceBell.dial();
4
});
Copied!

Require permission before initializing

You can take the ServiceBell.init() snippet and call it at any point, including after the user has agreed to a permission (e.g. by clicking "accept" in a modal or banner.) However, you still must keep the long part of the snippet that looks like !function... first, in order to load the ServiceBell API.
Here's an example using a jQuery dialog, but it would work with any JavaScript framework.
1
<div id="dialog-confirm" title="Receive calls?">
2
<p><span class="ui-icon ui-icon-alert" style="float:left; margin:12px 12px 20px 0;"></span>
3
Would you like to opt-in to receiving calls from our team during your session?</p>
4
</div>
5
6
<script>
7
// Inject the ServiceBell API.
8
!function(w,d){function e(e,i){w.ServiceBell.q=w.ServiceBell.q||[],w.ServiceBell.q.push([e,i])}w.ServiceBell=w.ServiceBell||["init","identify","dial","alert","bookMeeting","hide","show","expand","collapse","connect","disconnect"].reduce((function(i,n){return i[n]=function(){e(n,arguments)},i}),{});var s=d.createElement("script");s.id="service-bell-script",s.src="CDN_URL_HERE/main.js",s.async=1;var i=d.getElementsByTagName("script")[0];i.parentNode.insertBefore(s,i)}(window,document);
9
10
// Pop open jQuery dialog to confirm they're OK with being called.
11
$(function () {
12
$("#dialog-confirm").dialog({
13
resizable: false,
14
height: "auto",
15
width: 400,
16
modal: true,
17
buttons: {
18
Accept: function () {
19
ServiceBell.init("CLIENT_KEY_HERE");
20
$(this).dialog("close");
21
},
22
Decline: function () {
23
$(this).dialog("close");
24
},
25
},
26
});
27
});
28
</script>
Copied!

Handling missed calls

If you want to trigger custom behavior after a visitor tries dialing but nobody answers their request, you can listen to the sb:dialmiss event.
Here's an example that directs the visitor to the contact page if they're missed:
1
window.addEventListener("sb:dialmiss", function() {
2
window.location.href = "/contact-us";
3
});
Copied!

Show expanded widget, hide on collapse

If you want to keep the widget hidden most of the time, but expand it to let the user decide if they want to call or book a meeting (depending on availability) without immediately dialing, you can do that with a combination of ServiceBell methods and events.
1
// Show & expand the widget.
2
ServiceBell.show();
3
ServiceBell.expand();
4
5
// If the visitor closes it after expanding, hide it completely.
6
window.addEventListener("sb:collapse", () => {
7
ServiceBell.hide();
8
});
Copied!
Last modified 9d ago