[thelist] [tip] recording visitor's window sizes

Erik Mattheis gozz at gozz.com
Fri Mar 8 18:42:01 CST 2002


<tip type="recording visitor's window sizes" author="Erik Mattheis">

If you want to know the sizes of your visitor's windows, you can do
something like this:

IMPORTANT: the script must either be below the <body> tag or in a
function which is called onload or document.body will be undefined:

<script language="JavaScript" type="text/javascript">
<!--
// set defaults
width = 0;
height = 0;

// set how to accurate you want to record the results
// 25 will group window widths between 625 and 650
// as one group, etc.
increment = 25;

// find window width
if (document.body && document.body.clientWidth) {
	width = document.body.clientWidth;
	height = document.body.clientHeight;
}
else if (window.innerWidth) {
	width = window.innerWidth;
	height = window.innerHeight;
}

// change the values according to your increment
// setting
width = Math.floor(width/increment)*increment;
height = Math.floor(height/increment)*increment;

// convert values to a string and pad them out to
// always contain 4 digits - this makes the results
// easier to read:
width = width.toString();
height = height.toString();
while (width.length < 4) {
	width = '0' + width;
}
while (height.length < 4) {
	height = '0' + height;
}

// record the results in your webservers log files
window_width = new Image();
window_width.src = '/i/window_size.gif?width|' + width;
window_height = new Image();
window_height.src = '/i/window_size.gif?height|' + height;

//-->
</script>

window_size.gif is just any gif


If you're using Analog for log analysis, you might have to add the
following line to your config file so the query string on the gif is
displayed:

ARGSINCLUDE /i/window_size.gif

Alternately, if don't mind getting harmless 404's, you could change
the last lines to:

window_width = new Image();
window_width.src = 'width|' + width + '.gif';
window_height = new Image();
window_height.src = 'height|' + height + '.gif';


Now sit back and wait a while, then check out your website's stats -
they include the window size of your visitors.

You could go further and use cookie to prevent the results from being
biased by people who have screens large enough to make viewing your
site a pleasurable experience.
</tip>
--

__________________________________________
- Erik Mattheis

(612) 377 2272
http://goZz.com/

__________________________________________



More information about the thelist mailing list