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

Plausible script not included on website #80

Closed JanRuettinger closed 12 months ago

JanRuettinger commented 1 year ago

Hi,

the script.js file is not loaded for me with the following setup.

next.config.js

/** @type {import('next').NextConfig} */

const withTM = require('next-transpile-modules')(['echarts', 'zrender']);

const nextConfig = {
    reactStrictMode: true,
    eslint: {
        dirs: ['src'],
    },
};

module.exports = withTM(nextConfig);

_app.ts

import type { AppProps } from 'next/app';
import PlausibleProvider from 'next-plausible';

function MyApp({ Component, pageProps }: AppProps) {
    return (
        <PlausibleProvider domain="xxx" trackLocalhost={true}>
            <Component {...pageProps} />
        </PlausibleProvider>
    );
}

export default MyApp;

When I include the script tag manually in the header plausible works fine.

Any ideas what might cause this?

4lejandrito commented 1 year ago

How are you running the app? If you're trying locally with next dev, you need to manually add the enabled={true} prop to PlausibleProvider. By default it is only enabled in production mode.

JanRuettinger commented 1 year ago

That was it thank you! Now the proxy feature doesn't work.

const withTM = require('next-transpile-modules')(['echarts', 'zrender']);
const { withPlausibleProxy } = require('next-plausible');

const nextConfig = {
    reactStrictMode: true,
    eslint: {
        dirs: ['src'],
    },
};

module.exports = withPlausibleProxy(withTM(nextConfig));

That's my updated next.config.js

Again the script is not loaded when deployed on Vercel but works perfectly fine on localhost (also the proxy feature).

4lejandrito commented 1 year ago

You're using withPlausibleProxy wrong... it receives its config as first parameter and then returns a function in which you can pass your nextjs config. So you should use it like this:

module.exports = withPlausibleProxy()(withTM(nextConfig));

Let me know if that works.

4lejandrito commented 12 months ago

Seems fixed by the latest answer.