Do you frequently check your Google Analytics account for the total number of active visitors with the Realtime feature? Do you keep it inside an active tab in the background just so you can flip to it to check again every two minutes, almost in a semi-obsessive manner? Ah yes… you my friend, could use THIS nice little JavaScript snippet!

Basically, what it does – it updates the title of your Google Analytics page (while on the Realtime view) with the last 3 visitor count (more specifically, the last 3 that were different from the previous value). It runs every 5 seconds, so it’s not too often to slow-down your system, and it’s not too slow to miss a beat! It just reads the information already updated on the page, it doesn’t do any remote HTTP calls whatsoever to fetch the data.

Here’s what it looks like:

Screenshot of the JavaScript Snippet results.

How to install / run it?

Most browsers have developer tools such as a “console”, which you can use to paste Javascript code and execute it on the current page. A quick way to do this, is to right-click on your Google Analytics page, select “Inspect element ” (in Chrome), select the “Console” tab and paste the code below inside of it. Once pasted, hit enter to execute it and you will notice the title of the page should change right away.

JavaScript Code Snippet: Google Analytics Realtime Title Update:

//While in Google Analytics's Realtime view, paste and execute this to update the title
var _lastVisitors =	[]; //Stores an array of last varied visitor counts.
var _lastMaxLength =	3; //Caps the length of the array above.

function updateTitle() {
	var domVisitors = parseInt(document.getElementById("ID-overviewCounterValue").innerHTML);
	var strVisitors;
	if(domVisitors!=_lastVisitors[0]) {
		if(_lastVisitors.length>_lastMaxLength) {
			_lastVisitors.length = _lastMaxLength;
	strVisitors =	_lastVisitors.join("-");
	var localToday = new Date();
	var localTime = localToday.toLocaleTimeString();

	//You can alter the String format here however you like:
	document.title = strVisitors + " @" + localTime;
	setTimeout("updateTitle()", 5000);
//Do one immediate update:

You can modify the script to your own needs. Unfortunately, it will have to be re-pasted and re-executed each time you refresh or revisit your Google Analytics Realtime page. BUT… I’m pretty sure there is some Chrome extensions that will let you “bind” code snippets to specific web pages, which can then be executed automatically per visits.

That’s it for now!

Questions? Comments? Suggestions?