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

Nextjs 13 App Dir example triggers twice on initial site load #45

Closed
IHIutch opened this issue Jun 1, 2023 · 6 comments
Closed

Nextjs 13 App Dir example triggers twice on initial site load #45

IHIutch opened this issue Jun 1, 2023 · 6 comments

Comments

@IHIutch
Copy link
Contributor

IHIutch commented Jun 1, 2023

Just followed the guide on installing fathom using the App directory with Nextjs 13 and I noticed the trackPageview() runs twice on the initial site load. Basically, any initial visit or page refresh.

image

next: 13.4.2

Here's a repro: https://codesandbox.io/p/sandbox/inspiring-raman-yxnjxp

@IHIutch
Copy link
Contributor Author

IHIutch commented Jun 1, 2023

Maybe related? vercel/next.js#49115

@derrickreimer
Copy link
Owner

Sorry for the trouble! This might be worth a shot. I suspect it's auto-firing a page view on load, and then firing another pageview in the other effect hook.

  function TrackPageView() {
    const pathname = usePathname()
    const searchParams = useSearchParams()

    useEffect(() => {
      load('MY_FATHOM_ID', {
        includedDomains: ['yourwebsite.com'],
+       auto: false
      })
    }, [])

Let me know if this solves it and we can update the docs!

@IHIutch
Copy link
Contributor Author

IHIutch commented Jun 1, 2023

Ah, yes that does appear to work. Thanks!

@IHIutch IHIutch closed this as completed Jun 1, 2023
@derrickreimer
Copy link
Owner

Cool! I'll update the readme.

@shhgholipour
Copy link

Sorry for the trouble! This might be worth a shot. I suspect it's auto-firing a page view on load, and then firing another pageview in the other effect hook.

  function TrackPageView() {
    const pathname = usePathname()
    const searchParams = useSearchParams()

    useEffect(() => {
      load('MY_FATHOM_ID', {
        includedDomains: ['yourwebsite.com'],
+       auto: false
      })
    }, [])

Let me know if this solves it and we can update the docs!

It didn't work for me

@derrickreimer
Copy link
Owner

@shhgholipour do you have a Next.js repo you can point to that reproduces the issue?

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

3 participants