W
W
WAYNEDEV2022-02-09 13:44:22
Web development
WAYNEDEV, 2022-02-09 13:44:22

How to disable yandex metric in nuxt if env != prod?

Hello!
I use the @nuxtjs/yandex-metrika plugin, but I can’t find something how to disable the metric depending on the environment
In general, you need to disable it if APP_ENVIRONMEN != prod

Now I’m just trying not to pass the metric id, but this is wrong

// в nuxt.config
modules: [
        [
            '@nuxtjs/yandex-metrika',
            {
                id: (process.env.APP_ENVIRONMENT as string) === 'prod' ? '8******' : '',
                webvisor: true,
                clickmap: true,
                trackLinks: true,
                accurateTrackBounce: true,
            }
        ]
    ],


Tell me, please, what to do. I can't find any info about this anywhere I
would be very grateful!

Answer the question

In order to leave comments, you need to log in

4 answer(s)
M
Maxim E, 2016-02-04
@creativeworm

via .htaccess
RewriteRule (.*) http://mydomen.com/$1 [R=301,L]

A
Anton, 2016-02-04
@Lampochkagori

Check with your DNS provider to see if you can set up a 301 redirect.

D
Dmitry, 2016-02-04
@mytmid

If hosting is ordered:
1. Go to the control panel
2. Web server
3. Sites
4. Select the desired site
5. Site management -> "Site mode" -> "Redirect"

O
olenkill2, 2022-02-16
@olenkill2

The modules array can be built up to the object in which it will be used.
Below is an example.

const module = ['@nuxt/recaptcha']

if ((process.env.APP_ENVIRONMENT as string) === 'prod') {
  modules.push([
            '@nuxtjs/yandex-metrika',
            {
                id:  '8******',
                webvisor: true,
                clickmap: true,
                trackLinks: true,
                accurateTrackBounce: true,
            }
  ])
}

export default {
   ...
   modules,
}

I would also get into the source codes and see if there is a parameter responsible for "inclusion".

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question