LP#1966802: add Matomo support to Bootstrap OPAC
authorJeff Davis <jdavis@sitka.bclibraries.ca>
Mon, 28 Mar 2022 18:30:26 +0000 (11:30 -0700)
committerJane Sandberg <js7389@princeton.edu>
Thu, 7 Apr 2022 20:05:55 +0000 (13:05 -0700)
Signed-off-by: Jeff Davis <jdavis@sitka.bclibraries.ca>
Signed-off-by: Jane Sandberg <js7389@princeton.edu>
Open-ILS/src/templates-bootstrap/opac/parts/base.tt2
Open-ILS/src/templates-bootstrap/opac/parts/matomo_analytics.tt2 [new file with mode: 0644]

index eceb162..91030b7 100755 (executable)
         [% '<style>'; custom_css ; '</style>' %]
         [% END %]
 
+        [% matomo_id = ctx.get_org_setting(ctx.search_ou, 'opac.analytics.matomo_id'); %]
+        [% matomo_url = ctx.get_org_setting(ctx.search_ou, 'opac.analytics.matomo_url'); %]
+        [% IF matomo_id && matomo_url %]
+           [% matomo_enabled = 1; %]
+        [% END %]
+
         [%- libname = ctx.get_aou(ctx.search_ou).name;
             libname = libname | html;
             libsname = ctx.get_aou(ctx.search_ou).shortname; %]
@@ -49,6 +55,7 @@
 
         [% IF !ctx.is_staff %]
             [% INCLUDE 'opac/parts/goog_analytics.tt2' %]
+            [% INCLUDE 'opac/parts/matomo_analytics.tt2' %]
         [% END %]
         [% PROCESS 'opac/parts/stripe.tt2' %]
 <script  src="[% ctx.media_prefix %]/opac/deps/node_modules/jquery/dist/jquery.min.js"></script>
diff --git a/Open-ILS/src/templates-bootstrap/opac/parts/matomo_analytics.tt2 b/Open-ILS/src/templates-bootstrap/opac/parts/matomo_analytics.tt2
new file mode 100644 (file)
index 0000000..48c7c67
--- /dev/null
@@ -0,0 +1,19 @@
+[%- PROCESS "opac/parts/header.tt2";
+    IF matomo_enabled == 1 %]
+
+       <!-- Matomo -->
+       <script type="text/javascript">
+         var _paq = window._paq || [];
+         /* tracker methods like "setCustomDimension" should be called before "trackPageView" */
+         _paq.push(['trackPageView']);
+         _paq.push(['enableLinkTracking']);
+         (function() {
+           var u="[% matomo_url %]";
+           _paq.push(['setTrackerUrl', u+'matomo.php']);
+           _paq.push(['setSiteId', '[% matomo_id %]']);
+           var d=document, g=d.createElement('script'), s=d.getElementsByTagName('script')[0];
+           g.type='text/javascript'; g.async=true; g.defer=true; g.src=u+'matomo.js'; s.parentNode.insertBefore(g,s);
+         })();
+       </script>
+       <!-- End Matomo Code -->
+[%- END %]