How to track OpenLaszlo Websites with Google-Analytics

Some time ago, i had to integrate a google analytics tracking into a OpenLaszlo website, compiled to flash or DHTML/HTML5.

How to do this!?
At first, we need a google account and additional a google analytics tracking code, registrated for the site to track.
After a little bit of searching, i have a summary of collected script snippets that we need.

In the HTML file, that’s embed our OpenLaszlo Website, we have to integrate the google analytics tracking code with a little JavaScript snippet:

<script type="text/javascript">
	var _gaq = _gaq || [];
	_gaq.push(['_setAccount', 'UA-XXXXXXXX-1']);
	_gaq.push(['_setDomainName', 'none']);
	_gaq.push(['_setAllowLinker', true]);
	_gaq.push(['_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>

After that, it is necessary to call a google analytics javascript function at every site switch. A call could be look like:

<method name="switchSite" args="menu='startsite', site='startsite', siteType='site', content='undefined'">
<![CDATA[
	// Google-Analytics
	lz.Browser.callJS("_gaq.push(['_trackPageview', '/"+menu+"/"+site+"/"+siteType+"/"+content+".html'])");
	...

If now a visitor navigate through your site, the _gaq.push function sends a page call like ‘/menu/site/siteType/content.html’ to google analytics. So you’re able to follow your visitors, see which pages they find interessting or where they exit your page… 😉

  1. No comments yet.