Thursday 16 July 2009

Using SitePal for the WhosOn Chat Operator Status

I've had a few requests recently to show a SitePal rep when you are available to talk. You can do this with some custom javascript code. An extension to this is to make it so that if the SitePal is clicked, it opens the chat window.



You will have your standard embed code from SitePal - this will look like:

<script language="JavaScript" type="text/javascript" src="http://vhss-d.oddcast.com/vhost_embed_functions_v2.php?acc=100000&js=1"></script><script language="JavaScript" type="text/javascript">AC_VHost_Embed(100000,300,400,'',1,1, 100000, 0,1,0,'aaaaaaaaaaaaaaaaaaaaa',9);</script>


This is made up of two components - the loading of the javascript from the site, and the call to create the window. We want to create this window when the operator status is online.



You will also have your WhosOn code, which will look like this:

<!-- Embedded WhosOn: Insert the script below at the point on your page where you want the Click To Chat link to appear -->
<script type='text/javascript' src='http://yourwhosongateway.com/include.js?domain=www.domain.com'></script>
<script type='text/javascript' >
if(typeof sWOTrackPage=='function')sWOTrackPage();
</script>
<!-- End of embedded WhosOn -->




To prepare in your WhosOn, first upload your normal online and offline images into your website - these will no longer be used directly in WhosOn.

In your site properties -> Visitor Chat -> Display Nothing When Off Line

















This will mean that the WhosOn code will return a 1x1 pixel when offline, and we can test for this in the javascript.


We leave the first line of WhosOn code in place:




<!-- Embedded WhosOn: Insert the script below at the point on your page where you want the Click To Chat link to appear -->
<script type='text/javascript' src='http://yourwhosongateway.com/include.js?domain=www.domain.com'></script>



but we are going to override some of the other things - this is the standard custom code for execution / override of what happens when the status is returned.

<script>
function overrideLoad()
{
if (sWOImage.width == 1)
{
// show offline image
var sWOOffline = document.createElement('img');
sWOOffline.src = "/images/offline.gif";
sWOChatElement.appendChild(sWOOffline);
}
else
{
var sWOOnline = document.createElement('img');
sWOOnline.src = "/images/online.gif";
sWOChatElement.appendChild(sWOOnline);sWOChatElement.onclick=sWOStartChat;
}
}
if(typeof sWOTrackPage=='function')
{
sWOImageLoaded=overrideLoad;
sWOTrackPage();
}
</script>



Now we need to add in the call to the SitePal.


The complete code will look like:


<script language="JavaScript" type="text/javascript" src="http://vhss-d.oddcast.com/vhost_embed_functions_v2.php?acc=100000&js=1">
<!-- Embedded WhosOn: Insert the script below at the point on your page where you want the Click To Chat link to appear -->
<script type='text/javascript' src='http://yourwhosongateway.com/include.js?domain=www.domain.com'></script>
<script>
function overrideLoad()
{
if (sWOImage.width == 1)
{
// show offline image
var sWOOffline = document.createElement('img');
sWOOffline.src = "/images/offline.gif";
sWOChatElement.appendChild(sWOOffline);
}
else
{
AC_VHost_Embed(100000,300,400,'',1,1, 100000, 0,1,0,'aaaaaaaaaaaaaaaaaaaaa',9);
var sWOOnline = document.createElement('img');
sWOOnline.src = "/images/online.gif";
sWOChatElement.appendChild(sWOOnline);sWOChatElement.onclick=sWOStartChat;
}
}
if(typeof sWOTrackPage=='function')
{
sWOImageLoaded=overrideLoad;
sWOTrackPage();
}
</script>



You can see that we have called the AC_VHost_Embed function as part of the online status call.


This will mean that your SitePal will show, and it will normally say something like "click below to chat to us" or "click the 'online' link on the right to chat to us"

You can also get the scene to directly send someone to the chat when it is clicked on.
First, we need to generate the click link in WhosOn - go to site properties -> visitor chat -> manual links, and you will get a cut & paste link like:

<a href="https://chatserver.whoson.com/chat/chatstart.htm?domain=www.domain.com" onclick="javascript:window.open('https://chatserver.whoson.com/chat/chatstart.htm?domain=www.domain.com','wochat','width=484,height=361');return false;">Click To Chat</a>


You only need the href part of this:
https://chatserver.whoson.com/chat/chatstart.htm?domain=www.domain.com

Then, when you are creating the scene in SitePal, if you go to the Scene Options, then put the href part of the link into the URL: box.

Then you need to check "clicking on the scene opens the link", and the "open in new window" option. Now when someone clicks on your new SitePal scene, it will open up the WhosOn chat window.

You can see the areas for this in the SitePal User Guide, section 2.5

Friday 17 April 2009

Using WhosOn in your Blogspot Blog.

I've decided to add tracking & chat to my blog here, partially as an excercise in how to do it and also for vanity purposes... although the small number of human visitors is always a disappointment!


In the WhosOn client, generate the tracking code. It will look like this:

<script type='text/javascript' src='http://{your-gateway}/include.js?domain={your-domain}'></script><script type='text/javascript' >if(typeof sWOTrackPage=='function')sWOTrackPage();</script>


Add an HTML/Javascript Gadget to the bottom of your blog Layout, and paste this code into it.


Then, you can add another Gadget to show the chat link - I put a new HTML/Javascript Gadget on the left hand side, and put in:

<a id='whoson_chat_link'></a>


The WhosOn code dynamically replaces this link with the correct image (online / offline).


If you only want to track, then you can generate the tracking only code through the client - you don't need to put the anchor in the left if you do this.

Wednesday 15 April 2009

WhosOn V5 - Scripts


WhosOn Version 5 (http://www.whoson.com/v5whatsnew.aspx) has some great new features for users who want more advanced chat distribution among their agents.

We've used a VBScript compatible engine, which allows the script to access the data about the visitor (IP, Geo-Location, #Visits etc) and any pre-chat survey information that has been filled in, and use this to route the chat to the correct operator, send some automatic text, or cancel / block the chatter.

This means dynamic rules can be used to find existing customers, and pass through to the right sales person based on a database query, or just get the lead to the correct person immediately, rather than having to do a manual transfer after the event.

I'm working with some of our customers to provide the custom logic for what they need - here is the first example I have worked on:



Sub Main()
    ' commands start here
    CancelChatRequest = False
    Dim ticket As String
    Dim tr As String
    Dim p As Integer

    tr = ThisChatSession.PreChatSurvey

    p = InStr(1, LCase(tr), "ticket")
    If p > 0 Then
        p = InStr(p, tr, "") + 7
        ticket = Left(Mid(tr, p), InStr(p, tr, "") - p)
        AddToLog("Ticket: "  & ticket)

        Dim conn As New ADODB.Connection
        Dim adors As New ADODB.Recordset

        conn.ConnectionString = "DSN=Tickets;"
        conn.Open

        Set adors.ActiveConnection = conn

        With adors
            .Open("SELECT * FROM Tickets WHERE TicketNo = '" & ticket & "'")
            If Not .EOF Then
                Dim op As String
                op = LCase(.Fields("Operator"))
                ' check if operator is online
                For p = 0 To OperatorsConnectedCount - 1
                    If op = LCase(Operator(p).Name) And Operator(p).CurrentStatus <>
                        ' if operator is online or busy, send this chat to them
                        SendChatRequestToOperators = op
                        SendMessageToVisitor = "You are being connected to the assigned user for this issue - " & op
                        AddToLog("Script: Operator for issue online: " & op)
                        p = OperatorsConnectedCount
                    End If
                Next p

                If Not Len(SendChatRequestToOperators) > 0 Then
                    SendMessageToVisitor = "The operator (" & op & ") assigned to this issue is not online - transfering to Support"
                    AddToLog("Script: Operator for issue not online: " & op)
                    SendChatRequestToDepartments = "Support"
                End If
            Else
                SendMessageToVisitor = "The ticket number was not found - transfering to Support"
                AddToLog("Script: The ticket number was not found")
                SendChatRequestToDepartments = "Support"
            End If
            .Close
        End With

        Set adors = Nothing
        conn.Close
        Set conn = Nothing
    Else
        SendChatRequestToDepartments = "Support"
    End If

End Sub