Compare commits

...

8 Commits

Author SHA1 Message Date
YuCheng Hu 965e762310 Update the link and config 2024-01-15 12:20:02 -05:00
YuCheng Hu 346d08559f Update the information and try to fixed the issue for https://www.isharkfly.com/t/discourse/15258/2 2024-01-12 22:43:15 -05:00
honeymoose e56e9cb9c9 Update about.json 2024-01-13 03:30:32 +00:00
YuCheng Hu 1c8225fb78 change document link 2020-05-20 17:19:47 -04:00
YuCheng Hu 2d755f9849 Add words for CWIKI 2020-05-20 16:53:07 -04:00
YuCheng Hu d6ca673710 Change new lic link 2020-05-20 16:42:42 -04:00
YuCheng Hu 758d48ec96 Change to matomo.js 2020-05-20 16:29:33 -04:00
Ryan Boder bbd0dcb82d Fix current user issue and add tracking features (#1)
* Add cross subdomain tracking

* Add cross subdomain tracking

* Enable crossdomain linking

* Move crossdomain code to a better place

* Remove subdomain from site title

* Fix all subdomains parameter

* Be more specific in subdomain tracking description

* Add user ID tracking

* Handle whitespace around user id field

* Exclude some groups from tracking

* Add exmaple groups to exclude from tracking

* Fix whitespace handling in user ID tracking

* Fix null reference on anonymous users
2019-09-19 13:04:24 -04:00
4 changed files with 40 additions and 9 deletions

View File

@ -1,6 +1,6 @@
MIT License
Copyright (c) 2018 Kyle Zhao
Copyright (c) 2024 iSharkFly
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal

View File

@ -1,6 +1,6 @@
{
"name": "Matomo Analytics",
"about_url": "https://meta.discourse.org/t/how-to-enable-matomo-analytics-on-discourse/33090",
"license_url": "https://github.com/discourse/discourse-matomo-analytics/blob/master/LICENSE",
"name": "iSharkFly Matomo Analytics",
"about_url": "https://www.isharkfly.com/t/discourse-matomo/51",
"license_url": "https://github.com/Discourse-C/discourse-matomo-analytics/blob/master/LICENSE",
"component": true
}
}

View File

@ -1,19 +1,38 @@
<script type="text/discourse-plugin" version="0.2">
api.onPageChange((url, title) => {
const currentUser = api.getCurrentUser();
if (settings.exclude_groups.trim() && currentUser) {
const excludedGroups = settings.exclude_groups.split(",").map(g => g.trim());
const currentUserGroups = currentUser.groups.map(g => g.name);
if (excludedGroups.filter(g => currentUserGroups.includes(g)).length) {
return;
}
}
window._paq = window._paq || [];
window._paq_loaded = window._paq_loaded || false;
if (!_paq_loaded) {
var u = `//${settings.host_url}/`;
_paq.push(['setTrackerUrl', u+'piwik.php']);
_paq.push(['setTrackerUrl', u+'matomo.php']);
_paq.push(['setSiteId', settings.website_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+'piwik.js'; s.parentNode.insertBefore(g,s);
g.type='text/javascript'; g.async=true; g.defer=true; g.src=u+'matomo.js'; s.parentNode.insertBefore(g,s);
_paq_loaded = true;
}
const currentUser = api._currentUser;
_paq.push(['setCustomVariable', 1, 'Anonymous', !currentUser, 'visit']);
const userIdField = settings.user_id_tracking.trim();
if (userIdField && currentUser && currentUser[userIdField]) {
_paq.push(['setUserId', currentUser[userIdField]]);
}
if (settings.subdomain_tracking) {
const allDomains = "*" + document.domain.substring(document.domain.indexOf("."));
_paq.push(["setCookieDomain", allDomains]);
_paq.push(["setDomains", allDomains]);
}
_paq.push(["setCustomUrl", url]);
_paq.push(["setDocumentTitle", title]);
_paq.push(["trackPageView"]);

View File

@ -5,3 +5,15 @@ host_url:
website_id:
type: string
default: ''
exclude_groups:
type: string
default: ''
description: Comma separated list of groups to exclude from tracking such as admins, staff.
user_id_tracking:
type: string
default: ''
description: An indentifying field name on the current user object such as id, username or external_id.
subdomain_tracking:
type: bool
default: false
description: Track visitors across main domain & subdomains, assuming discourse is on a subdomain.