diff --git a/app/api/tenants/tenantContext.ts b/app/api/tenants/tenantContext.ts index 223118d8d9..36bf81855c 100644 --- a/app/api/tenants/tenantContext.ts +++ b/app/api/tenants/tenantContext.ts @@ -3,7 +3,7 @@ import { handleError } from 'api/utils'; import { appContext } from 'api/utils/AppContext'; import { TenantDocument, TenantsModel, DBTenant, tenantsModel } from './tenantsModel'; -export type Tenant = { +type Tenant = { name: string; dbName: string; indexName: string; @@ -14,6 +14,7 @@ export type Tenant = { featureFlags?: { s3Storage?: boolean; }; + globalMatomo?: { id: string; url: string }; }; class Tenants { @@ -81,3 +82,4 @@ class Tenants { const tenants = new Tenants(config.defaultTenant); export { tenants }; +export type { Tenant }; diff --git a/app/react/App.tsx b/app/react/App.tsx index 18357b17be..990346a0e9 100644 --- a/app/react/App.tsx +++ b/app/react/App.tsx @@ -1,10 +1,16 @@ import React from 'react'; import { RouterProvider, createBrowserRouter } from 'react-router-dom'; -import { createStore, Provider } from 'jotai'; +import { Provider } from 'jotai'; import { Provider as ReduxProvider } from 'react-redux'; import { getRoutes } from './Routes'; import CustomProvider from './App/Provider'; -import { settingsAtom, templatesAtom, translationsAtom, thesaurisAtom } from './V2/atoms'; +import { + settingsAtom, + templatesAtom, + translationsAtom, + thesaurisAtom, + atomStore, +} from './V2/atoms'; import { relationshipTypesAtom } from './V2/atoms/relationshipTypes'; import { store } from './store'; @@ -16,7 +22,6 @@ const thesauris = reduxState?.thesauris.toJS() || []; const router = createBrowserRouter(getRoutes(settings, reduxState?.user.get('_id'))); -const atomStore = createStore(); atomStore.set(settingsAtom, settings); atomStore.set(templatesAtom, templates); atomStore.set(thesaurisAtom, thesauris); diff --git a/app/react/App/App.js b/app/react/App/App.js index 65ca9082ee..bc3e17a679 100644 --- a/app/react/App/App.js +++ b/app/react/App/App.js @@ -8,13 +8,13 @@ import { TranslateForm, t } from 'app/I18N'; import { Icon } from 'UI'; import { socket } from 'app/socket'; import { NotificationsContainer } from 'V2/Components/UI'; -import { settingsAtom } from 'app/V2/atoms/settingsAtom'; +import { Matomo } from 'app/V2/Components/Analitycs'; +import { settingsAtom } from 'V2/atoms/settingsAtom'; import Confirm from './Confirm'; import { Menu } from './Menu'; import { AppMainContext } from './AppMainContext'; import SiteName from './SiteName'; import GoogleAnalytics from './GoogleAnalytics'; -import { Matomo } from './Matomo'; import 'react-widgets/dist/css/react-widgets.css'; import 'bootstrap/dist/css/bootstrap.css'; import 'nprogress/nprogress.css'; diff --git a/app/react/App/Matomo.js b/app/react/App/Matomo.js deleted file mode 100644 index b12895cbf5..0000000000 --- a/app/react/App/Matomo.js +++ /dev/null @@ -1,52 +0,0 @@ -import { useEffect } from 'react'; -import { connect } from 'react-redux'; -import PropTypes from 'prop-types'; - -const MatomoComponent = ({ id, url }) => { - useEffect(() => { - if (id && url) { - const matomoUrl = url.replace(/\/?$/, '/'); - - const script = document.createElement('script'); - - script.innerHTML = ` - var _paq = _paq || []; - _paq.push(['trackPageView']); - _paq.push(['enableLinkTracking']); - (function() { - var u="${matomoUrl}"; - _paq.push(['setTrackerUrl', u+'piwik.php']); - _paq.push(['setSiteId', '${id}']); - var d=document, g=d.createElement('script'), s=d.getElementsByTagName('script')[0]; - g.type='text/javascript'; g.async=true; g.defer=true; g.src=u+'piwik.js'; s.parentNode.insertBefore(g,s); - })();`; - - document.body.appendChild(script); - } - }, [id, url]); - - return undefined; -}; - -MatomoComponent.defaultProps = { - id: '', - url: '', -}; - -MatomoComponent.propTypes = { - id: PropTypes.string, - url: PropTypes.string, -}; - -function mapStateToProps({ settings }) { - try { - const { id, url } = JSON.parse(settings.collection.get('matomoConfig')); - return { id, url }; - } catch (e) { - return {}; - } -} - -const Matomo = connect(mapStateToProps)(MatomoComponent); - -export { Matomo, MatomoComponent, mapStateToProps }; diff --git a/app/react/App/Root.js b/app/react/App/Root.js index 7ffbfb8637..87bd11451f 100644 --- a/app/react/App/Root.js +++ b/app/react/App/Root.js @@ -71,6 +71,10 @@ class Root extends Component { innerHtml += `window.__user__ = ${serialize(this.props.user, { isJSON: true })};`; } + if (this.props.atomStoreData) { + innerHtml += `window.__atomStoreData__ = ${serialize(this.props.atomStoreData, { isJSON: true })};`; + } + return (