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

How can I use this with next.config.mjs as generated by t3 #89

Closed sfabriece closed 1 year ago

sfabriece commented 1 year ago

When creating a nextjs app with t3, it generates a next.config.mjs. I'm struggling to figure out how configure the proxy.

4lejandrito commented 1 year ago

Hi @sfabriece,

Have you followed these steps?

What have you tried? Why does it not work?

nhamilton1 commented 1 year ago

I was able to get it to work with t3 version 7.0.1.

Here is my config:

!process.env.SKIP_ENV_VALIDATION && (await import("./src/env/server.mjs"));
import { withPlausibleProxy } from "next-plausible";

/** @type {import("next").NextConfig} */
const config = withPlausibleProxy()({
  reactStrictMode: true,
  swcMinify: true,
  i18n: {
    locales: ["en"],
    defaultLocale: "en",
  },
  headers: async () => {
    return [
      {
        source: "/(.*)",
        headers: securityHeaders,
      },
    ];
  },
});

export default config;

As for my PlausibleProvider I have it setup like this:


<PlausibleProvider domain={domain} enabled={true}>
      {getLayout(<Component {...pageProps} />)}
</PlausibleProvider>

I was not able to figure out how to have the plausible script display while I was on localhost, even though I had the trackLocalhost set to true. However, as soon as I deployed it, I was able to see the script.

sfabriece commented 1 year ago

The steps outlined above work for my use case.