LP1517298: Matomo Support with library org settings
authorRogan Hamby <rogan.hamby@gmail.com>
Tue, 18 Feb 2020 16:19:11 +0000 (11:19 -0500)
committerJason Boyer <JBoyer@equinoxinitiative.org>
Fri, 11 Sep 2020 20:13:09 +0000 (16:13 -0400)
Signed-off-by: Rogan Hamby <rogan.hamby@gmail.com>
Signed-off-by: Jane Sandberg <sandbej@linnbenton.edu>
Signed-off-by: Rogan Hamby <rogan.hamby@gmail.com>
Signed-off-by: Jason Boyer <JBoyer@equinoxinitiative.org>

Open-ILS/src/sql/Pg/950.data.seed-values.sql
Open-ILS/src/sql/Pg/upgrade/xxxx.data.support_matomo.sql [new file with mode: 0644]
Open-ILS/src/templates/opac/parts/base.tt2
Open-ILS/src/templates/opac/parts/matomo_analytics.tt2
docs/RELEASE_NOTES_NEXT/Administration/lp1517298_matomo.adoc [new file with mode: 0644]

index af65b92..27099e3 100644 (file)
@@ -1938,7 +1938,9 @@ INSERT INTO permission.perm_list ( id, code, description ) VALUES
  ( 621, 'VIEW_BOOKING_RESOURCE_TYPE', oils_i18n_gettext(621,
     'View booking resource types', 'ppl', 'description')),
  ( 622, 'VIEW_BOOKING_RESOURCE', oils_i18n_gettext(622,
-    'View booking resources', 'ppl', 'description'))
+    'View booking resources', 'ppl', 'description')),
+ ( 623, 'UPDATE_ORG_UNIT_SETTING.opac.analytics.use_matomo', oils_i18n_gettext(623,
+    'Set OPAC to use Matomo tracking', 'ppl', 'description'))
 ;
 
 
@@ -20756,3 +20758,24 @@ VALUES (
     'Grid Config: acq.provider.search.results',
     'cwst', 'label')
 );
+
+INSERT into config.org_unit_setting_type
+    ( name, grp, label, description, datatype, update_perm ) VALUES
+    ( 'opac.analytics.matomo_id', 'opac',
+        oils_i18n_gettext('opac.analytics.matomo_id',
+            'Requires the Matomo ID',
+            'coust', 'label'),
+        oils_i18n_gettext('opac.analytics.matomo_id',
+            'Requires the Matomo ID',
+            'coust', 'description'),
+        'string', 623),
+    ( 'opac.analytics.matomo_url', 'opac',
+        oils_i18n_gettext('opac.analytics.matomo_url',
+            'Requires the url to the Matomo software',
+            'coust', 'label'),
+        oils_i18n_gettext('opac.analytics.matomo_url',
+            'Requires the url to the Matomo software',
+            'coust', 'description'),
+        'string', 623)
+;
+
diff --git a/Open-ILS/src/sql/Pg/upgrade/xxxx.data.support_matomo.sql b/Open-ILS/src/sql/Pg/upgrade/xxxx.data.support_matomo.sql
new file mode 100644 (file)
index 0000000..a90e83b
--- /dev/null
@@ -0,0 +1,34 @@
+       BEGIN;
+
+       SELECT evergreen.upgrade_deps_block_check('xxxx', :eg_version);
+
+       INSERT into config.org_unit_setting_type
+       ( name, grp, label, description, datatype, fm_class ) VALUES
+      ( 'opac.analytics.matomo_id', 'opac',
+          oils_i18n_gettext('opac.analytics.matomo_id',
+               'Requires the Matomo ID',
+               'coust', 'label'),
+          oils_i18n_gettext('opac.analytics.matomo_id',
+               'Requires the Matomo ID',
+               'coust', 'description'),
+          'string', NULL),
+      ( 'opac.analytics.matomo_url', 'opac',
+          oils_i18n_gettext('opac.analytics.matomo_url',
+               'Requires the url to the Matomo software',
+               'coust', 'label'),
+          oils_i18n_gettext('opac.analytics.matomo_url',
+               'Requires the url to the Matomo software',
+               'coust', 'description'),
+          'string', NULL)
+      ;
+
+      INSERT INTO permission.perm_list ( id, code, description ) VALUES
+      ( 623, 'UPDATE_ORG_UNIT_SETTING.opac.analytics.use_matomo', oils_i18n_gettext(623,
+         'Set OPAC to use Matomo tracking', 'ppl', 'description')),
+      ;
+
+      UPDATE config.org_unit_setting_type SET update_perm = 623 WHERE name = 'opac.analytics.matomo_id';            
+      UPDATE config.org_unit_setting_type SET update_perm = 623 WHERE name = 'opac.analytics.matomo_url';
+
+      COMMIT;
+
index 69210a5..ea47a60 100644 (file)
         [% '<style>'; custom_css ; '</style>' %]                                          
         [% END %]
 
+        [% IF ctx.get_org_setting(ctx.search_ou, 'opac.analytics.use_matomo') == 1 %]
+           [% matomo_enabled = 1; %]
+           [% 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'); %]  
+           [% INCLUDE 'opac/parts/matomo_analytics.tt2' %]                                       
+        [% END %]
+
         [%- libname = ctx.get_aou(ctx.search_ou).name;
             libname = libname | html;
             libsname = ctx.get_aou(ctx.search_ou).shortname; %]
index 5f2ffd8..48c7c67 100644 (file)
@@ -1,18 +1,19 @@
 [%- PROCESS "opac/parts/header.tt2";
-    IF matomo_analytics.enabled == 'true' -%]
-<!-- 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_analytics.url %]";
-    _paq.push(['setTrackerUrl', u+'matomo.php']);
-    _paq.push(['setSiteId', '[% matomo_analytics.site %]']);
-    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 -%]
+    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 %]
diff --git a/docs/RELEASE_NOTES_NEXT/Administration/lp1517298_matomo.adoc b/docs/RELEASE_NOTES_NEXT/Administration/lp1517298_matomo.adoc
new file mode 100644 (file)
index 0000000..79f977e
--- /dev/null
@@ -0,0 +1,28 @@
+Matomo Support
+^^^^^^^^^^^^^^
+Support for the open source web analytics platform Matomo is now 
+native to Evergreen. Support is on an org unit level so different 
+libraries can have separate or no analytics. Once you setup 
+a Matomo service you will need the URL and site ID. Typically 
+Matomo will give you a block of javascript you can insert into 
+web sites. One line will look like :
+
+var u="http://mylibrary.lib/matomo/";
+
+The full URL in the double quotes will be your URL.  Another line 
+will look like:  
+
+_paq.push(['setSiteId', '1']);
+
+In this case the number 1 will be your site ID.  
+
+These are set by YOAUSes opac.analytics.matomo_url and 
+opac.analytics.matomo_id respectively. There is also a boolean 
+setting called opac.analytics.use_matomo which determines if 
+it is used at all. Three new permsisions control access to 
+these: 
+
+UPDATE_ORG_UNIT_SETTING.opac.analytics.matomo_id
+UPDATE_ORG_UNIT_SETTING.opac.analytics.matomo_url
+UPDATE_ORG_UNIT_SETTING.opac.analytics.use_matomo