Skip to content

Commit

Permalink
Upgrade react-ga4 in order to also support Google Analytics GA4 @avoinea
Browse files Browse the repository at this point in the history
  • Loading branch information
avoinea committed Oct 24, 2022
1 parent 75e21b1 commit b0bb26d
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 7 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@

### Feature

- Upgrade react-ga4 in order to also support Google Analytics GA4 @avoinea refs #9

### Bugfix

### Internal
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@
"dependencies": {
"@datapunt/matomo-tracker-js": "0.5.1",
"@plone/scripts": "*",
"react-ga": "3.3.0"
"react-ga4": "^1.4.1"
},
"devDependencies": {
"release-it": "^15.4.1"
Expand Down
11 changes: 6 additions & 5 deletions src/components/Banner/Google.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,21 @@ const Google = ({ reactGa }) => {
const confirmTracking = !!Number(cookies.confirm_tracking);

if (__CLIENT__) {
reactGa.initialize(
config.settings.DSGVOBanner.trackingId ||
config.settings.DSGVOBanner.tracker.id,
reactGa.default.initialize([
{
trackingId:
config.settings.DSGVOBanner.trackingId ||
config.settings.DSGVOBanner.tracker.id,
gaOptions: {
anonymizeIp: true,
},
},
);
]);
}

useEffect(() => {
if (confirmTracking) {
reactGa.pageview(location.pathname);
reactGa.default.send({ hitType: 'pageview', page: location.pathname });
}
}, [location, confirmTracking, reactGa]);

Expand Down
2 changes: 1 addition & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export default (config) => {
privacy_url: '/privacy',
...(config.settings.DSGVOBanner || {}),
};
config.settings.loadables['reactGa'] = loadable.lib(() => import('react-ga'));
config.settings.loadables['reactGa'] = loadable.lib(() => import('react-ga4'));
config.settings.loadables['matomoTracker'] = loadable.lib(() =>
import('@datapunt/matomo-tracker-js'),
);
Expand Down

0 comments on commit b0bb26d

Please sign in to comment.