Server-Side Tracking Using The Gateway

You can also use the WhosOn Gateway to implement server-side visitor tracking using ASPX, ASP, PHP or any other code that executes at the server.

 

The advantages of using server-side tracking as opposed to client-side tracking using javascript are as follows:

 

- Fastest possible visitor tracking and page loads. Pages will show in WhosOn even before the visitor has seen them!

- No requirement for javascript or images to be enabled on the visitor's browser.

- Ability to track spiders and other automated bots.

- Ability to serve custom content based on operator availability and visitor GEO-IP.

- No requirement for the WhosOn Gateway to be running on a public IP address.

- Ability to track SSL pages without the requirement to assign an SSL certificate to the WhosOn Gateway.

 

If your web site is built using ASPX, ASP or PHP then server-side tracking is the recommended method of tracking visitors with WhosOn.

 

How It Works

Your server-side code makes a HTTP request to the WhosOn Gateway for the file 'stat.xml'. Since the request happens server-side, you can use 'localhost' as the Gateway address and there wont be any firewall issues. The request contains details of the visitor and page. The WhosOn Gateway returns some XML containing current operator status and optional visitor GEO-IP data. Your server-side code can then use this XML data to serve custom content (like a Click To Chat link).

 

Example HTTP Request:

 

The following HTTP request to the WhosOn Gateway will return an XML file:

 

http://localhost:8080/stat.xml?domain=www.mysite.com&auth=authentication&ip=123.123.123.123&p=page.htm&r=http://www.referrer.com

 

With all server-side calls to the Gateway you must pass the 'auth' parameter. This must be set to the Authentication string as set in your WhosOn Server settings. This is an added security measure. The 'ip' parameter must be set to the IP address of the visitor. The 'p' parameter must be set to the page name they are viewing. The 'r' parameter can be set to an optional referrer.

 

Query String Parameters

 

The following querystrings can be passed via the stat.xml request:

 

domain/d

Domain name of the site in WhosOn

dept/t

Department name (optional)

p

Page name (if no page is specified the 'home page' as defined in WhosOn site settings is assumed

auth

WhosOn Server Authentication string as defined in WhosOn settings - Remote Access section

ip

IP address of visitor

r

Referrer (optional)

u

User name (optional - if specified this value is used to track the visitor in addition to the IP address)

v

Revenue of visit (optional)

c

Cost of visit (optional)

s

HTTP status (optional) - allows you to pass page errors (404's etc) to WhosOn to show as exceptions

n

Visitor contact information (Name|Company|Email|Telephone) (optional)

 

The WhosOn Gateway will then send the visitor information to the WhosOn Server and return a XML file, in the format:

 

 

<?xml version="1.0" encoding="UTF-8" ?>

<domain>

  <online>2</online>

  <name>www.whoson.com</name>

  <message>One moment - we will be with you shortly.</message>

         <operators>

     <operator>

        <name>Daniel</name>

        <status>0</status>

        <dept>Technical Support</dept>

     </operator>

     <operator>

        <name>Stephen</name>

        <status>0</status>

        <dept>Sales</dept>

     </operator>

  </operators>

</domain>

 

The <online> tag will contain the number of operators currently online. You can use this to serve your on/off line chat link/graphic. The <message> tag contains the default 'available' message as defined by the site properties in WhosOn.

 

The <operators> tag contains a repeating section for each <operator> showing their <name>, <status> and <department>

 

Requesting GEO-IP Data

If you request 'geoip.xml' instead of 'stat.xml' in the HTTP request to the Gateway, then the WhosOn Gateway will also include GEO-IP data for the IP address passed in the 'ip' parameter in the returned XML.

 

The following tags are returned in addition to the above:

 

  <visitor>

     <ip>195.62.223.1</ip>

     <country>United Kingdom</country>

     <region>Stoke-on-Trent</region>

     <city>Keele</city>

     <organization>Routed block for Parker Software</organization>

     <lattitude>53</lattitude>

     <longitude>-2.2833</longitude>

  </visitor>

 

You could then use this data in your server-side code to serve different content based on the visitor's location.

 

License Note: You are licensed to use the GEO-IP data in this way only for your own site. You cannot use the WhosOn Gateway to serve GEO-IP data for other users or sites.

 

Using The ASPX Class

We have created a Visual Studio 2005 (Visual Basic) Class that encapsulates the HTTP call to the WhosOn Gateway and extracts the data returned. The class file is installed in the C:\Program Files\WhosOnV5\Developer\ServerSideTracking\ASPX folder.

 

To use the class, add it to your Visual Studio (or Visual Web Developer) project. Then in the Page_Load event of each page you want to monitor, add the following code:

 

Private Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

DIM PSL As New clsWhosOn

Try

   PSL.WhosOnGatewayInternalIP = "localhost"         ' set this to the IP address of the WhosOn Gateway (localhost if its on the same pc)

   PSL.WhosOnGatewayExternalIP = "gateway.mysite.com ' set this to the External IP/DNS of the Gateway (required for Invites to be served)

   PSL.WhosOnGatewayPort = 8080                      ' set to the Gateway port (8080 is the default)

   PSL.WhosOnDomain = "www.mysite.com"               ' monitored site in WhosOn

   PSL.WhosOnAuthenticationString = "myauth"         ' set to your WhosOn authentication string

   PSL.VisitPage = Page                              ' assign the 'Page' object to the 'VisitPage' property

   PSL.ReturnGEOIP = True                            ' set to True if you want GEO-IP data returned

   PSL.ServeInvite = True                            ' set to True if you want the 'invite' javascript served to the page

   ' send page view info to WhosOn

   If PSL.SendPageInfoToWhosOn = True Then

      ' page info has been sent to WhosOn

      ' the class returns operator status an GEO-IP data in the 'Response' property

      If PSL.Response.OperatorsOnLine > 0 Then

         ' here we set our 'available' content

         lblChat.Text = "Click To Chat'

      Else

         ' set the 'not available' content

         lblChat.Text = "Leave A Message"

      End If

      If PSL.Response.VisitorCountry.Length > 0 Then

         lblGeoIP = "Welcome From <br /><b>" & PSL.Response.VisitorCountry

      End If

   End If

Catch

 

End Try

 

End Sub

 

That's it! The 'SendPageInfoToWhosOn' method of the Class creates the HTTP object and sends it to the WhosOn Gateway. Data is then returned in the Response properties. You simply set the 'VisitPage' property to the current instance of the Page object.

 

The number of available operators is then returned in the Response.OperatorsOnLine property. You can then use this to hide or show your 'Click To Chat' content on your page.  You can also call the SendPageInfoToWhosOn method in response to other events (if you want to track button clicks, form submissions etc). The class also adds the 'invite' javascript function to the page response, if you set the ServeInvite property to True.

 

 

Passing Visitor Contact Information

 

You can pass visitor contact information (name, company, email & telephone) via the class. This will then show against the visitor in WhosOn and be recorded in the database. This is useful when you capture form submissions. Simply set the class properties VisitorName, VisitorCompany, VisitorEmail,VisitorTelephone prior to calling the SendPageInfoToWhosOn method.

 

 

Passing Cost & Revenue

 

Set the class properties VisitCost and VisitRevenue to numeric values prior to calling the SendPageInfoToWhosOn method to pass cost and/or revenue to WhosOn to be recorded against the visit.

 

 

Using The Class On Master Pages

 

For ASPX based web sites created with Visual Studio 2005 or Visual Web Developer, the easiest way to add server side tracking is to use Master Pages. You then add the code to the Page_Load event of the master page.

 

 

Firing Custom Javascript When Invites Are Sent

 

The class has a property called 'OnInvite'. This can be set to the name of a client-side Javascript function that will called when an Invite is sent to the visitor. This can be used to replace the standard invite response of displaying a moving graphic. You can then implement your own custom invite response. For example:

 

server-side:

PSL.OnInvite = 'MyInvite'

 

client-side:

<script>

function MyInvite()

{

Alert("Hello. This is an invite from WhosOn!");

}

</script>

 

PHP & ASP Server Side Tracking

We have also created a PHP class and sample ASP page that provides the same functionality as the ASPX class. These installed in the C:\Program Files\WhosOnV5\Developer\ServerSideTracking\ folder.

 

DotNetNuke Integration

We have also created a DotNetNuke module allowing you to integrate WhosOn live stats and chat into any DotNetNuke 4+ site. The module is installed in the C:\Program Files\WhosOnV5\ServerSideTracking\DNN folder.