2017-05-12 00:23:56 +00:00
|
|
|
// @flow
|
2018-02-11 07:23:50 +00:00
|
|
|
import * as React from 'react';
|
2016-02-27 21:53:11 +00:00
|
|
|
import { render } from 'react-dom';
|
2016-06-26 06:31:22 +00:00
|
|
|
import { Provider } from 'mobx-react';
|
2018-08-10 06:14:51 +00:00
|
|
|
import { BrowserRouter as Router } from 'react-router-dom';
|
2016-06-26 06:31:22 +00:00
|
|
|
import stores from 'stores';
|
2016-02-27 21:53:11 +00:00
|
|
|
|
2017-11-13 00:08:55 +00:00
|
|
|
import ErrorBoundary from 'components/ErrorBoundary';
|
2017-07-03 05:16:48 +00:00
|
|
|
import ScrollToTop from 'components/ScrollToTop';
|
2018-12-17 01:57:41 +00:00
|
|
|
import Toasts from 'components/Toasts';
|
2019-03-13 04:35:35 +00:00
|
|
|
import Theme from 'components/Theme';
|
2018-08-10 06:14:51 +00:00
|
|
|
import Routes from './routes';
|
2017-09-04 21:48:56 +00:00
|
|
|
|
2016-06-26 05:43:28 +00:00
|
|
|
let DevTools;
|
|
|
|
if (__DEV__) {
|
2016-08-03 12:00:17 +00:00
|
|
|
DevTools = require('mobx-react-devtools').default; // eslint-disable-line global-require
|
2016-06-26 05:43:28 +00:00
|
|
|
}
|
2016-06-05 21:38:14 +00:00
|
|
|
|
2018-05-05 23:16:08 +00:00
|
|
|
const element = document.getElementById('root');
|
|
|
|
|
|
|
|
if (element) {
|
|
|
|
render(
|
|
|
|
<React.Fragment>
|
2019-03-13 04:35:35 +00:00
|
|
|
<ErrorBoundary>
|
|
|
|
<Provider {...stores}>
|
|
|
|
<Theme>
|
2018-06-10 02:10:30 +00:00
|
|
|
<Router>
|
2018-12-17 01:57:41 +00:00
|
|
|
<React.Fragment>
|
|
|
|
<ScrollToTop>
|
2019-01-19 08:23:39 +00:00
|
|
|
<Routes />
|
2018-12-17 01:57:41 +00:00
|
|
|
</ScrollToTop>
|
|
|
|
<Toasts />
|
|
|
|
</React.Fragment>
|
2018-06-10 02:10:30 +00:00
|
|
|
</Router>
|
2019-03-13 04:35:35 +00:00
|
|
|
</Theme>
|
|
|
|
</Provider>
|
|
|
|
</ErrorBoundary>
|
2018-05-05 23:16:08 +00:00
|
|
|
{DevTools && <DevTools position={{ bottom: 0, right: 0 }} />}
|
|
|
|
</React.Fragment>,
|
|
|
|
element
|
|
|
|
);
|
|
|
|
}
|
2018-02-11 07:23:50 +00:00
|
|
|
|
|
|
|
window.addEventListener('load', async () => {
|
|
|
|
// installation does not use Google Analytics, or tracking is blocked on client
|
|
|
|
// no point loading the rest of the analytics bundles
|
|
|
|
if (!process.env.GOOGLE_ANALYTICS_ID || !window.ga) return;
|
|
|
|
|
2018-02-11 07:54:54 +00:00
|
|
|
// https://github.com/googleanalytics/autotrack/issues/137#issuecomment-305890099
|
|
|
|
await import('autotrack/autotrack.js');
|
2018-02-11 07:23:50 +00:00
|
|
|
|
|
|
|
window.ga('require', 'outboundLinkTracker');
|
|
|
|
window.ga('require', 'urlChangeTracker');
|
2019-06-25 05:14:59 +00:00
|
|
|
window.ga('require', 'eventTracker', {
|
|
|
|
attributePrefix: 'data-',
|
|
|
|
});
|
2018-02-11 07:23:50 +00:00
|
|
|
});
|