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

Previous page title is being used as action name #132

Open
linusjaderlund opened this issue Oct 10, 2024 · 0 comments
Open

Previous page title is being used as action name #132

linusjaderlund opened this issue Oct 10, 2024 · 0 comments

Comments

@linusjaderlund
Copy link

Hello 😄

I'm having an issue when tracking data is sent on route change.
Problem is that the action name is being set to the previous pages title. So if I go from "A" to "B" and the data is sent for route "B" I get action name "A".
Everything else in the data seems to be correct.

I've rewritten the application to set the page title as soon as possible, now it happens as the page is rendered on the server.
But the more I optimize the application the more consequential this issue gets.

First: is this an issue or by design?
Second: if not by design, how do i solve it?

Initialization happens in _app.tsx withing a custom hook that looks like this:

export const useHandleTracking = () => {
  const cookieService = new CookieService();
  const isStatisticsCookieAccepted = cookieService.isCookieAccepted(CookieType.STATISTICS);
  const { matomoUrl, matomoSiteId }: ApplicationConfig = getConfig().publicRuntimeConfig.application;

  type WindowPaq = Window & typeof globalThis & { _paq: Array<any> };

  useEffect(() => {
    const matomoBrowserObject = (window as WindowPaq)._paq;
    const isInitialized = Array.isArray(matomoBrowserObject) && matomoBrowserObject.length > 0;

    if (isStatisticsCookieAccepted && !isInitialized) {
      init({ url: matomoUrl, siteId: matomoSiteId });
    }
  }, [isStatisticsCookieAccepted, matomoSiteId, matomoUrl]);
};
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

No branches or pull requests

1 participant