diff --git a/src/targets/browser/index.tsx b/src/targets/browser/index.tsx index 93fcbc519c14ef21dabe8e3e9b6e99c24f0a4516..836a1b589cd98af765f6969216463fa73a3b8b0e 100644 --- a/src/targets/browser/index.tsx +++ b/src/targets/browser/index.tsx @@ -21,12 +21,13 @@ import schema from 'doctypes' import { createBrowserHistory, History } from 'history' import { HashRouter } from 'react-router-dom' import MatomoTracker from 'utils/matomoTracker' +import { CozyData } from 'types/cozy-data' const setupApp = memoize(() => { const history: History = createBrowserHistory() // eslint-disable-next-line @typescript-eslint/no-explicit-any const root: any = document.querySelector('[role=application]') - const data = JSON.parse(root.dataset.cozy) + const data: CozyData = JSON.parse(root.dataset.cozy) const protocol = window.location.protocol const cozyUrl = `${protocol}//${data.domain}` diff --git a/src/types/cozy-data.d.ts b/src/types/cozy-data.d.ts new file mode 100644 index 0000000000000000000000000000000000000000..58550d08ff8d33b9cb14f1cb579f17f9bc16dfc8 --- /dev/null +++ b/src/types/cozy-data.d.ts @@ -0,0 +1,21 @@ +export type CozyData = { + app: { + editor: string + icon: string + name: string + prefix: string + slug: string + } + capabilities: { + file_versioning: boolean + flat_subdomains: boolean + can_auth_with_password: boolean + can_auth_with_oidc: boolean + } + domain: string + flags: any + locale: string + subdomain: string + token: string + tracking: boolean +} diff --git a/src/utils/matomoTracker.ts b/src/utils/matomoTracker.ts index 2e43776d5a1a1f20373fc6f9f8b2bb19fabc9280..184f51f3731cc0f2301bb7191d6b5cdff23ff239 100644 --- a/src/utils/matomoTracker.ts +++ b/src/utils/matomoTracker.ts @@ -1,6 +1,6 @@ import { History, Location, UnregisterCallback } from 'history' -import { readCozyDataFromDOM } from 'cozy-ui/transpiled/react/helpers/appDataset' import hash from 'object-hash' +import { CozyData } from 'types/cozy-data' interface InitSettings { cozyUrl: string @@ -72,8 +72,9 @@ export default class MatomoTracker { let cozyDomain let userId const root: any = document.querySelector('[role=application]') - if (root && root.dataset) { - cozyDomain = readCozyDataFromDOM('cozyDomain') + const data: CozyData = JSON.parse(root.dataset.cozy) + if (root && data) { + cozyDomain = data.domain } if (cozyDomain) { userId = cozyDomain