Skip to content

Commit

Permalink
Update to Google Analytics 4 (#342)
Browse files Browse the repository at this point in the history
  • Loading branch information
seanprashad authored Dec 24, 2024
1 parent 4d5376d commit 68313f9
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 14 deletions.
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.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"prop-types": "^15.8.1",
"react": "^16.14.0",
"react-dom": "^16.14.0",
"react-ga": "^2.7.0",
"react-ga4": "^2.1.0",
"react-icons": "^3.11.0",
"react-markdown": "^4.3.1",
"react-minimal-pie-chart": "^8.4.0",
Expand Down
5 changes: 2 additions & 3 deletions src/components/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,11 @@ import './styles.scss';
import Navigation from './Navigation';
import Tabs from './Tabs';

import { initGA, PageView } from './Shared/Tracking';
import { initGA } from './Shared/Tracking';

class App extends React.Component {
componentDidMount() {
initGA('G-GKMJ4KP806', { debug: false });
PageView();
initGA('G-J7FBQPGZTW');
}

render() {
Expand Down
21 changes: 11 additions & 10 deletions src/components/Shared/Tracking/index.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,20 @@
import ReactGA from 'react-ga';
import ReactGA from 'react-ga4';

const initGA = (trackingID, options) => {
ReactGA.initialize(trackingID, { ...options });
};

const PageView = () => {
ReactGA.pageview(window.location.pathname + window.location.search);
ReactGA.initialize([
{
trackingId: trackingID,
gaOptions: { ...options },
},
]);
};

const Event = (category, action, label) => {
ReactGA.event({
category,
action,
label,
category: category,
action: action,
label: label,
});
};

export { initGA, PageView, Event };
export { initGA, Event };

0 comments on commit 68313f9

Please sign in to comment.