Hacking into Page-Level Details for Language

Generate a page-by-language text file that can be mined for deep and rich information.

While most web measurement applications do a pretty good job reporting on the percentage distribution of languages used to browse your site, very few go so far as to let you segment your visitor activity [Hack #48] by language. Fortunately, if you have a nominal amount of control over your web site, you can write a relatively simple hack to provide this information.

The Code

The following code is written in VBScript for Microsoft’s Active Server Pages, but could quite easily be adapted to PHP, Perl, or Java. You should save the following code as language_by_page.inc and include it in your header files.

	<%
	Dim fso, lf
	df = "en" ' Default language for site is English (en)
	' Test to see if current visitor is using other than the default language 
	(df) 
	if (Left(REQUEST.SERVERVARIABLES("HTTP_ACCEPT_LANGUAGE"), 2) <> df AND 
	REQUEST.SERVERVARIABLES("HTTP_ACCEPT_LANGUAGE") <> "") then
		' If so, open the language_by_page.txt file for appending
		Set fso = CreateObject("Scripting.FileSystemObject")
		Set lf = fso.OpenTextFile("c:\websites\webanalytics\cgi-data\
		language_by_page.txt", 8, True)
		
	' Append the name of the script, the language and the time stamp
	lf.WriteLine( REQUEST.SERVERVARIABLES("SCRIPT_NAME") & "|" & 
	REQUEST.SERVERVARIABLES("HTTP_ACCEPT_LANGUAGE") & "|" & now())
	' Don't forget to close the "lf" object
	lf.Close
end if
%>

Running the Code

Here is what you ...

Get Web Site Measurement Hacks now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.