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

Duplicate Page View Tracking in SPA #116

Open
rtrindade08 opened this issue Dec 7, 2023 · 1 comment
Open

Duplicate Page View Tracking in SPA #116

rtrindade08 opened this issue Dec 7, 2023 · 1 comment

Comments

@rtrindade08
Copy link

Hello,

I am currently working on a Single Page Application (SPA) and facing an issue with tracking query strings during page navigation. My goal is to accurately track page views, including the full URL with query strings, whenever the user navigates from one page to another.

I have implemented the following code in my _app file to integrate Matomo tracking:

I've added this in my _app :

const appConfig = useAppConfig()
  useEffect(() => {
    if (appConfig?.matomoUrl && appConfig?.matomoSiteId) {
      init({
        url: appConfig?.matomoUrl,
        siteId: appConfig?.matomoSiteId,
        onRouteChangeComplete: (path) => {
          const fullUrl = window.location.origin + path
          window._paq.push(['setCustomUrl', fullUrl])
          window._paq.push(['trackPageView'])
        },
      })
    }
  }, [appConfig?.matomoUrl, appConfig?.matomoSiteId])

This setup successfully tracks the full URL, including query strings, as intended. However, I have encountered an issue where each page view is being tracked twice.

I am reaching out to see what adjustments in my setup I need to do to ensure that page views are only tracked once per navigation event.

Thank you.

@revolunet
Copy link
Member

Hi,

Reading the source, looks like it's not possible at the moment to disable the builtin trackPageView if you do it yourself.

We could add a trackQuerystring (default to false) option to the init method that adds the querystring to the builtin setCustomUrl so you wont even have to override onRouteChangeComplete.

What do you think ? Would you like to land a PR for this ?

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

2 participants