Skip to content

Instantly share code, notes, and snippets.

@lukaszkorecki
Created July 27, 2010 14:24
Show Gist options
  • Save lukaszkorecki/492283 to your computer and use it in GitHub Desktop.
Save lukaszkorecki/492283 to your computer and use it in GitHub Desktop.
Chartbeat user count in your browser as one, big, fat number

What is it?

A very simple Chartbeat utility - it shows (using a 1000px size font) number of users on your website.

Additionally it plays the sound if your user count is above a certain level using the <audio /> tag.

It's been hacked very quickly and not in the best way - but hey! It works!

A screenshot

showing just the number was not enough

How to use it?

  1. Get the raw file from the gist
  2. Save it as a html file on your web server or just open it in a browser (a browser which supports <audio /> :-)) and make the screen visible to all people in your office
  3. Edit host and apikey vars (and optionally the src of the audio element. You might want to adjust the threshold as well (30 - totally random number)
  4. ?????
  5. Profit

TODO

The code is quite dirty and needs to be more structured - that will be done once I get some time.

A screenshot would be nice.

<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8">
<title>Chartbeat Status</title>
<script src="http://ajax.googleapis.com/ajax/libs/prototype/1.6.1.0/prototype.js" type="text/javascript" charset="utf-8"></script>
<script type="text/javascript" charset="utf-8">
SOUND_PLAYED_YEAH = false;
NUMBER_OF_PEOPLE = 0;
LOLWUT = function(obj) {
NUMBER_OF_PEOPLE = obj.people;
};
var host = "YOUR_DOMAIN"
var apikey = "YOUR_API_KEY"
var url = "http://api.chartbeat.com/quickstats?host="+host+"&apikey="+apikey+"&jsonp=LOLWUT"
var request = function() {
SOUND = document.getElementsByTagName("audio")[0];
$(document.getElementsByTagName("head")[0]).insert({ bottom : (new Element("script", { src : url}))});
if(NUMBER_OF_PEOPLE > 30 ) {
$("number").addClassName("WOOHOO")
if( !SOUND_PLAYED_YEAH) {
if(SOUND.play){
SOUND.play();
SOUND_PLAYED_YEAH = true;
}
}
} else {
$("number").removeClassName("WOOHOO")
}
if(NUMBER_OF_PEOPLE < 20) {
SOUND_PLAYED_YEAH = false;
}
$("number").update(NUMBER_OF_PEOPLE);
}
$(document).observe("dom:loaded", function(){
request();
new PeriodicalExecuter(function(){ request(); }, 10);
});
</script>
<style type="text/css" media="screen">
#number, .bottom {
font-size: 1000px;
margin: 0 auto;
text-align: center;
font-family: monospace;
}
.bottom {
font-size: 24px;
}
.WOOHOO {
color: red;
}
</style>
</head>
<body>
<div id="number">
</div>
<div class="bottom">chartbeat, yeah?</div>
<audio id="sound" src="PATH_TO_YOUR_AUDIO_FILE"></audio>
</body>
</html>
@heewa
Copy link

heewa commented Jul 27, 2010

Nice! Two suggestions:

  1. Use an api called "quickstats". We haven't added it to docs as it's not fully locked down quite yet, but it's working. It's much faster, and a lot easier on our backends.
  2. Check in with chartbeat before adding this to a big site, you might hit API limits (also using summizer rather than quickstats will hit the limits much much sooner).

Best,
Heewa
Sr. Engineer, Chartbeat

@lukaszkorecki
Copy link
Author

Thanks for the suggestions!

I'll make some changes when I get some more time.

,,,,

and done. Now with sound and less intensive API calls

@heewa
Copy link

heewa commented Jul 28, 2010

Very cool! Can I see it in action somewhere?

@lukaszkorecki
Copy link
Author

Yeah - just included a photo :-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment