Skip to content

Commit d6d7fe5

Browse files
stepan662JanCizmar
authored andcommitted
fix: ga4-tag
1 parent ea8d908 commit d6d7fe5

File tree

3 files changed

+12
-22
lines changed

3 files changed

+12
-22
lines changed

webapp/package-lock.json

Lines changed: 5 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

webapp/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
"date-fns": "2.29.2",
2424
"diff": "^5.0.0",
2525
"formik": "^2.2.9",
26-
"ga-gtag": "^1.1.7",
2726
"intl-messageformat": "^9.8.1",
2827
"notistack": "^2.0.4",
2928
"prism-react-renderer": "1.2.1",
@@ -36,6 +35,7 @@
3635
"react-dom": "^17.0.2",
3736
"react-draggable": "^4.4.3",
3837
"react-google-recaptcha-v3": "1.9.5",
38+
"react-gtm-module": "^2.0.11",
3939
"react-helmet": "^6.1.0",
4040
"react-list": "^0.8.16",
4141
"react-markdown": "^8.0.4",

webapp/src/component/Ga4Tag.tsx

Lines changed: 6 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,19 @@
11
import { useEffect } from 'react';
2-
import { useSelector } from 'react-redux';
3-
import { gtag, install } from 'ga-gtag';
2+
import TagManager from 'react-gtm-module';
43

54
import { useConfig } from 'tg.globalContext/helpers';
6-
import { AppState } from 'tg.store/index';
7-
8-
export const initGtag = (tagId: string) => {
9-
install(tagId);
10-
gtag('js', new Date());
11-
gtag('config', tagId);
12-
};
135

146
export const Ga4Tag = () => {
157
const config = useConfig();
168
const tag = config?.ga4Tag;
179

18-
const allowPrivate = useSelector(
19-
(state: AppState) => state.global.security.allowPrivate
20-
);
21-
2210
useEffect(() => {
23-
if (tag && allowPrivate) {
24-
initGtag(tag!);
11+
if (tag) {
12+
TagManager.initialize({
13+
gtmId: tag,
14+
});
2515
}
26-
}, [tag, allowPrivate]);
16+
}, [tag]);
2717

2818
return null;
2919
};

0 commit comments

Comments
 (0)