-
Notifications
You must be signed in to change notification settings - Fork 23
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
With NextJs 13 error setTrackerUrl (setSiteId) is registered more than once #104
Comments
I followed https://www.linkedin.com/pulse/preventing-useeffect-from-running-twice-strict-mode-useref-tingre/ and got rid of the warning with the code below. It would be nicer to have an unInit function that can be called to cleanup the integration in the hooks return statement or something. Maybe init should be useInit and handle this kind of check internally. const matomoInitialized = useRef(false)
useEffect(() => {
if (MATOMO_URL && MATOMO_SITE_ID && matomoInitialized.current === false) {
init({ url: MATOMO_URL, siteId: MATOMO_SITE_ID })
}
return () => {
matomoInitialized.current = true
}
}, []) |
Thank you! This solved the console error and the issue I had with it registering every page view twice! |
@tordans shouldn't the library just handle mutliple |
In case you were wondering, like me, this snippet will let Matomo track the initial page load, but not the subsequent SPA page router changes. It's not enough and the library does not handle this natively for Next 13. See #99 for WIP solution. |
The following error is displayed in the developer console:
The method setTrackerUrl (setSiteId) is registered more than once in "_paq" variable. Only the last call has an effect. Please have a look at the multiple Matomo trackers documentation.
Next.Js version 13.4.2
The text was updated successfully, but these errors were encountered: