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

Only create Matomo Tracker instance if confirm_tracking cookie has be… #36

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
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
1 change: 1 addition & 0 deletions news/35.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Only create Matomo Tracker instance if confirm_tracking cookie has been set. @fredvd
17 changes: 9 additions & 8 deletions src/components/Banner/Matomo.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,16 @@ const Matomo = ({ matomoTracker }) => {
const confirmTracking = !!Number(cookies.confirm_tracking);
let tracker;

if (__CLIENT__) {
tracker = new matomoTracker.default({
urlBase: config.settings.DSGVOBanner.tracker.urlBase,
siteId: config.settings.DSGVOBanner.tracker.id,
});
}

useEffect(() => {
if (confirmTracking) {
if (confirmTracking && __CLIENT__ ) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@fredvd useEffect hooks only run on the client (see the implementation of the useClient hook! https://github.com/plone/volto/blob/0987c96dbc4597b8ab36009af4e4bfa125f123ec/packages/volto/src/hooks/client/useClient.js#L5) so this is redundant.

Suggested change
if (confirmTracking && __CLIENT__ ) {
if (confirmTracking) {

tracker = new matomoTracker.default({
urlBase: config.settings.DSGVOBanner.tracker.urlBase,
siteId: config.settings.DSGVOBanner.tracker.id,
configurations: { // optional, default value: {}
disableCookies: false,
setSecureCookie: true,
},
});
tracker.trackPageView();
}
}, [tracker, confirmTracking]);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The hook should not have tracker as a dependency. That means it will run again any time tracker changes, which means it will run after every render since the hook itself sets tracker.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(This is also why the linter is complaining.)

Expand Down
Loading