Skip to content

Commit

Permalink
Merge pull request #875 from helix84/DS-2478-update-GA
Browse files Browse the repository at this point in the history
DS-2478 update Google Analytics tracking JS snippet
  • Loading branch information
helix84 committed Mar 3, 2015
2 parents 40be894 + 9b79e7e commit 9014692
Show file tree
Hide file tree
Showing 8 changed files with 173 additions and 185 deletions.
30 changes: 30 additions & 0 deletions dspace-jspui/src/main/webapp/layout/google-analytics-snippet.jsp
@@ -0,0 +1,30 @@
<%--
The contents of this file are subject to the license and copyright
detailed in the LICENSE and NOTICE files at the root of the source
tree and available online at
http://www.dspace.org/license/
--%>
<%@ page import="org.dspace.core.ConfigurationManager" %>
<%
String analyticsKey = ConfigurationManager.getProperty("jspui.google.analytics.key");
%>
<%--Gooogle Analytics recording.--%>
<%
if (analyticsKey != null && analyticsKey.length() > 0)
{
%>
<script>
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,'script','//www.google-analytics.com/analytics.js','ga');
ga('create', '<%= analyticsKey %>', 'auto');
ga('send', 'pageview');
</script>
<%
}
%>
70 changes: 27 additions & 43 deletions dspace-jspui/src/main/webapp/layout/header-default.jsp
Expand Up @@ -50,10 +50,10 @@
<meta name="Generator" content="<%= generator %>" />
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="shortcut icon" href="<%= request.getContextPath() %>/favicon.ico" type="image/x-icon"/>
<link rel="stylesheet" href="<%= request.getContextPath() %>/static/css/jquery-ui-1.10.3.custom/redmond/jquery-ui-1.10.3.custom.css" type="text/css" />
<link rel="stylesheet" href="<%= request.getContextPath() %>/static/css/bootstrap/bootstrap.min.css" type="text/css" />
<link rel="stylesheet" href="<%= request.getContextPath() %>/static/css/bootstrap/bootstrap-theme.min.css" type="text/css" />
<link rel="stylesheet" href="<%= request.getContextPath() %>/static/css/bootstrap/dspace-theme.css" type="text/css" />
<link rel="stylesheet" href="<%= request.getContextPath() %>/static/css/jquery-ui-1.10.3.custom/redmond/jquery-ui-1.10.3.custom.css" type="text/css" />
<link rel="stylesheet" href="<%= request.getContextPath() %>/static/css/bootstrap/bootstrap.min.css" type="text/css" />
<link rel="stylesheet" href="<%= request.getContextPath() %>/static/css/bootstrap/bootstrap-theme.min.css" type="text/css" />
<link rel="stylesheet" href="<%= request.getContextPath() %>/static/css/bootstrap/dspace-theme.css" type="text/css" />
<%
if (!"NONE".equals(feedRef))
{
Expand All @@ -79,36 +79,20 @@
}
%>

<script type='text/javascript' src="<%= request.getContextPath() %>/static/js/jquery/jquery-1.10.2.min.js"></script>
<script type='text/javascript' src='<%= request.getContextPath() %>/static/js/jquery/jquery-ui-1.10.3.custom.min.js'></script>
<script type='text/javascript' src='<%= request.getContextPath() %>/static/js/bootstrap/bootstrap.min.js'></script>
<script type='text/javascript' src='<%= request.getContextPath() %>/static/js/holder.js'></script>
<script type="text/javascript" src="<%= request.getContextPath() %>/utils.js"></script>
<script type="text/javascript" src="<%= request.getContextPath() %>/static/js/choice-support.js"> </script>

<%--Gooogle Analytics recording.--%>
<%
if (analyticsKey != null && analyticsKey.length() > 0)
{
%>
<script type="text/javascript">
var _gaq = _gaq || [];
_gaq.push(['_setAccount', '<%= analyticsKey %>']);
_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>
<script type='text/javascript' src="<%= request.getContextPath() %>/static/js/jquery/jquery-1.10.2.min.js"></script>
<script type='text/javascript' src='<%= request.getContextPath() %>/static/js/jquery/jquery-ui-1.10.3.custom.min.js'></script>
<script type='text/javascript' src='<%= request.getContextPath() %>/static/js/bootstrap/bootstrap.min.js'></script>
<script type='text/javascript' src='<%= request.getContextPath() %>/static/js/holder.js'></script>
<script type="text/javascript" src="<%= request.getContextPath() %>/utils.js"></script>
<script type="text/javascript" src="<%= request.getContextPath() %>/static/js/choice-support.js"> </script>
<dspace:include page="/layout/google-analytics-snippet.jsp" />

<%
}
if (extraHeadDataLast != null)
{ %>
<%= extraHeadDataLast %>
<%
}
<%= extraHeadDataLast %>
<%
}
%>


Expand All @@ -135,34 +119,34 @@
}
else
{
%>
%>
<div class="container">
<dspace:include page="/layout/navbar-minimal.jsp" />
</div>
<%
<%
}
%>
</header>

<main id="content" role="main">
<div class="container banner">
<div class="row">
<div class="col-md-9 brand">
<h1><fmt:message key="jsp.layout.header-default.brand.heading" /></h1>
<fmt:message key="jsp.layout.header-default.brand.description" />
<div class="row">
<div class="col-md-9 brand">
<h1><fmt:message key="jsp.layout.header-default.brand.heading" /></h1>
<fmt:message key="jsp.layout.header-default.brand.description" />
</div>
<div class="col-md-3"><img class="pull-right" src="<%= request.getContextPath() %>/image/logo.gif" alt="DSpace logo" />
</div>
</div>
</div>
</div>
</div>
<br/>
<%-- Location bar --%>
<%
if (locbar)
{
%>
<div class="container">
<dspace:include page="/layout/location-bar.jsp" />
<dspace:include page="/layout/location-bar.jsp" />
</div>
<%
}
Expand All @@ -172,6 +156,6 @@
<%-- Page contents --%>
<div class="container">
<% if (request.getAttribute("dspace.layout.sidebar") != null) { %>
<div class="row">
<div class="col-md-9">
<% } %>
<div class="row">
<div class="col-md-9">
<% } %>
56 changes: 20 additions & 36 deletions dspace-jspui/src/main/webapp/layout/header-submission.jsp
Expand Up @@ -50,10 +50,10 @@
<meta name="Generator" content="<%= generator %>" />
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="shortcut icon" href="<%= request.getContextPath() %>/favicon.ico" type="image/x-icon"/>
<link rel="stylesheet" href="<%= request.getContextPath() %>/static/css/jquery-ui-1.10.3.custom/redmond/jquery-ui-1.10.3.custom.css" type="text/css" />
<link rel="stylesheet" href="<%= request.getContextPath() %>/static/css/bootstrap/bootstrap.min.css" type="text/css" />
<link rel="stylesheet" href="<%= request.getContextPath() %>/static/css/bootstrap/bootstrap-theme.min.css" type="text/css" />
<link rel="stylesheet" href="<%= request.getContextPath() %>/static/css/bootstrap/dspace-theme.css" type="text/css" />
<link rel="stylesheet" href="<%= request.getContextPath() %>/static/css/jquery-ui-1.10.3.custom/redmond/jquery-ui-1.10.3.custom.css" type="text/css" />
<link rel="stylesheet" href="<%= request.getContextPath() %>/static/css/bootstrap/bootstrap.min.css" type="text/css" />
<link rel="stylesheet" href="<%= request.getContextPath() %>/static/css/bootstrap/bootstrap-theme.min.css" type="text/css" />
<link rel="stylesheet" href="<%= request.getContextPath() %>/static/css/bootstrap/dspace-theme.css" type="text/css" />
<%
if (!"NONE".equals(feedRef))
{
Expand All @@ -79,36 +79,20 @@
}
%>

<script type='text/javascript' src="<%= request.getContextPath() %>/static/js/jquery/jquery-1.10.2.min.js"></script>
<script type='text/javascript' src='<%= request.getContextPath() %>/static/js/jquery/jquery-ui-1.10.3.custom.min.js'></script>
<script type='text/javascript' src='<%= request.getContextPath() %>/static/js/bootstrap/bootstrap.min.js'></script>
<script type='text/javascript' src='<%= request.getContextPath() %>/static/js/holder.js'></script>
<script type="text/javascript" src="<%= request.getContextPath() %>/utils.js"></script>
<script type="text/javascript" src="<%= request.getContextPath() %>/static/js/choice-support.js"> </script>

<%--Gooogle Analytics recording.--%>
<%
if (analyticsKey != null && analyticsKey.length() > 0)
{
%>
<script type="text/javascript">
var _gaq = _gaq || [];
_gaq.push(['_setAccount', '<%= analyticsKey %>']);
_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>
<script type='text/javascript' src="<%= request.getContextPath() %>/static/js/jquery/jquery-1.10.2.min.js"></script>
<script type='text/javascript' src='<%= request.getContextPath() %>/static/js/jquery/jquery-ui-1.10.3.custom.min.js'></script>
<script type='text/javascript' src='<%= request.getContextPath() %>/static/js/bootstrap/bootstrap.min.js'></script>
<script type='text/javascript' src='<%= request.getContextPath() %>/static/js/holder.js'></script>
<script type="text/javascript" src="<%= request.getContextPath() %>/utils.js"></script>
<script type="text/javascript" src="<%= request.getContextPath() %>/static/js/choice-support.js"> </script>
<dspace:include page="/layout/google-analytics-snippet.jsp" />

<%
}
if (extraHeadDataLast != null)
{ %>
<%= extraHeadDataLast %>
<%
}
<%= extraHeadDataLast %>
<%
}
%>


Expand All @@ -135,11 +119,11 @@
}
else
{
%>
%>
<div class="container">
<dspace:include page="/layout/navbar-minimal.jsp" />
</div>
<%
<%
}
%>
</header>
Expand All @@ -161,6 +145,6 @@
<%-- Page contents --%>
<div class="container">
<% if (request.getAttribute("dspace.layout.sidebar") != null) { %>
<div class="row">
<div class="col-md-9">
<% } %>
<div class="row">
<div class="col-md-9">
<% } %>
44 changes: 14 additions & 30 deletions dspace-jspui/src/main/webapp/layout/legacy/header-default.jsp
Expand Up @@ -52,7 +52,7 @@
<link rel="stylesheet" href="<%= request.getContextPath() %>/print.css" media="print" type="text/css" />
<link rel="shortcut icon" href="<%= request.getContextPath() %>/favicon.ico" type="image/x-icon"/>
<link rel="stylesheet" href="<%= request.getContextPath() %>/css/discovery.css" type="text/css" />
<link rel="stylesheet" href="<%= request.getContextPath() %>/static/css/jquery-ui-1.10.3.custom/redmond/jquery-ui-1.10.3.custom.min.css" type="text/css" />
<link rel="stylesheet" href="<%= request.getContextPath() %>/static/css/jquery-ui-1.10.3.custom/redmond/jquery-ui-1.10.3.custom.min.css" type="text/css" />
<%
if (!"NONE".equals(feedRef))
{
Expand All @@ -78,38 +78,22 @@
}
%>

<script type='text/javascript' src='<%= request.getContextPath() %>/static/js/jquery/jquery-1.10.2.min.js'></script>
<script type='text/javascript' src='<%= request.getContextPath() %>/static/js/jquery/jquery-ui-1.10.3.custom.min.js'></script>
<script type="text/javascript" src="<%= request.getContextPath() %>/utils.js"></script>
<script type="text/javascript" src="<%= request.getContextPath() %>/static/js/scriptaculous/prototype.js"> </script>
<script type="text/javascript" src="<%= request.getContextPath() %>/static/js/scriptaculous/effects.js"> </script>
<script type="text/javascript" src="<%= request.getContextPath() %>/static/js/scriptaculous/builder.js"> </script>
<script type="text/javascript" src="<%= request.getContextPath() %>/static/js/scriptaculous/controls.js"> </script>
<script type="text/javascript" src="<%= request.getContextPath() %>/static/js/choice-support.js"> </script>

<%--Gooogle Analytics recording.--%>
<%
if (analyticsKey != null && analyticsKey.length() > 0)
{
%>
<script type="text/javascript">
var _gaq = _gaq || [];
_gaq.push(['_setAccount', '<%= analyticsKey %>']);
_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>
<script type='text/javascript' src='<%= request.getContextPath() %>/static/js/jquery/jquery-1.10.2.min.js'></script>
<script type='text/javascript' src='<%= request.getContextPath() %>/static/js/jquery/jquery-ui-1.10.3.custom.min.js'></script>
<script type="text/javascript" src="<%= request.getContextPath() %>/utils.js"></script>
<script type="text/javascript" src="<%= request.getContextPath() %>/static/js/scriptaculous/prototype.js"> </script>
<script type="text/javascript" src="<%= request.getContextPath() %>/static/js/scriptaculous/effects.js"> </script>
<script type="text/javascript" src="<%= request.getContextPath() %>/static/js/scriptaculous/builder.js"> </script>
<script type="text/javascript" src="<%= request.getContextPath() %>/static/js/scriptaculous/controls.js"> </script>
<script type="text/javascript" src="<%= request.getContextPath() %>/static/js/choice-support.js"> </script>
<dspace:include page="/layout/google-analytics-snippet.jsp" />

<%
}
if (extraHeadDataLast != null)
{ %>
<%= extraHeadDataLast %>
<%
}
<%= extraHeadDataLast %>
<%
}
%>

</head>
Expand Down
20 changes: 12 additions & 8 deletions dspace-xmlui-mirage2/src/main/webapp/xsl/core/page-structure.xsl
Expand Up @@ -856,17 +856,21 @@
<xsl:call-template name="choiceLookupPopUpSetup"/>
</xsl:if>

<xsl:call-template name="addJavascript-google-analytics" />
</xsl:template>

<xsl:template name="addJavascript-google-analytics">
<!-- Add a google analytics script if the key is present -->
<xsl:if test="/dri:document/dri:meta/dri:pageMeta/dri:metadata[@element='google'][@qualifier='analytics']">
<script><xsl:text>
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,'script','//www.google-analytics.com/analytics.js','ga');

ga('create', '</xsl:text><xsl:value-of select="/dri:document/dri:meta/dri:pageMeta/dri:metadata[@element='google'][@qualifier='analytics']"/><xsl:text>', '</xsl:text><xsl:value-of select="/dri:document/dri:meta/dri:pageMeta/dri:metadata[@element='request'][@qualifier='serverName']"/><xsl:text>');
ga('send', 'pageview');
</xsl:text></script>
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,'script','//www.google-analytics.com/analytics.js','ga');

ga('create', '</xsl:text><xsl:value-of select="/dri:document/dri:meta/dri:pageMeta/dri:metadata[@element='google'][@qualifier='analytics']"/><xsl:text>', '</xsl:text><xsl:value-of select="/dri:document/dri:meta/dri:pageMeta/dri:metadata[@element='request'][@qualifier='serverName']"/><xsl:text>');
ga('send', 'pageview');
</xsl:text></script>
</xsl:if>
</xsl:template>

Expand Down

0 comments on commit 9014692

Please sign in to comment.