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

<GoogleAnalytics> is not a valid SSR component #16

Open
mattpilott opened this issue Feb 6, 2022 · 2 comments
Open

<GoogleAnalytics> is not a valid SSR component #16

mattpilott opened this issue Feb 6, 2022 · 2 comments

Comments

@mattpilott
Copy link

Seeing this in sveltekit unsure what i need to adjust

<GoogleAnalytics> is not a valid SSR component. You may need to review your build config to ensure that dependencies are compiled, rather than imported as pre-compiled modules

@nstuyvesant
Copy link

Guessing this component doesn't expect to be rendered server-side where there is no browser.

I decided to add this to my /src/routes/__layout.svelte instead...

onMount(async() => {
  const googleAnalytics = document.createElement('script')
  googleAnalytics.src = 'https://www.googletagmanager.com/gtag/js?id=YOUR-TRACKER-ID'
  document.body.append(googleAnalytics)

 window.dataLayer = window.dataLayer || [];
  function gtag(){
    window.dataLayer.push(arguments)
  }
  gtag('js', new Date());
  gtag('config', 'YOUR-TRACKER-ID');
}

@antony
Copy link
Member

antony commented Apr 27, 2022

Interesting - it may need updating for SvelteKit.

It doesn't render server-side - it does exactly what you've done above there :)

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