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

Events are sent to the wrong domain #124

Open stefanofusai opened 5 months ago

stefanofusai commented 5 months ago

First of all, thank you for your library! Unfortunately, I can't get it to work :(

I have my site hosted at placeholder.com, and my Plausible instance running (selfhosted) at analytics.placeholder.com Unfortunately, the library tries to access the script.js file at placeholder.com, resulting in a 404, and I can't seem to change this.

Here is my next.config.js:

if (!process.env.PLAUSIBLE_DOMAIN) {
    throw new Error("Please set the PLAUSIBLE_DOMAIN environment variable");
}

module.exports = withPlausibleProxy({
    customDomain: process.env.PLAUSIBLE_DOMAIN, // PLAUSIBLE_DOMAIN = https://analytics.placeholder.com
})(nextConfig);

And here is my layout.tsx:

if (!process.env.DOMAIN) {
    throw new Error("Please set the DOMAIN environment variable");
}

return (
    <html lang={lang} suppressHydrationWarning>
        <head>
            <PlausibleProvider domain={process.env.DOMAIN} /> {/* DOMAIN = https://placeholder.com */}
            ...
        </head>
        <body
            ...
        </body>
    </html>
);

What am I doing wrong? Thank you!

nirav24 commented 4 months ago

I was able to make it work with my self-hosted plausible instance

Can you try

<PlausibleProvider domain={process.env.DOMAIN} 
customDomain="https://analytics.placeholder.com" selfHosted={true} />
stefanofusai commented 4 months ago

I was able to make it work with my self-hosted plausible instance

Can you try

<PlausibleProvider domain={process.env.DOMAIN} 
customDomain="https://analytics.placeholder.com" selfHosted={true} />

Thank you for your help, unfortunately this still doesn't work. What does your process.env.DOMAIN look like?

nirav24 commented 4 months ago

I have it hardcoded to my website's DNS which also matches with plausible's website dns

EDIT: I have domain without https://

stefanofusai commented 4 months ago

I have it hardcoded to my website's DNS which also matches with plausible's website dns

EDIT: I have domain without https://

Thank you for your help. It still seems like requests are not being sent out. I'm really not sure what I'm doing wrong

next.config.js

module.exports = withPlausibleProxy({
    customDomain: process.env.PLAUSIBLE_CUSTOM_DOMAIN, // https://analytics.example.com
})(nextConfig);

layout.tsx

<head>
    <PlausibleProvider
        domain={process.env.PLAUSIBLE_DOMAIN} // example.com
        customDomain={process.env.PLAUSIBLE_CUSTOM_DOMAIN} // https://analytics.example.com
        selfHosted={true}
    />
lorenzpfei commented 1 month ago

are u sure your env variables are properly exposed/set? I did exactly the same but with hardcoded variables and it worked.