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(() => { ...@@ -61,6 +61,7 @@ const setupApp = memoize(() => {
Piwik.getTracker() Piwik.getTracker()
const tracker = new MatomoTracker({ const tracker = new MatomoTracker({
cozyUrl: cozyUrl,
url: __PIWIK_TRACKER_URL__, url: __PIWIK_TRACKER_URL__,
siteId: __PIWIK_SITEID__, siteId: __PIWIK_SITEID__,
history: history, history: history,
......
...@@ -2,6 +2,7 @@ import { History, Location, UnregisterCallback } from 'history' ...@@ -2,6 +2,7 @@ import { History, Location, UnregisterCallback } from 'history'
import { readCozyDataFromDOM } from 'cozy-ui/transpiled/react/helpers/appDataset' import { readCozyDataFromDOM } from 'cozy-ui/transpiled/react/helpers/appDataset'
interface InitSettings { interface InitSettings {
cozyUrl: string
url: string url: string
siteId: number siteId: number
history: History history: History
...@@ -15,6 +16,7 @@ declare global { ...@@ -15,6 +16,7 @@ declare global {
} }
export default class MatomoTracker { export default class MatomoTracker {
cozyUrl: string
url: string url: string
siteId: number siteId: number
phpFilename: string phpFilename: string
...@@ -23,6 +25,7 @@ export default class MatomoTracker { ...@@ -23,6 +25,7 @@ export default class MatomoTracker {
unlistenFromHistory: UnregisterCallback unlistenFromHistory: UnregisterCallback
constructor({ constructor({
cozyUrl,
url, url,
siteId, siteId,
history, history,
...@@ -33,6 +36,7 @@ export default class MatomoTracker { ...@@ -33,6 +36,7 @@ export default class MatomoTracker {
'MatomoTracker cannot be initialized! SiteId and url are mandatory.' 'MatomoTracker cannot be initialized! SiteId and url are mandatory.'
) )
} }
this.cozyUrl = cozyUrl
this.url = url this.url = url
this.siteId = siteId this.siteId = siteId
this.phpFilename = phpFilename this.phpFilename = phpFilename
...@@ -48,6 +52,9 @@ export default class MatomoTracker { ...@@ -48,6 +52,9 @@ export default class MatomoTracker {
if (url.indexOf('http://') !== -1 || url.indexOf('https://') !== -1) { if (url.indexOf('http://') !== -1 || url.indexOf('https://') !== -1) {
url = `${url}/` url = `${url}/`
} else if (url.indexOf('/remote') !== -1) {
//use of remote doctype
url = `${this.cozyUrl}${url}/`
} else { } else {
url = url =
document.location.protocol === 'https:' document.location.protocol === 'https:'
...@@ -58,7 +65,11 @@ export default class MatomoTracker { ...@@ -58,7 +65,11 @@ export default class MatomoTracker {
window._paq = window._paq || [] window._paq = window._paq || []
MatomoTracker.push(['enableHeartBeatTimer', 30]) MatomoTracker.push(['enableHeartBeatTimer', 30])
MatomoTracker.push(['setSiteId', this.siteId]) 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']) MatomoTracker.push(['enableLinkTracking'])
} }
return { return {
......
Supports Markdown
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