Skip to content

Commit

Permalink
Simple Google Analytics
Browse files Browse the repository at this point in the history
More complex virtual page views for tabs/etc to be implemented later.
  • Loading branch information
JacobsonMT committed Aug 3, 2016
1 parent 3c936b7 commit a22a81f
Show file tree
Hide file tree
Showing 15 changed files with 109 additions and 2 deletions.
5 changes: 4 additions & 1 deletion gotrack/src/main/resources/example_gotrack.properties
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,7 @@ gotrack.dryRun=false
# Load pre-calculated data from database or recalculating them, should be true if new data has just been added
gotrack.recalculate=false
# Write pre-calculated data to database (This takes a while), can set to true once during development for speedy start-ups
gotrack.writeCache=true
gotrack.writeCache=true
# Google Analytics (leave tracker empty for sandbox/development versions)
gotrack.ga_tracker=
gotrack.ga_domain=chibi.ubc.ca
5 changes: 5 additions & 0 deletions gotrack/src/main/webapp/WEB-INF/errors/400.xhtml
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,9 @@
<ui:define name="errorContent">
<p>The request could not be understood by the server due to malformed syntax.</p>
</ui:define>
<ui:define name="js">
<script type="text/javascript">
googleAnalyticsTrackPageviewIfConfigured( "/gotrack/error/400" );
</script>
</ui:define>
</ui:composition>
5 changes: 5 additions & 0 deletions gotrack/src/main/webapp/WEB-INF/errors/404.xhtml
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,9 @@
<ui:define name="errorContent">
<p>The requested resource as specified in your browser's address bar cannot be found.</p>
</ui:define>
<ui:define name="js">
<script type="text/javascript">
googleAnalyticsTrackPageviewIfConfigured( "/gotrack/error/404" );
</script>
</ui:define>
</ui:composition>
5 changes: 5 additions & 0 deletions gotrack/src/main/webapp/WEB-INF/errors/500.xhtml
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,9 @@
xmlns="http://www.w3.org/1999/xhtml"
xmlns:ui="http://java.sun.com/jsf/facelets"
>
<ui:define name="js">
<script type="text/javascript">
googleAnalyticsTrackPageviewIfConfigured( "/gotrack/error/500" );
</script>
</ui:define>
</ui:composition>
5 changes: 5 additions & 0 deletions gotrack/src/main/webapp/WEB-INF/errors/bug.xhtml
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,9 @@
xmlns:ui="http://java.sun.com/jsf/facelets"
>
<ui:define name="contentTitle">You got a RuntimeException! There's a BUG somewhere!</ui:define>
<ui:define name="js">
<script type="text/javascript">
googleAnalyticsTrackPageviewIfConfigured( "/gotrack/error/bug" );
</script>
</ui:define>
</ui:composition>
5 changes: 5 additions & 0 deletions gotrack/src/main/webapp/WEB-INF/errors/database.xhtml
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,9 @@
xmlns:ui="http://java.sun.com/jsf/facelets"
>
<ui:define name="contentTitle">Oops! DB fail!</ui:define>
<ui:define name="js">
<script type="text/javascript">
googleAnalyticsTrackPageviewIfConfigured( "/gotrack/error/database" );
</script>
</ui:define>
</ui:composition>
5 changes: 5 additions & 0 deletions gotrack/src/main/webapp/WEB-INF/errors/expired.xhtml
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,9 @@
<ui:define name="errorContent">
<p>Your session has expired due to inactivity. Please refresh your page.</p>
</ui:define>
<ui:define name="js">
<script type="text/javascript">
googleAnalyticsTrackPageviewIfConfigured( "/gotrack/error/expired" );
</script>
</ui:define>
</ui:composition>
5 changes: 5 additions & 0 deletions gotrack/src/main/webapp/WEB-INF/errors/gene.xhtml
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,9 @@
<ui:define name="errorContent">
<p>The selected gene symbol could not be found.</p>
</ui:define>
<ui:define name="js">
<script type="text/javascript">
googleAnalyticsTrackPageviewIfConfigured( "/gotrack/error/gene" );
</script>
</ui:define>
</ui:composition>
5 changes: 5 additions & 0 deletions gotrack/src/main/webapp/WEB-INF/errors/term.xhtml
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,9 @@
<ui:define name="errorContent">
<p>The selected term id could not be found.</p>
</ui:define>
<ui:define name="js">
<script type="text/javascript">
googleAnalyticsTrackPageviewIfConfigured( "/gotrack/error/term" );
</script>
</ui:define>
</ui:composition>
46 changes: 46 additions & 0 deletions gotrack/src/main/webapp/WEB-INF/templates/analytics.xhtml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<ui:composition
xmlns="http://www.w3.org/1999/xhtml"
xmlns:f="http://xmlns.jcp.org/jsf/core"
xmlns:h="http://xmlns.jcp.org/jsf/html"
xmlns:ui="http://xmlns.jcp.org/jsf/facelets">

<f:verbatim rendered="#{empty (settingsCache.getProperty('gotrack.ga_tracker'))}">
<script type="text/javascript">
console.log("No Tracker.");
if ( typeof googleAnalyticsTrackPageviewIfConfigured === 'undefined' ) {
var googleAnalyticsTrackPageviewIfConfigured = function(pageURL) {/* no op, for sandbox and development */
console.log("Didn't track: " + pageURL);
};
}
</script>
</f:verbatim>

<f:verbatim rendered="#{not empty (settingsCache.getProperty('gotrack.ga_tracker'))}">
<script type="text/javascript">
var _gaq = _gaq || [];
var pluginUrl = '//www.google-analytics.com/plugins/ga/inpage_linkid.js';
_gaq.push([ '_require', 'inpage_linkid', pluginUrl ]);
_gaq.push([ '_setAccount', "settingsCache.getProperty('gotrack.ga_tracker')" ]);
_gaq.push([ '_setDomainName', "settingsCache.getProperty('gotrack.ga_domain')" ]);
_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);
})();
if ( typeof googleAnalyticsTrackPageviewIfConfigured === 'undefined' ) {
var googleAnalyticsTrackPageviewIfConfigured = googleAnalyticsTrackPageviewIfConfigured || function(pageURL) {
if ( typeof _gaq !== 'undefined' ) {
_gaq.push([ '_setAccount', "settingsCache.getProperty('gotrack.ga_tracker')" ]);
_gaq.push([ '_trackPageview', pageURL ]);
}
};
}
</script>
</f:verbatim>

</ui:composition>
1 change: 1 addition & 0 deletions gotrack/src/main/webapp/WEB-INF/templates/mainLayout.xhtml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
<meta name="keywords"
content="genomics,bioinformatics,genetics,gene,function,ontology,biotechnology,medicine,biomedical,meta-analysis,statistics,search,open source,database,software" />

<ui:include src="/WEB-INF/templates/analytics.xhtml" />
<h:outputScript library="js" name="common.js" />
<ui:insert name="js" />

Expand Down
3 changes: 3 additions & 0 deletions gotrack/src/main/webapp/enrichment.xhtml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@
<h:outputStylesheet library="css" name="enrichment.css" />
</ui:define>
<ui:define name="js">
<script type="text/javascript">
googleAnalyticsTrackPageviewIfConfigured( "/gotrack/enrichment" );
</script>
<h:outputScript library="js" name="utility.js" />

<!-- Highcharts stuff -->
Expand Down
3 changes: 3 additions & 0 deletions gotrack/src/main/webapp/genes.xhtml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@
<h:outputStylesheet library="css" name="genes.css" />
</ui:define>
<ui:define name="js">
<script type="text/javascript">
googleAnalyticsTrackPageviewIfConfigured( "/gotrack/genes" );
</script>
<h:outputScript library="js" name="utility.js" />

<!-- Highcharts stuff -->
Expand Down
10 changes: 9 additions & 1 deletion gotrack/src/main/webapp/index.xhtml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:p="http://primefaces.org/ui"
xmlns:of="http://omnifaces.org/functions">
xmlns:of="http://omnifaces.org/functions"
xmlns:ui="http://xmlns.jcp.org/jsf/facelets">
<h:head>
<title>GOtrack</title>
<h:outputStylesheet library="css" name="style.css" />
Expand All @@ -21,6 +22,13 @@
content="genomics,bioinformatics,genetics,gene,function,ontology,biotechnology,medicine,biomedical,meta-analysis,statistics,search,open source,database,software,enrichment,GO" />
<meta name="author" content="GOtrack admin ([email protected])" />

<ui:include src="/WEB-INF/templates/analytics.xhtml" />

<script type="text/javascript">
googleAnalyticsTrackPageviewIfConfigured( "/gotrack/index" );
</script>


</h:head>

<h:body>
Expand Down
3 changes: 3 additions & 0 deletions gotrack/src/main/webapp/terms.xhtml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@
<h:outputStylesheet library="css" name="tipsy.css" />
</ui:define>
<ui:define name="js">
<script type="text/javascript">
googleAnalyticsTrackPageviewIfConfigured( "/gotrack/terms" );
</script>
<h:outputScript library="js" name="utility.js" />


Expand Down

0 comments on commit a22a81f

Please sign in to comment.