Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

perf(app): 11082 - analytics runing after app supposed to be loaded #81

Merged
merged 1 commit into from
Aug 2, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 3 additions & 20 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -29,29 +29,12 @@
<% if (VITE_SPACING_JS===true) { %>
<script src="https://unpkg.com/spacingjs" async></script>
<% } %>
<% if (mode==='production') { %>
<!-- Google Tag Manager -->
<script>(function (w, d, s, l, i) {
w[l] = w[l] || []; w[l].push({
'gtm.start':
new Date().getTime(), event: 'gtm.js'
}); var f = d.getElementsByTagName(s)[0],
j = d.createElement(s), dl = l != 'dataLayer' ? '&l=' + l : ''; j.async = true; j.src =
'https://www.googletagmanager.com/gtm.js?id=' + i + dl; f.parentNode.insertBefore(j, f);
})(window, document, 'script', 'dataLayer', 'GTM-5LD2Z3D');</script>
<!-- End Google Tag Manager -->
<% } %>
</head>

<body>
<% if (mode==='production' ) { %>
<!-- Google Tag Manager (noscript) -->
<noscript><iframe src="https://www.googletagmanager.com/ns.html?id=GTM-5LD2Z3D" height="0" width="0"
style="display:none;visibility:hidden"></iframe></noscript>
<!-- End Google Tag Manager (noscript) -->
<% } %>
<div id="root"></div>
<script type="module" src="/src/index.ts"></script>
<div id="root"></div>
<script type="module" src="/src/index.ts"></script>

</body>

</html>
11 changes: 11 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

37 changes: 19 additions & 18 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@
"react-dnd": "^15.1.1",
"react-dnd-html5-backend": "^15.1.2",
"react-dom": "^17.0.2",
"react-gtm-module": "^2.0.11",
"react-i18next": "^11.11.4",
"react-lazily": "^0.9.0",
"react-markdown": "^7.1.0",
Expand All @@ -118,42 +119,42 @@
"devDependencies": {
"@testing-library/react": "^12.0.0",
"@testing-library/react-hooks": "^8.0.0",
"@types/sinon": "^10.0.6",
"@typescript-eslint/eslint-plugin": "^5.27.1",
"@typescript-eslint/parser": "^5.27.1",
"@types/sinon": "^10.0.6",
"@vitejs/plugin-react": "^1.3.2",
"@uiw/react-github-corners": "1.5.14",
"@vitejs/plugin-react": "^1.3.2",
"autoprefixer": "^10.4.0",
"axios-mock-adapter": "^1.20.0",
"cpr": "^3.0.1",
"dependency-cruiser": "^11.8.0",
"eslint": "^7.32.0",
"eslint-import-resolver-typescript": "^2.7.1",
"eslint-plugin-import": "^2.26.0",
"eslint-plugin-react": "^7.28.0",
"eslint-plugin-react-hooks": "^4.2.0",
"happy-dom": "^5.2.0",
"husky": "^8.0.1",
"lint-staged": "^13.0.0",
"npm-run-all": "^4.1.5",
"open-cli": "^7.0.0",
"patch-package": "^6.4.7",
"postcss-custom-media": "^8.0.0",
"postcss-loader": "^6.1.1",
"postcss-nested": "^5.0.6",
"postcss-normalize": "8.0.1",
"prettier": "^2.3.2",
"react-cosmos": "5.7.2",
"react-test-renderer": "^17.0.0",
"rollup-plugin-visualizer": "^5.5.2",
"sinon": "^12.0.1",
"stylelint": "^14.1.0",
"stylelint-config-recommended": "^6.0.0",
"stylelint-config-standard": "^24.0.0",
"vitest": "^0.14.1",
"ts-json-schema-generator": "^1.0.0",
"axios-mock-adapter": "^1.20.0",
"dependency-cruiser": "^11.8.0",
"eslint": "^7.32.0",
"eslint-import-resolver-typescript": "^2.7.1",
"eslint-plugin-import": "^2.26.0",
"eslint-plugin-react": "^7.28.0",
"eslint-plugin-react-hooks": "^4.2.0",
"happy-dom": "^5.2.0",
"typescript": "4.3.5",
"vite": "^2.6.14",
"vite-plugin-html": "^2.1.1",
"rollup-plugin-visualizer": "^5.5.2",
"typescript": "4.3.5",
"patch-package": "^6.4.7",
"postcss-custom-media": "^8.0.0",
"postcss-loader": "^6.1.1",
"postcss-nested": "^5.0.6",
"postcss-normalize": "8.0.1"
"vitest": "^0.14.1"
}
}
13 changes: 13 additions & 0 deletions src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import ReactDOM from 'react-dom';
import { reatomContext } from '@reatom/react';
import { store } from '~core/store/store';
import { AuthWrapper } from '~core/auth';
import { runGoogleTagManager } from '~utils/metrics/tagManager';
import { RoutedApp } from './Routes';

ReactDOM.render(
Expand All @@ -12,3 +13,15 @@ ReactDOM.render(
</reatomContext.Provider>,
document.getElementById('root'),
);

// delayed run of statistics
// 4 seconds is the time we'd expect app to be ready
// TODO put this to when app is loaded when task #11042 is done
if (import.meta.env?.MODE !== 'development')
try {
setTimeout(() => {
runGoogleTagManager();
}, 4000);
} catch (error) {
console.warn('error when loading statistics', error);
}
5 changes: 5 additions & 0 deletions src/utils/metrics/tagManager.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import TagManager from 'react-gtm-module';

export function runGoogleTagManager() {
TagManager.initialize({ gtmId: 'GTM-5LD2Z3D' });
}