Vuepress: Google Analytics tag missing?

Created on 29 May 2018  路  5Comments  路  Source: vuejs/vuepress


Bug report



Version 0.10.0

Steps to reproduce

I've configured the GA attribute in the config.js file with the ID, but I'm not seeing any evidence of it in the dev or build files.

https://github.com/bencodezen/vue-meetups/blob/master/docs/.vuepress/config.js

What is expected?

I expected some evidence of the following to appear in a build file or something, but I don't see any evidence of it in the files.

<!-- Global site tag (gtag.js) - Google Analytics -->
<script async src="https://www.googletagmanager.com/gtag/js?id=UA-123456"></script>
<script>
  window.dataLayer = window.dataLayer || [];
  function gtag(){dataLayer.push(arguments);}
  gtag('js', new Date());

  gtag('config', 'UA-123456');
</script>

What is actually happening?

It seems like the configuration to integrate Google Analytics isn't working? Based on diving into the source code, it is generated based on (process.env.NODE_ENV === 'production' && GA_ID).

Is it possible that when triggering vuepress build docs it doesn't set the process.env.NODE_ENV to production which is why it is missing?

Other relevant information

  • Your OS: macOS High Sierra v10.13.4
  • Node.js version: 8.11.1
  • Browser version: Firefox Quantum v60.0.1
  • Is this a global or local install? Local install
  • Which package manager did you use for the install? yarn

Most helpful comment

@bencodezen

In dev, that you cannot see it is due to the code won't be included to the output bundle:

if (process.env.NODE_ENV === 'production' && GA_ID) {
   // GA's code
}

See: https://webpack.js.org/guides/production/#specify-the-environment

While in build, it should be in the output when you provide the GA's id:

image

All 5 comments

I might have figured it out. I think it has to do with the node_env flag. Will report back shortly.

Just tried adding a NODE_ENV variable with "production" as a value to the Netlify build process and it didn't seem to change the output.

@LinFeng1997 I'm currently waiting for Algolia to review the site. Is the Algolia configuration relevant to the Google Analytics though?

@bencodezen

In dev, that you cannot see it is due to the code won't be included to the output bundle:

if (process.env.NODE_ENV === 'production' && GA_ID) {
   // GA's code
}

See: https://webpack.js.org/guides/production/#specify-the-environment

While in build, it should be in the output when you provide the GA's id:

image

Can't believe I missed it in there. I assumed it was in one of the other build files. Thanks for clarifying @ulivz!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

AleksejDix picture AleksejDix  路  3Comments

ederchrono picture ederchrono  路  3Comments

FadySamirSadek picture FadySamirSadek  路  3Comments

kid1412621 picture kid1412621  路  3Comments

lesliecdubs picture lesliecdubs  路  3Comments