4lejandrito / next-plausible

Simple integration for https://nextjs.org and https://plausible.io analytics
https://next-plausible.vercel.app
MIT License
603 stars 33 forks source link

Script not added to Next.js App - Issue with custom script? #96

Closed AlessandroVol23 closed 1 year ago

AlessandroVol23 commented 1 year ago

Hi,

thanks for the lib 😊

I'm using it for various projects but it fails on one project where I also set a custom Script tag:

    <PlausibleProvider domain="serverlessq.com" enabled={true}>
      <Layout>
        <Script
          id="crisp-widget"
          strategy="afterInteractive"
          dangerouslySetInnerHTML={{
           script
          }}
        />
        <Component {...pageProps} />
      </Layout>
    </PlausibleProvider>

If I set the enabled={true} I see it on localhost. But once I deploy it I can't see it. Is the script tag maybe overriding it? Any idea what could cause this?

Thanks 😊

4lejandrito commented 1 year ago

Hi @AlessandroVol23! I don't think your script tag should affect next-plausible at all. If you remove it, does it work?

AlessandroVol23 commented 1 year ago

I removed the script tag but it is still not visible. The script tag with the tag data-domain is missing -> https://serverlessq.com

image

Any idea what to change? I haven't deployed it with enabled={true} but so far that works on all other pages which are also simply static next paegs

AlessandroVol23 commented 1 year ago

I've added it manually now with <Script tags so that works for me

4lejandrito commented 1 year ago

Hey @AlessandroVol23 I have no clue why it failed. I am sad you had to resort to a raw Script tag. If you ever try again with next-plausible please come back to this issue and I'll try to find out the root cause.

For now I'll close this.

marcosnc08 commented 1 year ago

In case anyone has this issue. I was having the same problem and I was missing a Head tag on _document.tsx

import { Head } from "next/document";

After adding it it started working

RainyCodeWizard commented 9 months ago

I removed the script tag but it is still not visible. The script tag with the tag data-domain is missing -> https://serverlessq.com image

Any idea what to change? I haven't deployed it with enabled={true} but so far that works on all other pages which are also simply static next paegs

If anyone still has this issue, i had to add scriptProps={{ strategy: 'beforeInteractive' }} to to solve it

[I am using NextJS 14 pages router]