Google Analytics

One of the strengths of the Istarel Workshop Application Framework is that common tasks can be performed in several different ways. Consider Google Analytics, a near ubiquitous tool for tracking website visitor data.

Modify an HTML Template

Each view-based Application Module in the Istarel Workshop Application Framework uses an IWPage object as the basis for constructing the resulting HTML page. When content is static, the most efficient and performant way of rendering content is to simply include it in the IWPage's underlying HTML template. On the Istarel Workshop website, all the public-facing pages use a PublicPage object, which uses page/html/public.html as its template file.

The simplest approach to adding Google Analytics, therefore, is to modify that template.

Listing: page/html/public.html

<!DOCTYPE html>
<html lang="en">

{head}
{body}

<script type="text/javascript">
var gaJsHost = (("https:" == document.location.protocol) ?
    "https://ssl." : "http://www.");
document.write(unescape("%3Cscript src='" + gaJsHost +
    "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E"));
</script>
<script type="text/javascript">
try {
var pageTracker = _gat._getTracker("UA-7285492-1");
pageTracker._trackPageview();
} catch(err) {}
</script>

</html>