We’re gradually adding analytics on our dashboard. We think that this will end up more efficient than using something like Google Analytics. It also allows a future tie in with the Web Application Firewall to more easily defend against the bad guys.
To start with we’re introducing a Live view of countries, views, pages, and sources.
Easy you might think? So did we. But this turns out to be surprisingly complicated. A particular difficulty was working out the visitor’s country. Each visitor has an IP address and this needs to be looked up to get the country. The common way to do this, that nearly every plugin doing statistics seems to use, is to call an API. This seemed not great to us as it slows things down. We wanted to use our own list of ip addresses in the database for the fastest possible response. Importing almost 300,000 ip ranges takes a long time though. Too long in fact and most servers will timeout if we do it from a web plugin. Our solution was to trickle feed the data in, using a job that runs every 10 minutes. This has the advantage that the server doesn’t get overloaded and that country lookups are very fast. The disadvantage is that it can take 2 days or so for the initial database population. We think that’s a reasonable price to pay for the advantages.
Thinking back to future implementations, having the list of IP addresses locally also means that we can add possible functionality to the web application firewall that can simply block entire countries. If your site has no target audience in high spam or high hacking countries then they’d be simply blockable. We’ve added this to our todo list.