peertube-theme-nctv-dark/peertube-plugin-matomo/client/common-client-plugin.js
2022-03-23 11:08:30 +01:00

33 lines
815 B
JavaScript

import { initMatomo } from './utils'
function register ({ registerHook, peertubeHelpers }) {
init(registerHook, peertubeHelpers)
.catch(err => console.error('Cannot initialize Matomo plugin', err))
}
export {
register
}
async function init (registerHook, peertubeHelpers) {
const success = await initMatomo(peertubeHelpers)
if (!success) return
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']);
}
})
registerHook({
target: 'action:video-watch.player.loaded',
handler: function () {
window._paq.push(['MediaAnalytics::scanForMedia', window.document]);
}
})
}