vuepress: @vuepress/google-analytics does not add tracking code as window is undefined?
- I confirm that this is a issue rather than a question.
Bug report
if I am building via vuepress build docs but window is undefined.
not really suprising as it does not run in the browser?
However there is this check
export default ({ router }) => {
console.log(typeof window); // undefined
// Google analytics integration
if (process.env.NODE_ENV === 'production' && GA_ID && typeof window !== 'undefined') {
from this change a while back: https://github.com/vuejs/vuepress/pull/893/commits/ca618e4b6c1cf5857f90f7d41848668ae56e3aa3
I’m still not sure why a check for window is there?
Version
every version? I know it worked before so I’m baffled how?
tested in:
$ npm ls vuepress
@open-wc/root@ [...]/open-wc/open-wc
└── vuepress@1.0.0-alpha.37
$ npm ls @vuepress/plugin-google-analytics
@open-wc/root@ [...]/open-wc/open-wc
└── @vuepress/plugin-google-analytics@1.0.0-alpha.37
Steps to reproduce
add to your config.js
plugins: [
'@vuepress/google-analytics',
{
'ga': 'UA-131782693-1'
}
],
live version:
git clone git@github.com:open-wc/open-wc.git
cd open-wc
npm i
npm run site:build
// search for "google-analytics" in the "_site" folder
What is expected?
tracking via analytics e.g. js tracking code get’s inserted
What is actually happening?
no tracking code
Other relevant information
$ node --version
v11.7.0
$ npm --version
6.6.0
$ cat /proc/version:
It is a WSL (Windows Subystem Linux)
Linux version 4.4.0-17134-Microsoft (Microsoft@Microsoft.com) (gcc version 5.4.0 (GCC) ) #523-Microsoft Mon Dec 31 17:49:00 PST 2018
$ lsb_release -a:
Distributor ID: Ubuntu
Description: Ubuntu 16.04.3 LTS
Release: 16.04
Codename: xenial
- Is this a global or local install? local
- Which package manager did you use for the install? yarn or npm didn’t matter
About this issue
- Original URL
- State: closed
- Created 5 years ago
- Reactions: 1
- Comments: 16 (4 by maintainers)
If it truly turns out to be a bug, please provide valid repro. You guys are just paste code from start to finish, but sorry, I can’t reproduce it.
The another thing is that I cannot understand why can you use plugin in 0.x, is the home page of the document not very clear?
FYI, I tried installing the plugins in multiple ways. To fix all your issues, use Yarn. NPM screws up the linking and the moment I just nuked node_modules and used
yarn installeverything worked. There are a few hours I’ll never get back…我遇到了同样的问题,我升级了vuepress到1.x,也在/docs/.vuepress/config.js中配置了plugins,但是仍然没有效果。
这里是版本库
这是最新的构建版本
请帮忙看下,谢谢
You may find the repo here: https://github.com/open-wc/open-wc
Also we’re not using 0.x of the plugin, although SGarno is. We’re currently using:
"@vuepress/plugin-google-analytics": "^1.0.0-alpha.30"and"vuepress": "^1.0.0-alpha.30".I believe @daKmoR has tried using the latest versions (
^1.0.0-alpha.37) as well, without success.