Blog // Posts tagged with prototype

 

Tracking file downloads with Google Analytics and Prototype

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'));
        });
    });
});

16 Jul 2008 
No comments

 
 

Simple PHP upload progress meter using Prototype

The uploadprogress extension is fairly simple to use - but it is important to note that on some PHP configurations it doesn't function correctly and only returns a progress of 100%.

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

6 Jul 2008 
8 comments

 

Latest tweets

Hmm. http://yfrog.com/nc1lgj # 24th July 2010

Code obfuscation is cheesy. # 3rd June 2010

@easydns congrats! it's about time :) # 11th May 2010

Home | Blog | About | Contact | Copyright © Donovan Schönknecht Top