TPac: move google analytics import to head
authorBill Erickson <berick@esilibrary.com>
Wed, 28 Sep 2011 21:23:13 +0000 (17:23 -0400)
committerLebbeous Fogle-Weekley <lebbeous@esilibrary.com>
Wed, 28 Sep 2011 21:33:17 +0000 (17:33 -0400)
Google Analytics documention recommends loading the JS in the page
<head>.

http://www.google.com/support/googleanalytics/bin/answer.py?answer=174090

Use as directed by default.

Also, moved the JS loading chunk to its own template to ease override by
those who do not wish to use as directed.

Signed-off-by: Bill Erickson <berick@esilibrary.com>
Signed-off-by: Lebbeous Fogle-Weekley <lebbeous@esilibrary.com>
Open-ILS/src/templates/opac/parts/base.tt2
Open-ILS/src/templates/opac/parts/goog_analytics.tt2 [new file with mode: 0644]
Open-ILS/src/templates/opac/parts/js.tt2

index c66c74f..0a6c10c 100644 (file)
@@ -9,6 +9,7 @@
         <link rel="stylesheet" type="text/css" href="[% ctx.media_prefix %]/css/skin/default/opac/style.css" />
         <title>[% l('Catalog - [_1]', ctx.page_title) %]</title>
         <link rel="unapi-server" type="application/xml" title="unAPI" href="/opac/extras/unapi" />
+        [% INCLUDE 'opac/parts/goog_analytics.tt2' %]
     </head>
     <body>
         [% content %] 
diff --git a/Open-ILS/src/templates/opac/parts/goog_analytics.tt2 b/Open-ILS/src/templates/opac/parts/goog_analytics.tt2
new file mode 100644 (file)
index 0000000..df69b43
--- /dev/null
@@ -0,0 +1,18 @@
+[%- PROCESS "opac/parts/config.tt2";
+    IF google_analytics.enabled == 'true' %]
+
+<!-- http://www.google.com/support/googleanalytics/bin/answer.py?answer=174090 -->
+<script type="text/javascript">
+    var _gaq = _gaq || [];
+    _gaq.push(['_setAccount', '[% google_analytics.code %]']);
+    _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>
+[%- END %]
index 9dbbeac..35ff2bb 100644 (file)
     IF CGI.https; url = url.replace('^http:', 'https:'); END; %]
 <script type='text/javascript' id='EIT' src='[% url %]'></script>
 [%- END %]
-
-[%- IF google_analytics.enabled == 'true' %]
-<!-- Google Analytics -->
-<script type="text/javascript">
-/* uncomment when ready */ /*
-  var _gaq = _gaq || [];
-  _gaq.push(['_setAccount', '[% google_analytics.code %]']);
-  _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>
-<!-- End Google Analytics -->
-[%- END %]