XHTML Mobile sites are easy

17 December 2007, 11:00

Over at play.tm we've made a mobile site, at m.play.tm. This was made possible by a few different technologies and conventions all coming together. Google Adsense for Mobile for monentisation, XHTML Mobile for the markup, and the apparent de-facto standard of putting mobile sites on the subdomain m.[yourdomainname].

With all our content in the a database its no problem to output it to the simplified version of XHTML for use on mobile browsers, the design process was simple too - you can't display much on a tiny phone screen. Google Adsense adverts on non-mobile sites are embedded in the page using Javascript. The JS is executes and passes the page's URL to the script and Google's server-side code spits out the relevant ads (using Google's crazily complex algorithms to get to best ads, undoubtedly).

Mobiles can't usually execute Javascript, and the extra HTTP call creates added latency, which mobile pages are sensitive to. To get around this Google mobile ads are added to the page server-side, using whatever scripting language you choose. I guess Google figure that if you're savvy enough to create a mobile site then you are savvy enough to understand server-side scripting. Unfortunately Google only provide Perl, PHP, JSP and ASP v3 samples. As the main page generating parts of play.tm are written in ASP.net I created this function (based on the ASP v3 function Google provides), which of course you are welcome to copy and probably improve for your implementation (a mention and link would be nice though!):

function showGoogleAd(url)
	Dim googleTime, googleDt, googleScheme, googleHost,googlePubId
	
	googlePubId = "ca-mb-pub-xxxxxxxxxxxxxxxxxxxx"
	
	googleTime = DateDiff("s", "01/01/1970 00:00:00", Now())
	googleDt = (1000 * googleTime) + System.Math.Round(1000 * (Timer - Int(Timer)))
	googleScheme = "http://"
	if StrComp(Request.ServerVariables("HTTPS"), "on") = 0 Then googleScheme = "https://"
	googleHost = Server.URLEncode(googleScheme & url)
	
	Dim googleAdUrl, googleAdOutput
	googleAdUrl = "http://pagead2.googlesyndication.com/pagead/ads?ad_type=text&" & googlePubId & "&dt=" & googleDt & "&format=mobile_double" & "&host=" & googleHost & "&ip=" & Server.URLEncode(Request.ServerVariables("REMOTE_ADDR")) & "&markup=xhtml&oe=utf8&output=xhtml&ref=" & Server.URLEncode(Request.ServerVariables("HTTP_REFERER")) & "&url=" & googleHost & "&useragent=" & Server.URLEncode(Request.ServerVariables("HTTP_USER_AGENT"))
	
	Dim googleWebClient as New WebClient()
	googleAdOutput = googleWebClient.DownloadString(googleAdUrl)
	response.write (googleAdOutput)
	
end function

The upshot of this is that whilst it is still early days for building up our mobile readership and for Google's Adsense for Mobile Content programme we've found a new way of monetising our content. The upfront cost in developing this the mobile site was small as it just reuses a lot of existing code and infrastructure and it is incredibly simple in terms of design (the CSS file is just a few lines long) and content (simple markup).

Jason Cartwright RSS Feed

about

Jason is a web developer living in London, working for Google and Ferrago Ltd.

links

me

work

colophon