Skip to content

Previous page title is being used as action name #132

Description

@linusjaderlund

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]);
};

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions