peertube-theme-nctv-dark/peertube-plugin-matomo/client/common-client-plugin.js

33 lines
815 B
JavaScript
Raw Normal View History

import { initMatomo } from './utils'
2019-07-26 07:43:20 +00:00
function register ({ registerHook, peertubeHelpers }) {
init(registerHook, peertubeHelpers)
.catch(err => console.error('Cannot initialize Matomo plugin', err))
2019-07-26 07:43:20 +00:00
}
export {
register
}
async function init (registerHook, peertubeHelpers) {
const success = await initMatomo(peertubeHelpers)
if (!success) return
2019-07-26 07:43:20 +00:00
registerHook({
target: 'action:router.navigation-end',
handler: function (params) {
2019-07-26 07:43:20 +00:00
window._paq.push(['setDocumentTitle', window.document.title]);
window._paq.push(['setCustomUrl', params.path]);
2019-07-26 07:43:20 +00:00
window._paq.push(['trackPageView']);
}
})
registerHook({
target: 'action:video-watch.player.loaded',
handler: function () {
window._paq.push(['MediaAnalytics::scanForMedia', window.document]);
}
})
2019-07-26 07:43:20 +00:00
}