2019-12-08 00:32:00 +05:30
|
|
|
import 'app/polyfills';
|
2019-11-09 22:56:46 +05:30
|
|
|
import 'react-hot-loader';
|
2016-01-03 01:54:07 +05:30
|
|
|
|
|
|
|
import React from 'react';
|
|
|
|
import ReactDOM from 'react-dom';
|
2019-12-08 00:32:00 +05:30
|
|
|
import { factory as userFactory } from 'app/components/user/factory';
|
|
|
|
import authFlow from 'app/services/authFlow';
|
|
|
|
import storeFactory from 'app/storeFactory';
|
|
|
|
import bsodFactory from 'app/components/ui/bsod/factory';
|
2020-01-18 02:07:52 +05:30
|
|
|
import * as loader from 'app/services/loader';
|
2019-12-08 00:32:00 +05:30
|
|
|
import logger from 'app/services/logger';
|
|
|
|
import font from 'app/services/font';
|
|
|
|
import history, { browserHistory } from 'app/services/history';
|
|
|
|
import i18n from 'app/services/i18n';
|
|
|
|
import { loadScript, debounce } from 'app/functions';
|
2020-01-18 02:07:52 +05:30
|
|
|
import { Location as HistoryLocation } from 'history';
|
2019-11-09 22:56:46 +05:30
|
|
|
|
2019-12-26 17:48:58 +05:30
|
|
|
import App from './shell/App';
|
2017-01-29 21:06:21 +05:30
|
|
|
|
2019-12-07 16:58:52 +05:30
|
|
|
const win: { [key: string]: any } = window as any;
|
|
|
|
|
2017-01-29 21:06:21 +05:30
|
|
|
history.init();
|
2016-12-07 02:36:45 +05:30
|
|
|
|
|
|
|
logger.init({
|
2020-01-14 17:51:38 +05:30
|
|
|
sentryDSN: (window as any).SENTRY_DSN as string,
|
2016-12-07 02:36:45 +05:30
|
|
|
});
|
2016-01-03 01:54:07 +05:30
|
|
|
|
2016-06-18 20:30:45 +05:30
|
|
|
const store = storeFactory();
|
2016-01-03 01:54:07 +05:30
|
|
|
|
2019-12-26 17:48:58 +05:30
|
|
|
bsodFactory({
|
|
|
|
store,
|
|
|
|
history: browserHistory,
|
|
|
|
stopLoading: () => loader.hide(),
|
|
|
|
});
|
2017-05-26 00:41:57 +05:30
|
|
|
authFlow.setStore(store);
|
2016-07-30 00:59:27 +05:30
|
|
|
|
2016-10-11 09:37:09 +05:30
|
|
|
Promise.all([
|
2019-11-27 14:33:32 +05:30
|
|
|
userFactory(store),
|
|
|
|
font.load(['Roboto', 'Roboto Condensed']),
|
|
|
|
i18n.ensureIntl(), // ensure, that intl is polyfilled before any rendering
|
2019-11-09 22:56:46 +05:30
|
|
|
]).then(() => {
|
2019-11-27 14:33:32 +05:30
|
|
|
ReactDOM.render(
|
2019-12-09 12:37:07 +05:30
|
|
|
<App store={store} history={browserHistory} />,
|
2019-11-27 14:33:32 +05:30
|
|
|
document.getElementById('app'),
|
|
|
|
);
|
2017-01-03 11:26:38 +05:30
|
|
|
|
2019-11-27 14:33:32 +05:30
|
|
|
initAnalytics();
|
2019-11-09 22:56:46 +05:30
|
|
|
});
|
2016-05-09 00:58:51 +05:30
|
|
|
|
2017-01-03 11:26:38 +05:30
|
|
|
const trackPageView = debounce(_trackPageView);
|
|
|
|
function initAnalytics() {
|
2019-12-07 16:58:52 +05:30
|
|
|
if (!win.ga) {
|
|
|
|
const ga: {
|
|
|
|
[key: string]: any;
|
|
|
|
(...args: any[]): void;
|
2020-05-20 22:05:52 +05:30
|
|
|
} = function (...args) {
|
2019-11-27 14:33:32 +05:30
|
|
|
// eslint-disable-next-line id-length
|
|
|
|
(ga.q = ga.q || []).push(args);
|
|
|
|
};
|
2019-12-07 16:58:52 +05:30
|
|
|
win.ga = ga;
|
2019-11-27 14:33:32 +05:30
|
|
|
ga.l = Date.now(); // eslint-disable-line
|
2017-01-03 11:26:38 +05:30
|
|
|
|
2019-12-07 16:58:52 +05:30
|
|
|
if (win.GA_ID) {
|
2019-11-27 14:33:32 +05:30
|
|
|
// when GA is not available, we will continue to push into array
|
|
|
|
// for debug purposes
|
|
|
|
// Catch to prevent "unhandled rejection" error
|
|
|
|
loadScript(
|
|
|
|
'https://www.google-analytics.com/analytics.js',
|
|
|
|
).catch(() => {});
|
|
|
|
}
|
2016-11-20 17:31:57 +05:30
|
|
|
|
2019-12-07 16:58:52 +05:30
|
|
|
ga('create', win.GA_ID, 'auto');
|
2019-11-27 14:33:32 +05:30
|
|
|
trackPageView(location);
|
2016-11-20 17:31:57 +05:30
|
|
|
|
2019-11-27 14:33:32 +05:30
|
|
|
browserHistory.listen(trackPageView);
|
|
|
|
}
|
2017-01-03 11:26:38 +05:30
|
|
|
}
|
|
|
|
|
2020-01-18 02:07:52 +05:30
|
|
|
function _trackPageView(location: HistoryLocation | Location): void {
|
2019-12-07 16:58:52 +05:30
|
|
|
const { ga } = win;
|
2016-11-20 17:31:57 +05:30
|
|
|
|
2019-11-27 14:33:32 +05:30
|
|
|
ga('set', 'page', location.pathname + location.search);
|
|
|
|
ga('send', 'pageview');
|
2016-11-20 17:31:57 +05:30
|
|
|
}
|