Server-side or client-side web analytics (part 1)
When implementing web analytics programs I sometimes get the question why I use a combination of PHP/ASP and Javascript. What they probably don’t know is that server-side and client-side scripting can detect different specifics of a visit. Both types have advantages and disadvantages, but you need certain tricks to combine both. This article explains the differences and how to overcome their disadvantages. It is mainly written for people that know something about scripting, but need a quick reminder to fix certain problems.
- Part 1: What is the difference between server-side and client-side (this article)
- Part 2: How to combine server- and client-side webanalytics
Part 1: What is the difference between server-side and client-side
What does client-/server-side mean?
To explain the difference between server-side en client-side analytics, I first need to explain the difference between server-side and client-side scripting..
- Client-side scripting means all calculations are done by the computer of the visitor. Most of the time the script is interpreted by their internet browser (Javascript) or a specific browser plugin (Flash actionscript).
- Server-side scripting means all calculations are done by the server your website is hosted on. The script is interpreted by the supported language parser, like PHP or ASP.
What can be detected?
Many factors like security issues have led to restrictions in both server- and client-side possibilities. Javascript isn’t even made to be able to communicate back to a webserver, but certain tricks have led to client-side webanalytics and Ajax. Therefore some types or information are only available in Javascript and some information can only be retrieved by PHP. The following table shows information available in both types and the main restrictions.
| Client | Server |
|---|---|
| Browser properties | Server/site/page properties |
| Page element properties | Connection properties |
| Change possible on any interaction | Change requires reload |
| Read-only access to external files | Many communication possibilities |
| Entire script source visible | Script source hidden for visitor |
| Restrictions based on browser security- and support settings. | Restricted by server settings |
| Client support required | All requests are counted |
Client-side summary
Languages like Javascript can detect what browser you are using, your screen size, plugin support and much more. But that may be restricted by the security level you set for your browser. It can also detect and change any property of the page (like the width and background-color of a table) you are watching and change it on the fly, based on any type of detected interaction. This interaction can even be a slight mouse movement or the press of a key.
The javascript source code can be read with any text editor, so don’t place passwords within them. But information a user enters remains client-side (minimizes server load) and normally isn’t send to any server. But there are ways to send information to the server-side.
Depending on the security settings in your browser, javascript can request and read external files like XML feeds. To circumvent stricter security settings, javascript may also request images; And that is what is exploited by many client-side web analytics programs like Google Analytics. The requested file/image URL can be stuffed with information, so the server can retrieve these GET variables from there.
p.s. Javascript can also vacate forms and send them and it can also read/write cookies to communicate with other files.
Javascript web analytics only logs visitors that support this language, in files that allow javascript execution.
Server-side summary
Languages like PHP can request (and change) any property of the webpage it is on and any variable used to while compiling the resulting HTML code. It can also see properties of the connection between visitor and server and unlike Javascript it can detect the IP address. Any change requires a reload or new page request, which requires more loading and a client-side action (can be from both a user or client-side script).
Server-side scripting code can’t be read by visitors, so no one can steal your script and no client support is needed. The calculations are done by the server, so more visitors means more server-load. Different server-side languages, plugins and external data can supplement eachother and the only thing that counts is the end result.
Languages like PHP offer numerous ways to communicate with other servers and files across the web and no one will ever know what was required to compile the data. When a website is hosted on a shared server, the possibilities of server-side can be somewhat limited, but on a dedicated server the only programming limitations are posed by server-load, software licenses and your own technical capabilities.
Standard server-side web analytics is based on server logs. This is a very limiting way of measuring visits and you need many filters to drop search engine robot requests and other non-human visits. But Javascript can’t detect non-human visitors at all.
So how do you combine both in your analytics reports?
How do you get customer information in a javascript web analytics tool? How do you log commerce sales? How do you log search engine robot visits? How do you track requests of images, PDF files or your RSS feed?
All these questions are answered in:
Part 2: How to combine server- and client-side webanalytics