summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--client/lib/utils.js45
-rw-r--r--config/router.js6
-rw-r--r--models/settings.js17
-rw-r--r--server/policy.js9
-rwxr-xr-xsnap-src/bin/config16
5 files changed, 92 insertions, 1 deletions
diff --git a/client/lib/utils.js b/client/lib/utils.js
index 6b8e3524..5349e500 100644
--- a/client/lib/utils.js
+++ b/client/lib/utils.js
@@ -144,6 +144,51 @@ Utils = {
}
});
},
+
+ setMatomo(data){
+ window._paq = window._paq || [];
+ window._paq.push(['setDoNotTrack', data.doNotTrack]);
+ if (data.withUserName){
+ window._paq.push(['setUserId', Meteor.user().username]);
+ }
+ window._paq.push(['trackPageView']);
+ window._paq.push(['enableLinkTracking']);
+
+ (function() {
+ window._paq.push(['setTrackerUrl', `${data.address}piwik.php`]);
+ window._paq.push(['setSiteId', data.siteId]);
+
+ const script = document.createElement('script');
+ Object.assign(script, {
+ id: 'scriptMatomo',
+ type: 'text/javascript',
+ async: 'true',
+ defer: 'true',
+ src: `${data.address}piwik.js`,
+ });
+
+ const s = document.getElementsByTagName('script')[0];
+ s.parentNode.insertBefore(script, s);
+ })();
+
+ Session.set('matomo', true);
+ },
+
+ manageMatomo() {
+ const matomo = Session.get('matomo');
+ if (matomo === undefined){
+ Meteor.call('getMatomoConf', (err, data) => {
+ if (err && err.error[0] === 'var-not-exist'){
+ Session.set('matomo', false); // siteId || address server not defined
+ }
+ if (!err){
+ Utils.setMatomo(data);
+ }
+ });
+ } else if (matomo) {
+ window._paq.push(['trackPageView']);
+ }
+ },
};
// A simple tracker dependency that we invalidate every time the window is
diff --git a/config/router.js b/config/router.js
index 1f80004a..91d08897 100644
--- a/config/router.js
+++ b/config/router.js
@@ -14,6 +14,8 @@ FlowRouter.route('/', {
Filter.reset();
EscapeActions.executeAll();
+ Utils.manageMatomo();
+
BlazeLayout.render('defaultLayout', {
headerBar: 'boardListHeaderBar',
content: 'boardList',
@@ -38,6 +40,8 @@ FlowRouter.route('/b/:id/:slug', {
EscapeActions.executeUpTo('popup-close');
}
+ Utils.manageMatomo();
+
BlazeLayout.render('defaultLayout', {
headerBar: 'boardHeaderBar',
content: 'board',
@@ -53,6 +57,8 @@ FlowRouter.route('/b/:boardId/:slug/:cardId', {
Session.set('currentBoard', params.boardId);
Session.set('currentCard', params.cardId);
+ Utils.manageMatomo();
+
BlazeLayout.render('defaultLayout', {
headerBar: 'boardHeaderBar',
content: 'board',
diff --git a/models/settings.js b/models/settings.js
index 308d867d..3b9b4eae 100644
--- a/models/settings.js
+++ b/models/settings.js
@@ -96,6 +96,14 @@ if (Meteor.isServer) {
return (min + Math.round(rand * range));
}
+ function getEnvVar(name){
+ const value = process.env[name];
+ if (value){
+ return value;
+ }
+ throw new Meteor.Error(['var-not-exist', `The environment variable ${name} does not exist`]);
+ }
+
function sendInvitationEmail (_id){
const icode = InvitationCodes.findOne(_id);
const author = Users.findOne(Meteor.userId());
@@ -180,5 +188,14 @@ if (Meteor.isServer) {
email: user.emails[0].address,
};
},
+
+ getMatomoConf(){
+ return {
+ address: getEnvVar('MATOMO_ADDRESS'),
+ siteId: getEnvVar('MATOMO_SITE_ID'),
+ doNotTrack: process.env.MATOMO_DO_NOT_TRACK || false,
+ withUserName: process.env.MATOMO_WITH_USERNAME || false,
+ };
+ },
});
}
diff --git a/server/policy.js b/server/policy.js
new file mode 100644
index 00000000..17c90c1c
--- /dev/null
+++ b/server/policy.js
@@ -0,0 +1,9 @@
+import { BrowserPolicy } from 'meteor/browser-policy-common';
+
+Meteor.startup(() => {
+ const matomoUrl = process.env.MATOMO_ADDRESS;
+ if (matomoUrl){
+ BrowserPolicy.content.allowScriptOrigin(matomoUrl);
+ BrowserPolicy.content.allowImageOrigin(matomoUrl);
+ }
+});
diff --git a/snap-src/bin/config b/snap-src/bin/config
index 9feada7b..46fa2c3f 100755
--- a/snap-src/bin/config
+++ b/snap-src/bin/config
@@ -3,7 +3,7 @@
# All supported keys are defined here together with descriptions and default values
# list of supported keys
-keys="MONGODB_BIND_UNIX_SOCKET MONGODB_BIND_IP MONGODB_PORT MAIL_URL MAIL_FROM ROOT_URL PORT DISABLE_MONGODB CADDY_ENABLED CADDY_BIND_PORT WITH_API"
+keys="MONGODB_BIND_UNIX_SOCKET MONGODB_BIND_IP MONGODB_PORT MAIL_URL MAIL_FROM ROOT_URL PORT DISABLE_MONGODB CADDY_ENABLED CADDY_BIND_PORT WITH_API MATOMO_ADDRESS MATOMO_SITE_ID MATOMO_DO_NOT_TRACK MATOMO_WITH_USERNAME"
# default values
DESCRIPTION_MONGODB_BIND_UNIX_SOCKET="mongodb binding unix socket:\n"\
@@ -51,3 +51,17 @@ KEY_CADDY_BIND_PORT="caddy-bind-port"
DESCRIPTION_WITH_API="Enable/disable the api of wekan"
DEFAULT_WITH_API="false"
KEY_WITH_API="with-api"
+
+DESCRIPTION_MATOMO_ADDRESS="The address of the server where matomo is hosted"
+KEY_MATOMO_ADDRESS="matomo-address"
+
+DESCRIPTION_MATOMO_SITE_ID="The value of the site ID given in matomo server for wekan"
+KEY_MATOMO_SITE_ID="matomo-site-id"
+
+DESCRIPTION_MATOMO_DO_NOT_TRACK="The option do not track which enables users to not be tracked by matomo"
+DEFAULT_CADDY_BIND_PORT="false"
+KEY_MATOMO_DO_NOT_TRACK="matomo-do-not-track"
+
+DESCRIPTION_MATOMO_WITH_USERNAME="The option that allows matomo to retrieve the username"
+DEFAULT_CADDY_BIND_PORT="false"
+KEY_MATOMO_WITH_USERNAME="matomo-with-username"