Compare commits
8 Commits
csp-extens
...
main
Author | SHA1 | Date |
---|---|---|
YuCheng Hu | 965e762310 | |
YuCheng Hu | 346d08559f | |
honeymoose | e56e9cb9c9 | |
YuCheng Hu | 1c8225fb78 | |
YuCheng Hu | 2d755f9849 | |
YuCheng Hu | d6ca673710 | |
YuCheng Hu | 758d48ec96 | |
Ryan Boder | bbd0dcb82d |
2
LICENSE
2
LICENSE
|
@ -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
|
||||
|
|
|
@ -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
|
||||
}
|
||||
}
|
|
@ -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"]);
|
||||
|
|
12
settings.yml
12
settings.yml
|
@ -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.
|
||||
|
|
Loading…
Reference in New Issue