Closed tmlmt closed 1 year ago
Hi, @tmlmt 👋. Terribly sorry, the problem is that you can't use env variables in app.config
or appConfig
. It's a Nuxt thing.
For now, the only way is to provide the id/host as plain strings. But, I understand the need to keep something like that private, I'd work on that as soon as I get the chance.
@ijkml thanks for the quick answer :)
app.config
. Any reason why you have developed nuxt-umami like this and not as module, for which env variables can be used?Well, a few reasons I didn't use module
Currently, no. Everything should work fine if you provided the config like:
umami: {
host: "http...",
id: "id..."
}
If it doesn't, please prove a repro.
HOST: https://ml-umami.netlify.app
ID: ba4c9424-c4b7-48df-b66d-4213730673e5
Alright 😅. I think several modules use the same principle of using an API endpoint, with some minimum config effort in dev. Example: https://sidebase.io/nuxt-auth/configuration/nuxt-auth-handler. Great if you can keep on finding out the best solution :)
The website-id is absolutely not a secret and that's fine, however what is best practice is separating your dev and prod environment, in order not to pollute the prod stats with dev activity. Hence the need for using env variables / secrets.
Here's the most minimal repro you can think of. Used the Nuxt 3 starter from Stackblitz, installed nuxt-umami@next, and put your config in nuxt.config.ts
. Same error message. https://stackblitz.com/edit/nuxt-starter-aruxgr?file=package-lock.json
Thanks for raising this issue. Sorry I couldn't get back to you yesterday, but the issue should be fixed with v2.0.3
. If you've got a minute, please update and see if it is resolved.
Also, you can try it online: https://stackblitz.com/edit/nuxt-umami-next
Yep, best practices. I agree it's something I should work on. Meanwhile, you can use env variables in nuxt.config
, so it's totally possible to do something like:
// nuxt.config
const umHost = process.env.NUXT_UMAMI_HOST;
const umId = process.env.NUXT_UMAMI_ID;
//...then
appConfig: {
umami: { host: umHost, id: umId },
}
Hey @ijkml, thanks a lot! Indeed, process.env
can be used in nuxt.config.ts
, and I confirm things are now working with v2.0.3
:))
@ijkml Is it still possible to set the HOST and ID from environment variables in runtimeConfig as shown in #39? Specifically set via env var when running a built server in production, no SSR.
I'm running nuxt-umami v3.0.2.
I've set up my nuxt.config.ts
as shown below, but still get the following error in the browser console (I've verified that the env variables are set correctly):
[UMAMI]: Your API endpoint is missing or incorrectly configured. Check `host` & `customEndpoint` in module config.
[3qcYbTLZ.js:49:4735](http://localhost:3000/_nuxt/3qcYbTLZ.js)
Object { hostname: "localhost", language: "en-US", screen: "<redacted>", url: "<redacted>", referrer: "", title: "" }
[3qcYbTLZ.js:50:17](http://localhost:3000/_nuxt/3qcYbTLZ.js)
[UMAMI]: `id` is missing or incorrectly configured. Check module config.
[3qcYbTLZ.js:49:4735](http://localhost:3000/_nuxt/3qcYbTLZ.js)
Object { hostname: "localhost", language: "en-US", screen: "<redacted>", url: "<redacted>", referrer: "", title: "" }
// nuxt.config.ts
...
runtimeConfig: {
public: {
umamiHost: process.env.NUXT_PUBLIC_UMAMI_HOST,
umamiId: process.env.NUXT_PUBLIC_UMAMI_ID,
}
}
I have other public runtimeConfig that is set from environment variables that works without issue.
Hi @ijkml, thanks for facilitating the integration of Umami in Nuxt 3 :) I can't make the module to work, as I get the error:
I'm on Nuxt 3.3.1. Here's my nuxt.config.ts:
and my .env file
I've also tried moving the config to
app.config.ts
and directly putting my id as a string instead of the ENV variable... same problem.Could you help me debug this?
Could you also provide like a fake ID and HOST in order to prepare some repro for you if needed?