Blog

Tracking file downloads with Google Analytics and Prototype

16 July 2008, 10:29

Using Prototype’s CSS-style selectors you can easily track file downloads with Google Analytics:

Event.observe(window, 'load', function() {
	$$('a[href$=".zip"]', 'a[href$=".pdf"]').each(function(anchor) {
		anchor.observe('click', function(event) {
			if (pageTracker) pageTracker._trackPageview(anchor.getAttribute('href'));
		});
	});
});

Comments

Simple PHP upload progress meter using Prototype

6 July 2008, 02:45

Update: This does not seem to work with the latest 0.9 version of the uploadprogress extension (thanks to Bruno Cantieni for pointing this out).

If I had a little more time I'd write a detailed tutorial for this but today you're going to get the crash course and examples.

Upload progress screenshot

The JavaScript uses David Stone's method for displaying percentage bars but you can modify the onCreate, onUpdate and onComplete callbacks if you want to use your own.


1) You will need uploadprogress >= 0.3.1 (0.3.0 does not seem to work for me), to build it from source (don't forget to restart your webserver after installing):

cvs -d :pserver:cvsread@cvs.php.net:/repository checkout pecl/uploadprogress
cd pecl/uploadprogress && phpize && ./configure && make && sudo make install

2) Progress tracking is automatically enabled if you have a field named UPLOAD_IDENTIFIER with a unique ID in your file upload form:

<input type="hidden" name="UPLOAD_IDENTIFIER" value="<?php echo $uploadID; ?>" id="uploadIdentifier" />

3) You retrieve the upload progress with your UPLOAD_IDENTIFIER (obviously these calls will be AJAX requests):

$data = uploadprogress_get_info($uploadID);

Once the upload is complete the extension will remove the temporary file and further info calls will return null.

That's it!

See the demo

Download the code


Comments [3]

ImageMagick 6.3.7 packages for Ubuntu 7.10 (i386)

13 March 2008, 09:20

I wanted to play around with some of the newer ImageMagick features so I’ve rebuilt the 6.3.7 Hardy packages for Gusty:

You’ll need to apt-get install the graphviz package to get these working.

Comments

Imagick

12 March 2008, 11:19

The PHP Imagick documentation is still very much incomplete – but if you’re looking for some info on using Imagick with PHP I’d highly recommend checking out Mikko Koppanen’s blog for some neat examples.

Comments

Face detection

4 March 2008, 00:22

If you’re interested in implementing face detection in your software, check out Torch3vision.

Using the haarscan app the detection is fast and fairly accurate when faces are clearly visible, as Paul Gardyne demonstrates below:

Face detection test

Pretty cool stuff!

Comments

Top

Copyright © 2007-2008 Undesigned