Server-side or client-side web analytics (part 2)
What most people don’t know is that client-side scripting doesn’t normally allow for any recording of data. Javascript can’t write data to a file and that is why it needs a way to transfer the data to a server-side script that records it to a database or log file. So web analytics is in absolute sense always server-side.
In this part of the article I will explain how you get server-side information into client-side statistics and vice versa.
- Part 1: What is the difference between server-side and client-side
- Part 2: How to combine server- and client-side webanalytics (this article)
Part 2: How to combine server- and client-side webanalytics
Google Analytics
For an explanation how client-side web analytics works, I will use the most common one “Google Analytics” as an example. Tools like Google Analytics work with a Javascript that requests an image. The image request is interpreted by a server-side script that creates the log files (and it always returns the same image to the visitor). The log files are then interpreted by a program that creates all kinds of fun statistics, for people to interpret into the visitor behavior they want to research.
Because the Javascript and the image are requested from Google servers with Javascript (their browser), the visitor comes in direct contact with those servers and leaves the much needed extra information that javascript cannot detect. This primarily includes visitor IP address and Google cookie. The Google cookie also links to language preferences and other data not available in other web analytics tools.
Because the Javascript is located on google.com that may be listed as a trusted domain in the browser, it could fall under lower safety restrictions and recieve more information. Governmental agencies sometimes have very strict Javascript settings and Google is often one of the exceptions (I just can’t imagine why).
Communication from server-side to client-side
PHP and Javascript have several common grounds where they can exchange data.
- Javascript and PHP can both read and write the same cookies.
- Javascript and PHP can both generate and read URLs and extract GET variables.
- Javascript and PHP can both generate and read POST variables.
- Javascript can read and PHP can read/generate text files or XML files.
- Javascript can be generated by PHP.
Server-side information in Google Analytics
Just a few examples of server-side data that you might want in Google Analytics or other client-side web analytics programs.
- Your internal client ID.
- Real e-commerce sales.
- Files and visitors without Javascript support.
So how do you get it there?
Your internal client ID
If someone is logged in to your system you can identify that visitor, but how do you get that data in your Analytics report? … Lets say you have a variable $strClientID. You can enter it as the Google Analytics “user defined” variable by doing the following:
<script src="http://www.google-analytics.com/urchin.js" type="text/javascript"></script>
<script type="text/javascript">
_uacct = "UA-000000-0";
__utmSetVar(’<?php echo $strClientID;?>’);
</script>
Real e-commerce sales
When you enable e-commerce tracking in Analytics you can communicate every product and every transaction to Google.
Look at this text file to see how it is done.
For more information look at
http://www.google.com/support/googleanalytics/bin/answer.py?answer=55528
Files and visitors without Javascript support
Look at this post about Google Analytics without Javascript. This requires some PHP skill, but you can probably add your own functionality to the script I’ve made. I’ve made 20 different versions for different functionality, so I won’t bother you with all of them.
The only drawback is that I’d recommend using a separate profile because all visits are logged on the IP address of your hosting provider. In analytics software “Webtrends” I did the same and then you can enter the IP and data of the client provided by your own PHP script.
Summing it up
There are several ways to communicate server-side data to javascript and thereby to Google analytics and other client-side web analytics.
I’d recommend on using client-side web analytics tools and server-side support for extra data. This is the most trustworthy to get the data you need to make sound assumptions about your visitors.
August 16th, 2007 at 8:17 pm
[…] - server-side and client-side web analytics - unobtrusive click assignments for Google Analytics - Google Analytics without javascript […]