Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to configure the module using enviroment variables #11

Open
madskronborg opened this issue Jul 17, 2023 · 1 comment
Open

How to configure the module using enviroment variables #11

madskronborg opened this issue Jul 17, 2023 · 1 comment

Comments

@madskronborg
Copy link

Hey there!

Thank you for your work on this module! 👏

I have been trying to configure the module with environment variables by setting the id using NUXT_PUBLIC_GTM_ID, but it does not work - do you have an example of how to configure the module through environment variables?

If it is not possible to do at this moment, would it be something you are interested in supporting in a future release?

@juyaki
Copy link

juyaki commented Aug 16, 2023

@madskronborg A bit late, but if it can help I was able to do it that way:

in nuxt.config.ts

  gtm: {
    id: process.env.NUXT_PUBLIC_GOOGLE_TAG_MANAGER_ID as string
  },

This is because in nuxt.config.ts vite didn't put the env variable in runtimeconfig yet, so you have to do it the old way with process.env.XXX

When you launch your project, don't forget to specify the path of your env file. Eg with two different env files:

  "scripts": {
    "generate-dev": "nuxt generate --dotenv .env.dev",
    "generate-prod": "nuxt generate --dotenv .env.prod",
    "dev": "nuxt dev --dotenv .env.dev",
    "prod": "nuxt dev --dotenv .env.prod",
  },

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants