diff --git a/app.config.environment.dev.js b/app.config.environment.dev.js index 8cb7804264915ccc335702a63d7e3a7f60c1786b..120aa2a2de67d54d8631f0eddd1dfe898241a24d 100644 --- a/app.config.environment.dev.js +++ b/app.config.environment.dev.js @@ -21,8 +21,8 @@ const stackProvidedLibsConfig = { __IS_ALPHA__: true, __DEVELOPMENT__: true, __STACK_ASSETS__: true, - __PIWIK_TRACKER_URL__: JSON.stringify('http://localhost:9800/'), - __PIWIK_SITEID__: 1, + __PIWIK_TRACKER_URL__: JSON.stringify('https://statweb.grandlyon.com/'), + __PIWIK_SITEID__: 117, __SAU_LINK__: JSON.stringify( 'https://portail-citoyen-sau.guichet-recette.grandlyon.com/ecolyo/' ), diff --git a/package.json b/package.json index 7dbcefe73ea6db47b96265b36722c94708f80fde..078cbad6662922ab224f0793b1b3cd58c1844e5e 100644 --- a/package.json +++ b/package.json @@ -86,6 +86,7 @@ "@types/d3": "^6.0.0", "@types/enzyme": "^3.10.8", "@types/file-saver": "^2.0.5", + "@types/history": "^5.0.0", "@types/jest": "^29.0.0", "@types/lodash": "^4.14.149", "@types/luxon": "^3.0.0", diff --git a/src/components/App.tsx b/src/components/App.tsx index 5de0b85096d762cf1c1a77fdc5a81c55d859aff8..fd0b11c37075af7f4debe63a30733d460af47bd7 100644 --- a/src/components/App.tsx +++ b/src/components/App.tsx @@ -7,29 +7,22 @@ import SplashScreenError from 'components/Splash/SplashScreenError' import { Content, Layout, Main } from 'cozy-ui/transpiled/react/Layout' import React, { useEffect } from 'react' import { useSelector } from 'react-redux' -import EnvironmentService from 'services/environment.service' +import { useLocation } from 'react-router-dom' import { AppStore } from 'store' import MatomoTracker from 'utils/matomoTracker' interface AppProps { - tracker: MatomoTracker + tracker: undefined | MatomoTracker } export const App = ({ tracker }: AppProps) => { + const location = useLocation() const { onboarding } = useSelector((state: AppStore) => state.ecolyo.profile) const { termsStatus } = useSelector((state: AppStore) => state.ecolyo.global) - const isDev = new EnvironmentService().isLocal() useEffect(() => { - if (tracker && !isDev) { - if (termsStatus.accepted) { - tracker.connectToHistory() - } - return () => { - tracker.disconnectFromHistory() - } - } - }, [termsStatus.accepted, tracker, isDev]) + tracker?.track(location) + }, [tracker, location]) return ( <Layout> diff --git a/src/targets/browser/index.tsx b/src/targets/browser/index.tsx index f6ae853033dc29899b76261c543dbedfb47c23c9..eb5836f4578cd219bcb3568be388fe65e718b80e 100644 --- a/src/targets/browser/index.tsx +++ b/src/targets/browser/index.tsx @@ -12,7 +12,7 @@ import CozyClient, { Client, CozyProvider } from 'cozy-client' import { handleOAuthResponse } from 'cozy-harvest-lib/dist/helpers/oauth' import { I18n, initTranslation } from 'cozy-ui/transpiled/react/I18n' import schema from 'doctypes' -import { createBrowserHistory, History } from 'history' +import { createHashHistory, History } from 'history' import { memoize } from 'lodash' import React from 'react' import { render } from 'react-dom' @@ -26,7 +26,7 @@ import manifest from '../../../manifest.webapp' import '../../styles/index.scss' const setupApp = memoize(() => { - const history: History = createBrowserHistory() + const history: History = createHashHistory() // eslint-disable-next-line @typescript-eslint/no-explicit-any const root: any = document.querySelector('[role=application]') const data = JSON.parse(root.dataset.cozy) @@ -65,7 +65,7 @@ const setupApp = memoize(() => { appNamePrefix: data.app.prefix, }) - let tracker + let tracker: undefined | MatomoTracker if (window.Piwik) { Piwik.getTracker() tracker = new MatomoTracker({ diff --git a/src/utils/matomoTracker.ts b/src/utils/matomoTracker.ts index 3cc3aaf0b5f2c4fc2356439f290af8b832ee979b..1fe084049f77000e7520041bd74f56d530e58765 100644 --- a/src/utils/matomoTracker.ts +++ b/src/utils/matomoTracker.ts @@ -1,5 +1,6 @@ import { readCozyDataFromDOM } from 'cozy-ui/transpiled/react/helpers/appDataset' -import { History, Location, UnregisterCallback } from 'history' +import { History } from 'history' +import { Location } from 'react-router' interface InitSettings { cozyUrl: string @@ -11,8 +12,8 @@ interface InitSettings { declare global { interface Window { - _paq: any - Piwik: any + _paq: { push: (arg0: unknown) => void } + Piwik: unknown } } @@ -22,7 +23,7 @@ export default class MatomoTracker { siteId: number phpFilename: string history: History - unlistenFromHistory: UnregisterCallback + tracking = false constructor({ cozyUrl, @@ -41,7 +42,6 @@ export default class MatomoTracker { this.siteId = siteId this.phpFilename = phpFilename this.history = history - this.unlistenFromHistory = () => null this.init() } @@ -57,8 +57,6 @@ export default class MatomoTracker { return { push: MatomoTracker.push, track: this.track, - connectToHistory: this.connectToHistory, - disconnectFromHistory: this.disconnectFromHistory, } } @@ -82,28 +80,15 @@ export default class MatomoTracker { } } - connectToHistory() { - this.unlistenFromHistory = this.history.listen(loc => { - this.track(loc) - }) - } - - disconnectFromHistory() { - if (this.unlistenFromHistory) { - this.unlistenFromHistory() - return true - } - return false - } - + /** If matomo find a cookie "mtm_consent_removed" tracking will not be sent */ track(loc: Location) { if (typeof window === 'undefined') { return } const currentPath = loc.hash.substring(1) - MatomoTracker.push(['setDocumentTitle', currentPath.substring(1)]) MatomoTracker.push(['setCustomUrl', 'https://ecolyo.com' + currentPath]) + MatomoTracker.push(['setDocumentTitle', currentPath.substring(1)]) MatomoTracker.push(['trackPageView']) } } diff --git a/yarn.lock b/yarn.lock index d646a1114bc68079d84f08507e0927a1e42d833f..64de230e88f3da932dd72cdc2c458e9b92f71ef9 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1481,9 +1481,9 @@ regenerator-runtime "^0.13.4" "@babel/runtime@^7.7.6": - version "7.20.7" - resolved "https://registry.yarnpkg.com/@babel/runtime/-/runtime-7.20.7.tgz#fcb41a5a70550e04a7b708037c7c32f7f356d8fd" - integrity sha512-UF0tvkUtxwAgZ5W/KrkHf0Rn0fdnLDU9ScxBrEVNUprE/MzirjK4MJUX1/BVDv00Sv8cljtukVK1aky++X1SjQ== + version "7.20.13" + resolved "https://registry.yarnpkg.com/@babel/runtime/-/runtime-7.20.13.tgz#7055ab8a7cff2b8f6058bf6ae45ff84ad2aded4b" + integrity sha512-gt3PKXs0DBoL9xCvOIIZ2NEqAGZqHjAnmVbfQtB620V0uReIQutpel14KcneZuer7UioY8ALKZ7iocavvzTNFA== dependencies: regenerator-runtime "^0.13.11" @@ -2757,6 +2757,13 @@ resolved "https://registry.yarnpkg.com/@types/history/-/history-4.7.11.tgz#56588b17ae8f50c53983a524fc3cc47437969d64" integrity sha512-qjDJRrmvBMiTx+jyLxvLfJU7UznFuokDv4f3WRuriHKERccVpFU+8XMQUAbDzoiJCsmexxRExQeMwwCdamSKDA== +"@types/history@^5.0.0": + version "5.0.0" + resolved "https://registry.yarnpkg.com/@types/history/-/history-5.0.0.tgz#29f919f0c8e302763798118f45b19cab4a886f14" + integrity sha512-hy8b7Y1J8OGe6LbAjj3xniQrj3v6lsivCcrmf4TzSgPzLkhIeKgc5IZnT7ReIqmEuodjfO8EYAuoFvIrHi/+jQ== + dependencies: + history "*" + "@types/hoist-non-react-statics@^3.3.0": version "3.3.1" resolved "https://registry.yarnpkg.com/@types/hoist-non-react-statics/-/hoist-non-react-statics-3.3.1.tgz#1124aafe5118cb591977aeb1ceaaed1070eb039f" @@ -3054,11 +3061,6 @@ resolved "https://registry.yarnpkg.com/@typescript-eslint/types/-/types-5.37.0.tgz#09e4870a5f3af7af3f84e08d792644a87d232261" integrity sha512-3frIJiTa5+tCb2iqR/bf7XwU20lnU05r/sgPJnRpwvfZaqCJBrl8Q/mw9vr3NrNdB/XtVyMA0eppRMMBqdJ1bA== -"@typescript-eslint/types@5.44.0": - version "5.44.0" - resolved "https://registry.yarnpkg.com/@typescript-eslint/types/-/types-5.44.0.tgz#f3f0b89aaff78f097a2927fe5688c07e786a0241" - integrity sha512-Tp+zDnHmGk4qKR1l+Y1rBvpjpm5tGXX339eAlRBDg+kgZkz9Bw+pqi4dyseOZMsGuSH69fYfPJCBKBrbPCxYFQ== - "@typescript-eslint/typescript-estree@5.30.5": version "5.30.5" resolved "https://registry.yarnpkg.com/@typescript-eslint/typescript-estree/-/typescript-estree-5.30.5.tgz#c520e4eba20551c4ec76af8d344a42eb6c9767bb" @@ -3113,14 +3115,6 @@ "@typescript-eslint/types" "5.37.0" eslint-visitor-keys "^3.3.0" -"@typescript-eslint/visitor-keys@5.44.0": - version "5.44.0" - resolved "https://registry.yarnpkg.com/@typescript-eslint/visitor-keys/-/visitor-keys-5.44.0.tgz#10740dc28902bb903d12ee3a005cc3a70207d433" - integrity sha512-a48tLG8/4m62gPFbJ27FxwCOqPKxsb8KC3HkmYoq2As/4YyjQl1jDbRr1s63+g4FS/iIehjmN3L5UjmKva1HzQ== - dependencies: - "@typescript-eslint/types" "5.44.0" - eslint-visitor-keys "^3.3.0" - "@webassemblyjs/ast@1.9.0": version "1.9.0" resolved "https://registry.yarnpkg.com/@webassemblyjs/ast/-/ast-1.9.0.tgz#bd850604b4042459a5a41cd7d338cbed695ed964" @@ -8735,7 +8729,7 @@ highlight.js@^10.7.1: resolved "https://registry.yarnpkg.com/highlight.js/-/highlight.js-10.7.3.tgz#697272e3991356e40c3cac566a74eef681756531" integrity sha512-tzcUFauisWKNHaRkN4Wjl/ZA07gENAjFl3J/c480dprkGTg5EQstgaNFqBfUqCq54kZRIEcreTsAgF/m2quD7A== -history@^5.3.0: +history@*, history@^5.3.0: version "5.3.0" resolved "https://registry.yarnpkg.com/history/-/history-5.3.0.tgz#1548abaa245ba47992f063a0783db91ef201c73b" integrity sha512-ZqaKwjjrAYUYfLG+htGaIIZ4nioX2L70ZUMIFysS3xvBsSG4x/n1V6TXV3N8ZYNuFGlDirFg32T7B6WOUPDYcQ==