Eventful—Google Analytics event tracking made easy

The easy way to add event tracking or bind domains together for use under a single Google Analytics profile.

Examples

Place the following code just before the </body> of your XHTML document.

Note: For best performance, it is recommended that you combine all the JavaScript files below into a single minified file.

<script type="text/javascript" src="jquery-1.6.4.js"></script>
<script type="text/javascript" src="jquery.url.js"></script>
<script type="text/javascript" src="jquery.eventful.js"></script>
<script type="text/javascript">
	var _gaq = _gaq || [];
	_gaq.push(
		['_setAccount', 'UA-12345-1'],
		['_trackPageview']
	);

	(function() {
		var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
		ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www')
		+ '.google-analytics.com/ga.js';
		var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
	})();
</script>

Then, configure the events you want to track:

// Glue all 'internal' domains together so they can be tracked under the one GA profile
	$.setInternalSites([
		'http://example.com', // your domain
		'https://secure.example.com' // another of your domains
	]);
	$.glueSites();

// Track page events
	$('#themes a').trackEvent('click', 'theme-selector');
	// :external pseudo-selector established using $.setInternalSites
	$('a:external').trackEvent('click', 'external-links');

Working example

A complete demonstration of eventful is available.

Download

eventful is licensed under the The GNU General Public License (GPL), by downloading it you are agreeing to abide by the terms of that license.

Package

Download the complete eventful 0.1 example package (.zip)

Individual files

Check out eventful on GitHub

Changelog

  • 0.1 Initial implementation.

Leave a reply