Add matomo plugin
This commit is contained in:
parent
73a0294104
commit
9c37c5e7f6
3
peertube-plugin-matomo/README.md
Normal file
3
peertube-plugin-matomo/README.md
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
# Hello World plugin
|
||||||
|
|
||||||
|
Just a PeerTube plugin example, that says "Hello world".
|
46
peertube-plugin-matomo/client/common-client-plugin.js
Normal file
46
peertube-plugin-matomo/client/common-client-plugin.js
Normal file
@ -0,0 +1,46 @@
|
|||||||
|
function register ({ registerHook, peertubeHelpers }) {
|
||||||
|
initMatomo(registerHook, peertubeHelpers)
|
||||||
|
.catch(err => console.error('Cannot initialize Matomo', err))
|
||||||
|
}
|
||||||
|
|
||||||
|
export {
|
||||||
|
register
|
||||||
|
}
|
||||||
|
|
||||||
|
function initMatomo (registerHook, peertubeHelpers) {
|
||||||
|
return peertubeHelpers.getSettings()
|
||||||
|
.then(s => {
|
||||||
|
if (!s || !s['site-id'] || !s['url']) {
|
||||||
|
console.error('Matomo settings are not set.')
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
const matomoUrl = s['url']
|
||||||
|
const siteId = s['site-id']
|
||||||
|
|
||||||
|
window._paq = window._paq || [];
|
||||||
|
window._paq.push(['trackPageView']);
|
||||||
|
window._paq.push(['enableLinkTracking']);
|
||||||
|
(function() {
|
||||||
|
var u = matomoUrl + '/';
|
||||||
|
window._paq.push(['setTrackerUrl', u+'matomo.php']);
|
||||||
|
window._paq.push(['setSiteId', siteId]);
|
||||||
|
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);
|
||||||
|
})();
|
||||||
|
|
||||||
|
window._paq.push(['setDocumentTitle', window.document.title]);
|
||||||
|
window._paq.push(['setCustomUrl', '/' + window.location.hash.substr(1)]);
|
||||||
|
window._paq.push(['trackPageView']);
|
||||||
|
|
||||||
|
registerHook({
|
||||||
|
target: 'action:router.navigation-end',
|
||||||
|
handler: function (params) {
|
||||||
|
window._paq.push(['setDocumentTitle', window.document.title]);
|
||||||
|
window._paq.push(['setCustomUrl', params.path]);
|
||||||
|
window._paq.push(['trackPageView']);
|
||||||
|
}
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
}
|
26
peertube-plugin-matomo/main.js
Normal file
26
peertube-plugin-matomo/main.js
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
async function register ({ registerHook, registerSetting, settingsManager, storageManager }) {
|
||||||
|
registerSetting({
|
||||||
|
name: 'url',
|
||||||
|
label: 'Matomo Url',
|
||||||
|
type: 'input',
|
||||||
|
private: false
|
||||||
|
})
|
||||||
|
|
||||||
|
registerSetting({
|
||||||
|
name: 'site-id',
|
||||||
|
label: 'Site id',
|
||||||
|
type: 'input',
|
||||||
|
private: false
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
async function unregister () {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = {
|
||||||
|
register,
|
||||||
|
unregister
|
||||||
|
}
|
||||||
|
|
||||||
|
// ############################################################################
|
24
peertube-plugin-matomo/package.json
Normal file
24
peertube-plugin-matomo/package.json
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
{
|
||||||
|
"name": "peertube-plugin-matomo",
|
||||||
|
"version": "0.0.1",
|
||||||
|
"description": "Hello world PeerTube plugin example",
|
||||||
|
"engine": {
|
||||||
|
"peertube": ">=1.3.0"
|
||||||
|
},
|
||||||
|
"keywords": [
|
||||||
|
"peertube",
|
||||||
|
"plugin"
|
||||||
|
],
|
||||||
|
"homepage": "https://framagit.org/framasoft/peertube/official-plugins/tree/master/peertube-plugin-matomo",
|
||||||
|
"author": "Chocobozzz",
|
||||||
|
"bugs": "https://framagit.org/framasoft/peertube/official-plugins/issues",
|
||||||
|
"library": "./main.js",
|
||||||
|
"staticDirs": {},
|
||||||
|
"css": [],
|
||||||
|
"clientScripts": [
|
||||||
|
{
|
||||||
|
"script": "client/common-client-plugin.js",
|
||||||
|
"scopes": [ "common" ]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user