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

Conversation

fredvd
Copy link

@fredvd fredvd commented Dec 9, 2024

…en set (#35)

@fredvd fredvd marked this pull request as draft December 9, 2024 09:10
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) {

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.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants