Use Your 404 Pages To Help Find Missing Children

If you visit a page on my blog that has gone missing it will now hopefully help (albeit just a touch) find missing children. Here is a screen shot of how it looks:

I’m going to ask Primary Technology to consider rolling this out across all of their sites! What do you think, would you be happy if your schools blog 404 pages helped to find missing children?

How long did it take to connect to socket io?

Send the duration(in ms) a client waited to connect to a Socket IO instance off to Google Analytics . I use this on PrimaryWall to make sure it’s not taking schools a long time to connect to walls. If I start to see this number getting bigger I know something is going wrong so I have an alert set if the average gets above 1000ms.

This code sends the ms it took from when the document was ready to when the socket was ready.

$(document).ready(function ()
{
  var socketConnectDuration = 0;
  setInterval ( socketConnectDurationIncrease, 100 );  // Start a timer
  socket.on('connect', function ()
  {
    _gaq.push(['_trackEvent', 'Connection duration', 'Connection duration', socketConnectDuration]); // Send the length of time to GA
....
  }
}

function socketConnectDurationIncrease(){
  socketConnectDuration = socketConnectDuration + 100;
}

Upgrading Etherpad if you installed with Git

/etc/init.d/etherpad-lite stop
git pull
/etc/init.d/etherpad-lite start

If you installed from the tar ball then grab the latest tar and extract it over your current install.

Make sure you always back up your dirty.db if you use that.

As far as database migrations we are hoping that the current schema wont need any modifications, if so we will try to handle this with upgrade scripts that will run automatically.

OWL energy monitor to Google Analytics

I have been able to get my CM160 owl energy monitor to provide data to Google Analytics. This allows me to track energy usage in my house.

It’s disgraceful how bad Owl’s support is for linux users but it’s great to see the community being so active in writing drivers/support to make it a reality.

I have a cron job that runs a php script that sends the data.

I have the Google Analytics PHP Class in the same folder.

The script looks like this:

$file = "/var/log/owl.txt";
$file = escapeshellarg($file); // for the security conscious (should be everyone!)
$line = `tail -n 1 $file`;
$data = explode(" ", $line);
$power = $data[6];
$power = $power*10; // times by 10 so its an integer

include 'autoload.php'; // ga class
use UnitedPrototype\GoogleAnalytics; // use the google analytics class

/* GA Stuff */
// Initilize GA Tracker
$tracker = new GoogleAnalytics\Tracker('UA-34066705-1', 'mclear.co.uk'); // CHANGE THESE SETTINGS

// Assemble Visitor information
// (could also get unserialized from database)
$visitor = new GoogleAnalytics\Visitor();
$visitor->setIpAddress('127.0.0.1');
$visitor->setUserAgent('Slave2');
$visitor->setScreenResolution('1024x768');

// Assemble Session information
// (could also get unserialized from PHP session)
$session = new GoogleAnalytics\Session();

// Assemble Page information
$page = new GoogleAnalytics\Page('/page.html');
$page->setTitle('My Page');

// Track page view
$tracker->trackPageview($page, $session, $visitor);

// Assemble Visitor information
// (could also get unserialized from database)
$visitor = new GoogleAnalytics\Visitor();
$visitor->setIpAddress("127.0.0.1");
$visitor->setUserAgent("slave2");


// Assemble Session information
// (could also get unserialized from PHP session)
$session = new GoogleAnalytics\Session();

// Assemble Page information
$page = new GoogleAnalytics\Page('/statisticsFromTheServer');
$page->setTitle('MySchoolHolidays Server');
/* End GA stuff */

$event = new GoogleAnalytics\Event();
$event->setCategory("power");
$event->setAction("costPerHour");
$event->SetLabel("pence");
$event->SetValue($power);
$event->setNonInteraction("true");
$tracker->trackEVent($event, $session, $visitor);

Your results will take a little while to come through and this can be tested by running the php script. If you don’t get an error then wait 24 hours and see if they come through under Content -> Events in GA

Disclaimer: I did try to use Open Web Analytics to accomplish this but it’s PHP class had an error so I gave up.