Ring a bell when someone visits your website

Posted at February 08, 2012

I love the new realtime Google Analytics. I love the fact how you can see what people are doing on your website right now. However I can’t stare at the interface all day, so why not play a little sound every time someone visits your website?

Note that this idea was inspired by bellbot, a website with the same functionality. My solution requires no signup or client side code (besides Google Aanalytics) though.

This is a little bookmarklet that you can run on your realtime Google Analytics page that plays a bell everytime a new visitor enters your website. The video below shows how it works.

It is now even easier to ring a bell, here are the updated steps to Ring a bell!

  1. Add Ring a bell! as bookmark to your browser.

  2. Get Google Analytics and make sure you have access to the realtime data.

  3. Navigate to the Realtime overview: Home – Realtime – Overview

  4. Click on the Ring a bell! bookmarklet.

For those curious, here is the javascript function.

(function( d, c ){
   var beep = new Audio( 'https://mikevanrossum.nl/stuff/doorbell.mp3' )
     , check = function( old ) {
      var visitors = parseInt( d.getElementById( 'ID-overviewCounterValue' ).innerHTML );
      // c.log('visitors: ' + visitors);
      // only try the second time and up
      if( old || old === 0 ) {
         //the difference between the old number and the new number
         var dif = visitors -- old;
         // if the new number is higher, we have new visitors
         if( dif > 0 ) {
            // play a sound & log for each visitor
            while( dif-- ) {
               c.log( 'Ding! New visitor!' );
               setTimeout( function() { beep.play(); }, 500 * i );
            }
         }
      }
      setTimeout( function() { check( visitors ); }, 2000 );
   }
   check();
}( document, console ));