Skip to content
Snippets Groups Projects
Unverified Commit ad9203de authored by vmaubert's avatar vmaubert Committed by GitHub
Browse files

fix(matomo): corrige la configuration de Matomo (#24)

parent b19d518c
No related branches found
No related tags found
No related merge requests found
...@@ -43,12 +43,15 @@ services: ...@@ -43,12 +43,15 @@ services:
build: build:
context: . context: .
dockerfile: Dockerfile.ui dockerfile: Dockerfile.ui
args:
GIT_SHA: unused
environment: environment:
UI_PORT: ${UI_PORT} UI_PORT: ${UI_PORT}
API_URL: ${API_URL} API_URL: ${API_URL}
API_MATOMO_URL: ${API_MATOMO_URL} API_MATOMO_URL: ${API_MATOMO_URL}
API_MATOMO_ID: ${API_MATOMO_ID} API_MATOMO_ID: ${API_MATOMO_ID}
ENV: ${ENV} ENV: ${ENV}
APPLICATION_VERSION: unused
ports: ports:
- ${UI_PORT}:${UI_PORT} - ${UI_PORT}:${UI_PORT}
...@@ -17,13 +17,13 @@ import store from './store' ...@@ -17,13 +17,13 @@ import store from './store'
window.ResizeObserver = window.ResizeObserver || resizeObserverPolyfill window.ResizeObserver = window.ResizeObserver || resizeObserverPolyfill
const app = createApp(App) Promise.resolve().then(async () => {
sync(store, router) const app = createApp(App)
sync(store, router)
if (import.meta.env.PROD) { if (import.meta.env.PROD) {
fetch('/sentryOptions') try {
.then(response => response.json()) const sentryResponse = await fetch('/sentryOptions')
.then(options => { const options = await sentryResponse.json()
if (!options.dsn) throw new Error('dsn manquant') if (!options.dsn) throw new Error('dsn manquant')
Sentry.init({ Sentry.init({
dsn: options.dsn, dsn: options.dsn,
...@@ -40,17 +40,18 @@ if (import.meta.env.PROD) { ...@@ -40,17 +40,18 @@ if (import.meta.env.PROD) {
// @ts-ignore // @ts-ignore
release: `camino-ui-${applicationVersion}` release: `camino-ui-${applicationVersion}`
}) })
}) } catch (e) {
.catch(e => console.error('erreur : Sentry :', e)) console.error('erreur : Sentry :', e)
}
const matomo = fetch('/matomoOptions') try {
.then(response => response.json()) const response = await fetch('/matomoOptions')
.then(options => { const options = await response.json()
if (!options || !options.host || !options.siteId) if (!options || !options.host || !options.siteId)
throw new Error('host et/ou siteId manquant(s)') throw new Error('host et/ou siteId manquant(s)')
return VueMatomo({
host: 'https://stats.data.gouv.fr', const matomo = await VueMatomo({
siteId: 70, host: options.host,
siteId: options.siteId,
router, router,
store, store,
requireConsent: false, requireConsent: false,
...@@ -60,22 +61,22 @@ if (import.meta.env.PROD) { ...@@ -60,22 +61,22 @@ if (import.meta.env.PROD) {
enableHeartBeatTimer: true, enableHeartBeatTimer: true,
enableLinkTracking: true enableLinkTracking: true
}) })
}) app.provide('matomo', matomo)
.catch(e => console.error('erreur : matomo :', e)) app.config.globalProperties.$matomo = matomo
app.provide('matomo', matomo) } catch (e) {
app.config.globalProperties.$matomo = matomo console.error('erreur : matomo :', e)
const eventSource = new EventSource('/stream/version')
eventSource.addEventListener('version', event => {
if (event.data !== applicationVersion) {
eventSource.close()
window.location.reload()
} }
})
}
app.use(router) const eventSource = new EventSource('/stream/version')
app.use(store) eventSource.addEventListener('version', event => {
if (event.data !== applicationVersion) {
app.mount('app-root') eventSource.close()
window.location.reload()
}
})
}
app.use(router)
app.use(store)
app.mount('app-root')
})
...@@ -2,7 +2,7 @@ export default function (options) { ...@@ -2,7 +2,7 @@ export default function (options) {
const { host, trackerFileName } = options const { host, trackerFileName } = options
const filename = `${host}/${trackerFileName}.js` const filename = `${host}/${trackerFileName}.js`
const scriptPromise = new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
const script = document.createElement('script') const script = document.createElement('script')
script.async = true script.async = true
script.defer = true script.defer = true
...@@ -13,13 +13,9 @@ export default function (options) { ...@@ -13,13 +13,9 @@ export default function (options) {
script.onload = resolve script.onload = resolve
script.onerror = reject script.onerror = reject
}) }).catch(error => {
scriptPromise.catch(error => {
console.info( console.info(
`Warning: ${error.target.src}. If the file exists, you may have a tracking blocker enabled.` `Warning: ${error.target.src}. If the file exists, you may have a tracking blocker enabled.`
) )
}) })
return scriptPromise
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment