Commit 4c911e62 authored by Yoan VALLET's avatar Yoan VALLET
Browse files

feat: handle remote url for matomo

parent 958098c7
......@@ -61,6 +61,7 @@ const setupApp = memoize(() => {
Piwik.getTracker()
const tracker = new MatomoTracker({
cozyUrl: cozyUrl,
url: __PIWIK_TRACKER_URL__,
siteId: __PIWIK_SITEID__,
history: history,
......
......@@ -2,6 +2,7 @@ import { History, Location, UnregisterCallback } from 'history'
import { readCozyDataFromDOM } from 'cozy-ui/transpiled/react/helpers/appDataset'
interface InitSettings {
cozyUrl: string
url: string
siteId: number
history: History
......@@ -15,6 +16,7 @@ declare global {
}
export default class MatomoTracker {
cozyUrl: string
url: string
siteId: number
phpFilename: string
......@@ -23,6 +25,7 @@ export default class MatomoTracker {
unlistenFromHistory: UnregisterCallback
constructor({
cozyUrl,
url,
siteId,
history,
......@@ -33,6 +36,7 @@ export default class MatomoTracker {
'MatomoTracker cannot be initialized! SiteId and url are mandatory.'
)
}
this.cozyUrl = cozyUrl
this.url = url
this.siteId = siteId
this.phpFilename = phpFilename
......@@ -48,6 +52,9 @@ export default class MatomoTracker {
if (url.indexOf('http://') !== -1 || url.indexOf('https://') !== -1) {
url = `${url}/`
} else if (url.indexOf('/remote') !== -1) {
//use of remote doctype
url = `${this.cozyUrl}${url}/`
} else {
url =
document.location.protocol === 'https:'
......@@ -58,7 +65,11 @@ export default class MatomoTracker {
window._paq = window._paq || []
MatomoTracker.push(['enableHeartBeatTimer', 30])
MatomoTracker.push(['setSiteId', this.siteId])
MatomoTracker.push(['setTrackerUrl', `${url + this.phpFilename}`])
// MatomoTracker.push(['setTrackerUrl', `${url + this.phpFilename}`])
MatomoTracker.push([
'setTrackerUrl',
`http://cozy.tools:8080/remote/org.ecolyo.matomo.rec`,
])
MatomoTracker.push(['enableLinkTracking'])
}
return {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment