2022-03-23 10:05:08 +00:00
|
|
|
import { initMatomo } from './utils'
|
|
|
|
|
2019-07-26 07:43:20 +00:00
|
|
|
function register ({ registerHook, peertubeHelpers }) {
|
2022-03-23 10:05:08 +00:00
|
|
|
init(registerHook, peertubeHelpers)
|
|
|
|
.catch(err => console.error('Cannot initialize Matomo plugin', err))
|
2019-07-26 07:43:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
export {
|
|
|
|
register
|
|
|
|
}
|
|
|
|
|
2022-03-23 10:05:08 +00:00
|
|
|
async function init (registerHook, peertubeHelpers) {
|
|
|
|
const success = await initMatomo(peertubeHelpers)
|
|
|
|
if (!success) return
|
2019-07-26 07:43:20 +00:00
|
|
|
|
2022-03-23 10:05:08 +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]);
|
2022-03-23 10:05:08 +00:00
|
|
|
window._paq.push(['setCustomUrl', params.path]);
|
2019-07-26 07:43:20 +00:00
|
|
|
window._paq.push(['trackPageView']);
|
2022-03-23 10:05:08 +00:00
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
registerHook({
|
|
|
|
target: 'action:video-watch.player.loaded',
|
|
|
|
handler: function () {
|
|
|
|
window._paq.push(['MediaAnalytics::scanForMedia', window.document]);
|
|
|
|
}
|
|
|
|
})
|
2019-07-26 07:43:20 +00:00
|
|
|
}
|
2022-03-23 10:05:08 +00:00
|
|
|
|