From 445fffcc570bce1ab4321a9fcacd664c5477c300 Mon Sep 17 00:00:00 2001 From: setlen Date: Fri, 12 Feb 2021 01:28:32 +0100 Subject: [PATCH 1/4] Add support for Plausible analytics and Matomo analytics Solves #10954 --- client/src/galaxy.library.js | 25 ++++++++++++- lib/galaxy/config/sample/galaxy.yml.sample | 8 ++++ lib/galaxy/managers/configuration.py | 4 ++ lib/galaxy/webapps/galaxy/config_schema.yml | 28 ++++++++++++++ lib/tool_shed/webapp/config_schema.yml | 28 ++++++++++++++ lib/tool_shed/webapp/templates/base.mako | 6 +++ .../webapp/templates/base/base_panels.mako | 6 +++ .../webapp/templates/galaxy_client_app.mako | 37 +++++++++++++++++++ .../webapps/tool_shed/base_panels.mako | 6 +++ templates/base.mako | 6 +++ templates/base/base_panels.mako | 6 +++ templates/galaxy_client_app.mako | 37 +++++++++++++++++++ templates/js-app.mako | 8 +++- 13 files changed, 202 insertions(+), 3 deletions(-) diff --git a/client/src/galaxy.library.js b/client/src/galaxy.library.js index 45cbb3ad954..0f77a558d40 100644 --- a/client/src/galaxy.library.js +++ b/client/src/galaxy.library.js @@ -58,7 +58,7 @@ var LibraryRouter = Backbone.Router.extend({ }, /** - * Track every route change as a page view in Google Analytics. + * Track every route change as a page view in Google Analytics or Plausible */ trackPageview: function () { var url = Backbone.history.getFragment(); @@ -69,6 +69,13 @@ var LibraryRouter = Backbone.Router.extend({ if (typeof ga !== "undefined") { ga("send", "pageview", `${getAppRoot()}library/list${url}`); } + if (typeof plausible !== "undefined") { + plausible(`pageview ${getAppRoot()}library/list${url}`); + } + if (typeof window._paq !== "undefined") { + window._paq.push(['setCustomUrl', `${getAppRoot()}library/list${url}`]); + window._paq.push(['trackPageView']); + } }, }); @@ -119,6 +126,22 @@ var GalaxyLibrary = Backbone.View.extend({ ga("create", Galaxy.config.ga_code, "auto"); ga("send", "pageview"); } + if (Galaxy.config.plausible_server && Galaxy.config.plausible_domain) { + document.write(""); + } + if (Galaxy.config.matomo_server && Galaxy.config.matomo_site_id) { + var _paq = window._paq = window._paq || []; + /* tracker methods like "setCustomDimension" should be called before "trackPageView" */ + _paq.push(['trackPageView']); + _paq.push(['enableLinkTracking']); + (function() { + var u=Galaxy.config.matomo_server+"/"; + _paq.push(['setTrackerUrl', u+'matomo.php']); + _paq.push(['setSiteId', Galaxy.config.matomo_site_id]); + var d=document, g=d.createElement('script'), s=d.getElementsByTagName('script')[0]; + g.type='text/javascript'; g.async=true; g.src=u+'matomo.js'; s.parentNode.insertBefore(g,s); + })(); + } Galaxy.libraries = this; diff --git a/lib/galaxy/config/sample/galaxy.yml.sample b/lib/galaxy/config/sample/galaxy.yml.sample index f55472697b2..be92803ec17 100644 --- a/lib/galaxy/config/sample/galaxy.yml.sample +++ b/lib/galaxy/config/sample/galaxy.yml.sample @@ -817,6 +817,14 @@ galaxy: # your Google Analytics account. Example: UA-XXXXXXXX-Y #ga_code: null + # Please enter the URL for the Plausible server (including https) so this can be used for tracking + # with Plausible (https://plausible.io/). + # plausible_server: null + + # Please enter the URL for the Galaxy server so this can be used for tracking + # with Plausible (https://plausible.io/). + #plausible_domain: null + # Galaxy can display data at various external browsers. These options # specify which browsers should be available. URLs and builds # available at these browsers are defined in the specified files. diff --git a/lib/galaxy/managers/configuration.py b/lib/galaxy/managers/configuration.py index 4fe42582691..c4159269537 100644 --- a/lib/galaxy/managers/configuration.py +++ b/lib/galaxy/managers/configuration.py @@ -158,6 +158,10 @@ class ConfigSerializer(base.ModelSerializer): 'datatypes_disable_auto': _use_config, 'allow_user_dataset_purge': _defaults_to(False), # schema default is True 'ga_code': _use_config, + 'plausible_server': _use_config, + 'plausible_domain': _use_config, + 'matomo_server': _use_config, + 'matomo_site_id': _use_config, 'enable_unique_workflow_defaults': _use_config, 'enable_beta_markdown_export': _use_config, 'simplified_workflow_run_ui': _use_config, diff --git a/lib/galaxy/webapps/galaxy/config_schema.yml b/lib/galaxy/webapps/galaxy/config_schema.yml index 4d45ca8de7a..cb780651ed5 100644 --- a/lib/galaxy/webapps/galaxy/config_schema.yml +++ b/lib/galaxy/webapps/galaxy/config_schema.yml @@ -1061,6 +1061,34 @@ mapping: You can enter tracking code here to track visitor's behavior through your Google Analytics account. Example: UA-XXXXXXXX-Y + plausible_server: + type: str + required: false + desc: | + Please enter the URL for the Plausible server (including https) so this can be used for tracking + with Plausible (https://plausible.io/). + + plausible_domain: + type: str + required: false + desc: | + Please enter the URL for the Galaxy server so this can be used for tracking + with Plausible (https://plausible.io/). + + matomo_server: + type: str + required: false + desc: | + Please enter the URL for the Matomo server (including https) so this can be used for tracking + with Matomo (https://matomo.org/). + + matomo_site_id: + type: str + required: false + desc: | + Please enter the site ID for the Matomo server so this can be used for tracking + with Matomo (https://matomo.org/). + display_servers: type: str default: hgw1.cse.ucsc.edu,hgw2.cse.ucsc.edu,hgw3.cse.ucsc.edu,hgw4.cse.ucsc.edu,hgw5.cse.ucsc.edu,hgw6.cse.ucsc.edu,hgw7.cse.ucsc.edu,hgw8.cse.ucsc.edu,lowepub.cse.ucsc.edu diff --git a/lib/tool_shed/webapp/config_schema.yml b/lib/tool_shed/webapp/config_schema.yml index 1302a11593a..3fadb90539a 100644 --- a/lib/tool_shed/webapp/config_schema.yml +++ b/lib/tool_shed/webapp/config_schema.yml @@ -172,6 +172,34 @@ mapping: You can enter tracking code here to track visitor's behavior through your Google Analytics account. Example: UA-XXXXXXXX-Y + plausible_server: + type: str + required: false + desc: | + Please enter the URL for the Plausible server (including https) so this can be used for tracking + with Plausible (https://plausible.io/). + + plausible_domain: + type: str + required: false + desc: | + Please enter the URL for the Galaxy server so this can be used for tracking + with Plausible (https://plausible.io/). + + matomo_server: + type: str + required: false + desc: | + Please enter the URL for the Matomo server (including https) so this can be used for tracking + with Matomo (https://matomo.org/). + + matomo_site_id: + type: str + required: false + desc: | + Please enter the site ID for the Matomo server so this can be used for tracking + with Matomo (https://matomo.org/). + id_secret: type: str default: changethisinproductiontoo diff --git a/lib/tool_shed/webapp/templates/base.mako b/lib/tool_shed/webapp/templates/base.mako index c72f5687ddf..ea1688d42bf 100644 --- a/lib/tool_shed/webapp/templates/base.mako +++ b/lib/tool_shed/webapp/templates/base.mako @@ -68,6 +68,12 @@ %if self.js_app and self.js_app.config and self.js_app.config.ga_code: ${ galaxy_client.config_google_analytics(self.js_app.config.ga_code) } %endif + %if self.js_app and self.js_app.config and self.js_app.config.plausible_server and self.js_app.config.plausible_domain: + ${ galaxy_client.config_plausible_analytics(self.js_app.config.plausible_server, self.js_app.config.plausible_domain) } + %endif + %if self.js_app and self.js_app.config and self.js_app.config.matomo_server and self.js_app.config.matomo_site_id: + ${ galaxy_client.config_matomo_analytics(self.js_app.config.matomo_server, self.js_app.config.matomo_site_id) } + %endif %if not form_input_auto_focus is UNDEFINED and form_input_auto_focus: +<%def name="config_plausible_analytics(plausible_server, plausible_domain)"> + + %if plausible_server and plausible_domain: + + %else: + + %endif + + +<%def name="config_matomo_analytics(matomo_server, matomo_site_id)"> + + + ## ---------------------------------------------------------------------------- <%def name="get_user_dict()"> diff --git a/lib/tool_shed/webapp/templates/webapps/tool_shed/base_panels.mako b/lib/tool_shed/webapp/templates/webapps/tool_shed/base_panels.mako index 95384138be4..e9ceef2c311 100644 --- a/lib/tool_shed/webapp/templates/webapps/tool_shed/base_panels.mako +++ b/lib/tool_shed/webapp/templates/webapps/tool_shed/base_panels.mako @@ -48,6 +48,12 @@ %if app.config.ga_code: ${ galaxy_client.config_google_analytics(app.config.ga_code)} %endif + %if app.config.plausible_server and app.config.plausible_domain: + ${ galaxy_client.config_plausible_analytics(app.config.plausible_server, app.config.plausible_domain) } + %endif + %if app.config.matomo_server: + ${ galaxy_client.config_matomo_analytics(app.config.matomo_server) } + %endif ## start main tag