Dec/090
Google Mobile Analytics and Opera Mini
Google Analytics is a popular web statistics site with lots of useful features, I’ve been a big fan since the start. Google recently added a bunch of new features, and an important one out of those for me is mobile web tracking.
Typically, Google’s way of tracking site usage is to ask you to put a small snippet of HTML onto your site which is essentially a javascript call to their servers. Great – except a lot of mobile phones don’t actually support javascript. So the only good solution is to run some code on the server. I don’t know if it’s related to Google’s purchase of AdMob, but they’ve done exactly that and provided server side code in various programming languages (C#, PHP, etc) to achieve this. See ga.php as a real example.
Great, now I’ve got beautiful graphs showing me how people use my site. But what’s that? 25% of my users live in the country (not set)? I’ve not heard of the place! It turns out those users more or less all used one browser: Opera Mini.
Oh Opera Mini, what a strange beast you are. While the Opera browser is a full normal browser, Opera Mini is a service that installs a thin client on your phone and Norwegian proxy servers visit the site for you. Norway? Well that’s a little better than living in (not set).
Luckily, this whole problem is fixed by a teensy change in their server side code. Rather than always fetching the browser’s current IP address, I tweaked Google’s PHP code so that it detects Opera Mini is in use and sends the real user’s IP address. To be honest, I’m a little confused why this isn’t in Google’s code in the first place.
So here it is. A minor fix to Google’s ga.php file (line 162) to improve Opera Mini handling:
Original line: "&utmip=" . getIP($_SERVER["REMOTE_ADDR"]);
and my version: "&utmip=" . getIP((stristr($_SERVER['HTTP_USER_AGENT'], 'opera mini') && array_key_exists('HTTP_X_FORWARDED_FOR', $_SERVER)) ? $_SERVER['HTTP_X_FORWARDED_FOR']: $_SERVER["REMOTE_ADDR"]);
That’s all. Now I get real country stats :)
Nov/076
Tracking my phone on Google Earth
After looking through various KML samples on the web during lunch today, I spent a little time experimenting with converting my existing location data into something that Google Earth could read – allowing people to track my location in real time.
Manual labour
About 6 times per day, I press a button on my phone and it sends a text message to my website with my current cell tower ID. My website then takes over and does all the smart stuff by itself. If I’ve traveled somewhere new, it automatically looks up the cell ID in a large UK database using their API to find the latitude and longitude of the cell tower I’m currently connected to. But big decimal numbers showing my current latitude and longitude aren’t all that interesting on their own.
Sidebar widget
The next step in my process was to add the widget on the side of my website to show everyone my current location. It’s not particularly fascinating – either I’m in my home town, at work, or traveling somewhere in between. But I’ve just added something a little more interesting.
Google Earth
Whereas before the link on my current location just took you to the coordinates where I’m currently sat, it will now load up a KML file showing a nice picture of a man standing on my current location, and hopefully a number of little cell towers which will show where I’ve been over the last 7 days.
The historic data isn’t all that interesting in Google Maps, but if I open up my KML file in Google Earth then I expose the timeline controls and I can choose to see where I was at different times and even animate my location over time.
What’s next?
I’ve got a habit of always wanting to do more. I’ve cleaned up my location database so I could add in other locations (i.e. not just cell towers) and try plotting even more data. I’d like to try the following:
- Load up GPS data for any hikes I go on
- Add a few key locations onto the map such as the Scout hut, my brother’s place in Canada, anything relevant to me
- Add some kind of refresh so that it updates automatically when I’m on the move
- Create some kind of JavScript timeline interface for Google Maps
Oct/070
Keeping programming knowledge alive
I’ve read a few articles about spoken languages across the globe fading to non-existance because no one speaks them any more and they get forgotten.
“More than half of the word’s 7000 languages are endangered, because they consist of an unsustainably small – and declining – speaker base.” – New Scientist
On a much less epic scale, I’m concerned about my own knowledge of programming languages fading to nothing from lack of use. The best example for me is Perl.
Perl is the first server-side programming language I tried to learn to improve my websites. I made very basic guestbook scripts and that was about it, but I did (for a short time) know the syntax and some basic principles in the language. I’ve not used Perl for 5 years!
I started looking into PHP, and never looked back. So what do I remember of Perl now? Hardly anything at all.
With a few years of self-taught PHP under my belt, I’m now pushing slowly into ASP.NET. This time, I’m going to keep my PHP very much alive.