8000 Add Google Analytics · MRGRD56/mrgrd56.github.io@4f4f298 · GitHub
[go: up one dir, main page]

Skip to content

Commit 4f4f298

Browse files
author
k.golikov
committed
Add Google Analytics
1 parent 521fbac commit 4f4f298

File tree

5 files changed

+26
-3
lines changed

5 files changed

+26
-3
lines changed

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
"react-color": "^2.19.3",
4141
"react-css-theme-switcher": "^0.3.0",
4242
"react-dom": "^18.0.0",
43+
"react-ga": "^3.3.1",
4344
"react-highlight-words": "^0.18.0",
4445
"react-konva": "^18.0.0-0",
4546
"react-redux": "^7.2.6",

src/components/ExternalLink.tsx

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,15 @@
11
import React, { FunctionComponent, HTMLProps } from 'react';
2+
import ReactGA from 'react-ga';
23

3-
const ExternalLink: FunctionComponent<HTMLProps<HTMLAnchorElement>> = ({ target, rel, ...props }) => (
4-
<a target={target ?? '_blank'} rel={rel ?? 'noopener noreferrer'} {...props} />
4+
const ExternalLink: FunctionComponent<HTMLProps<HTMLAnchorElement>> = ({ target, rel, href, ...props }) => (
5+
// @ts-ignore
6+
<ReactGA.OutboundLink
7+
eventLabel={href ?? 'unknown-external-link'}
8+
target={target ?? '_blank'}
9+
rel={rel ?? 'noopener noreferrer'}
10+
to={href as string}
11+
{...props}
12+
/>
513
);
614

715
export default React.memo(ExternalLink);

src/index.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@ import './index.scss';
77
import App from './App';
88
import ReactDOM from 'react-dom';
99
import moment from 'moment';
10+
import ReactGA from 'react-ga';
11+
12+
ReactGA.initialize('G-LJ339DXZVF');
1013

1114
moment.locale(navigator.language);
1215

src/layouts/appLayout/AppLayout.tsx

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import React, { FunctionComponent } from 'react';
1+
import React, { FunctionComponent, useEffect } from 'react';
22
import { Layout } from 'antd';
33
import { Content } from 'antd/lib/layout/layout';
44
import styles from './AppLayout.module.scss';
@@ -8,13 +8,19 @@ import AppFooter from './components/appFooter/AppFooter';
88
import useAppLocation from '../../hooks/useAppLocation';
99
import useAppFooter from '../../hooks/useAppFooter';
1010
import { HEADER_HEIGHT } from '../../constants/layout';
11+
import ReactGA from 'react-ga';
1112

1213
const AppLayout: FunctionComponent = ({ children }) => {
1314
const appRoute = useAppLocation();
1415
const { isFooterShown, isFooterAnywayShown, footerHeight } = useAppFooter();
1516

1617
const isLayoutHidden = appRoute?.isLayoutHidden === true;
1718

19+
useEffect(() => {
20+
const path = window.location.pathname + window.location.search + window.location.hash;
21+
ReactGA.pageview(path, undefined, appRoute?.title || document.title);
22+
}, [appRoute]);
23+
1824
if (isLayoutHidden) {
1925
return <>{children}</>;
2026
}

yarn.lock

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11177,6 +11177,11 @@ react-error-overlay@^6.0.10:
1117711177
resolved "https://registry.yarnpkg.com/react-error-overlay/-/react-error-overlay-6.0.10.tgz#0fe26db4fa85d9dbb8624729580e90e7159a59a6"
1117811178
integrity sha512-mKR90fX7Pm5seCOfz8q9F+66VCc1PGsWSBxKbITjfKVQHMNF2zudxHnMdJiB1fRCb+XsbQV9sO9DCkgsMQgBIA==
1117911179

11180+
react-ga@^3.3.1:
11181+
version "3.3.1"
11182+
resolved "https://registry.yarnpkg.com/react-ga/-/react-ga-3.3.1.tgz#d8e1f4e05ec55ed6ff944dcb14b99011dfaf9504"
11183+
integrity sha512-4Vc0W5EvXAXUN/wWyxvsAKDLLgtJ3oLmhYYssx+YzphJpejtOst6cbIHCIyF50Fdxuf5DDKqRYny24yJ2y7GFQ==
11184+
1118011185
react-highlight-words@^0.18.0:
1118111186
version "0.18.0"
1118211187
resolved "https://registry.yarnpkg.com/react-highlight-words/-/react-highlight-words-0.18.0.tgz#ff3b3ef7cb497fa2e8fa4d54c1a1a98ac6390d0e"

0 commit comments

Comments
 (0)
0